annotate src/engine.cpp @ 13036:8e2a0e8fa275 draft

(svn r17534) -Codechange: unify the naming of callback masks/flags
author rubidium <rubidium@openttd.org>
date Mon, 14 Sep 2009 12:22:57 +0000
parents 6eb3f749890a
children 082cdb4504ac
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"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
13 #include "debug.h"
10208
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
14 #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
15 #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
16 #include "news_func.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
17 #include "variables.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
18 #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
19 #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
20 #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
21 #include "group.h"
8114
2d6af5d7a142 (svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents: 7931
diff changeset
22 #include "strings_func.h"
8225
0e48dd14a0d8 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium <rubidium@openttd.org>
parents: 8221
diff changeset
23 #include "gfx_func.h"
10960
a4e5b5d2837c (svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents: 10927
diff changeset
24 #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
25 #include "window_func.h"
8140
fb8a05d579da (svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents: 8131
diff changeset
26 #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
27 #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
28 #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
29 #include "ai/ai.hpp"
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
30 #include "vehicle_func.h"
10960
a4e5b5d2837c (svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents: 10927
diff changeset
31 #include "settings_type.h"
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11951
diff changeset
32 #include "core/pool_func.hpp"
12837
a6a46b1b7ad9 (svn r17327) -Codechange: Allow external use of GetEngineCategoryName().
alberth <alberth@openttd.org>
parents: 12808
diff changeset
33 #include "engine_gui.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
34
8264
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8258
diff changeset
35 #include "table/strings.h"
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8258
diff changeset
36 #include "table/engines.h"
2495310e220f (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents: 8258
diff changeset
37
11972
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11951
diff changeset
38 EnginePool _engine_pool("Engine");
fd10870d74d4 (svn r16378) -Codechange: replace OldPool with simpler Pool. Compilation time, binary size and run time (with asserts disabled) should be improved
smatz <smatz@openttd.org>
parents: 11951
diff changeset
39 INSTANTIATE_POOL_METHODS(Engine)
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
40
11296
1b6a11831215 (svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents: 11238
diff changeset
41 EngineOverrideManager _engine_mngr;
1b6a11831215 (svn r15645) -Fix (r12924)[FS#2612]: Add an EngineOverrideManager to give the term 'compatible newgrf' again some sense and to not crash because of trivial changes.
frosch <frosch@openttd.org>
parents: 11238
diff changeset
42
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
43 /** Year that engine aging stops. Engines will not reduce in reliability
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
44 * and no more engines will be introduced */
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
45 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
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
63 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
64
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
65 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
66 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
67 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
68 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
69 {
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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 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
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 this->type = 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
75 this->internal_id = 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
76 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
77
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
78 /* 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
79 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
80 /* 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
81 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
82 /* 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
83 this->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
84 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
85 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
86
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
87 /* 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
88 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
89
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
90 /* 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
91 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
92 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
93
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
94 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
95 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
96 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
97 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
98
4b216e04a76c (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents: 10208
diff changeset
99 /* 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
100 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
101
9070
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
102 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
103
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
104 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
105 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
106 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
107 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
108 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
109
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
110 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
111 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
112 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
113 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
114 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
115
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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 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
117 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
118 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
119 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
120 break;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
121 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
122 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
123
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
124 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
125 {
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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 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
127 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
128 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
129
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
130 /**
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
131 * 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
132 * 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
133 * @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
134 */
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
135 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
136 {
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
137 /* 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
138 * 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
139 * 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
140 * 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
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 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
143 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
144 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
145 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
146
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 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
148 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
149 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
150
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 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
152 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
153 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
154
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 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
156 }
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 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
158 }
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
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
160 /**
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
161 * 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
162 *
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
163 * 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
164 * 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
165 * 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
166 *
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
167 * @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
168 * @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
169 */
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
170 uint Engine::GetDisplayDefaultCapacity() const
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 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
173 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
174 case VEH_TRAIN:
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 return GetEngineProperty(this->index, 0x14, this->u.rail.capacity) + (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? this->u.rail.capacity : 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
176
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 case VEH_ROAD:
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
178 return GetEngineProperty(this->index, 0x0F, this->u.road.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
179
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 case VEH_SHIP:
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 return GetEngineProperty(this->index, 0x0D, this->u.ship.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
182
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
183 case VEH_AIRCRAFT:
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 return AircraftDefaultCargoCapacity(this->GetDefaultCargoType(), &this->u.air);
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
185
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 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
187 }
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 }
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
189
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
190 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
191 {
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
192 switch (this->type) {
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
193 case VEH_ROAD:
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
194 return this->u.road.running_cost * GetPriceByIndex(this->u.road.running_cost_class) >> 8;
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
195
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
196 case VEH_TRAIN:
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
197 return GetEngineProperty(this->index, 0x0D, this->u.rail.running_cost) * GetPriceByIndex(this->u.rail.running_cost_class) >> 8;
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
198
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
199 case VEH_SHIP:
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
200 return GetEngineProperty(this->index, 0x0F, this->u.ship.running_cost) * _price.ship_running >> 8;
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
201
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
202 case VEH_AIRCRAFT:
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
203 return GetEngineProperty(this->index, 0x0E, this->u.air.running_cost) * _price.aircraft_running >> 8;
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
204
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
205 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
206 }
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
207 }
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
208
10927
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
209 Money Engine::GetCost() const
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
210 {
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
211 switch (this->type) {
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
212 case VEH_ROAD:
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
213 return GetEngineProperty(this->index, 0x11, this->u.road.cost_factor) * (_price.roadveh_base >> 3) >> 5;
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
214
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
215 case VEH_TRAIN:
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
216 if (this->u.rail.railveh_type == RAILVEH_WAGON) {
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
217 return (GetEngineProperty(this->index, 0x17, this->u.rail.cost_factor) * _price.build_railwagon) >> 8;
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
218 } else {
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
219 return GetEngineProperty(this->index, 0x17, this->u.rail.cost_factor) * (_price.build_railvehicle >> 3) >> 5;
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
220 }
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
221 case VEH_SHIP:
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
222 return GetEngineProperty(this->index, 0x0A, this->u.ship.cost_factor) * (_price.ship_base >> 3) >> 5;
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
223
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
224 case VEH_AIRCRAFT:
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
225 return GetEngineProperty(this->index, 0x0B, this->u.air.cost_factor) * (_price.aircraft_base >> 3) >> 5;
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
226
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
227 default: NOT_REACHED();
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
228 }
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
229 }
68230070e59b (svn r15263) -Codechange: added Engine::GetCost() to remove some code duplication.
glx <glx@openttd.org>
parents: 10925
diff changeset
230
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
231 /**
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
232 * Returns max speed for display purposes
10969
208ba3fba382 (svn r15308) -Codechange: Deduplicate km-ish/h -> mph conversions.
frosch <frosch@openttd.org>
parents: 10967
diff changeset
233 * @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
234 */
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
235 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
236 {
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
237 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
238 case VEH_TRAIN:
10969
208ba3fba382 (svn r15308) -Codechange: Deduplicate km-ish/h -> mph conversions.
frosch <frosch@openttd.org>
parents: 10967
diff changeset
239 return GetEngineProperty(this->index, 0x09, 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
240
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
241 case VEH_ROAD:
10969
208ba3fba382 (svn r15308) -Codechange: Deduplicate km-ish/h -> mph conversions.
frosch <frosch@openttd.org>
parents: 10967
diff changeset
242 return this->u.road.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
243
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
244 case VEH_SHIP:
10969
208ba3fba382 (svn r15308) -Codechange: Deduplicate km-ish/h -> mph conversions.
frosch <frosch@openttd.org>
parents: 10967
diff changeset
245 return GetEngineProperty(this->index, 0x0B, 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
246
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
247 case VEH_AIRCRAFT:
10969
208ba3fba382 (svn r15308) -Codechange: Deduplicate km-ish/h -> mph conversions.
frosch <frosch@openttd.org>
parents: 10967
diff changeset
248 return this->u.air.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
249
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
250 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
251 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
252 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
253
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
254 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
255 {
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
256 /* Currently only trains have 'power' */
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
257 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
258 case VEH_TRAIN:
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
259 return GetEngineProperty(this->index, 0x0B, this->u.rail.power);
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
260
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
261 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
262 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
263 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
264
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
265 /**
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
266 * Returns the weight for display purposes.
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
267 * 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
268 * @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
269 */
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
270 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
271 {
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
272 /* Currently only trains have 'weight' */
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
273 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
274 case VEH_TRAIN:
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
275 return GetEngineProperty(this->index, 0x16, this->u.rail.weight) << (this->u.rail.railveh_type == RAILVEH_MULTIHEAD ? 1 : 0);
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
276
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
277 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
278 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
279 }
57269a8c0b6d (svn r15306) -Codechange: Deduplicate code by adding Engine::GetDisplayMaxSpeed(), GetPower() and GetDisplayWeight(). (and using them)
frosch <frosch@openttd.org>
parents: 10960
diff changeset
280
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
281 /**
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
282 * Returns the tractive effort for display purposes.
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
283 * 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
284 * @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
285 */
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
286 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
287 {
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
288 /* Currently only trains have 'tractive effort' */
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
289 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
290 case VEH_TRAIN:
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
291 return (10 * this->GetDisplayWeight() * GetEngineProperty(this->index, 0x1F, this->u.rail.tractive_effort)) / 256;
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
292
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
293 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
294 }
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
295 }
631c89cee615 (svn r15521) -Codechange: add helper function to get the display tractive effort of a vehicle.
rubidium <rubidium@openttd.org>
parents: 11090
diff changeset
296
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
297 /**
12165
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
298 * Returns the vehicle's life length in days.
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
299 * @return the life length
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
300 */
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
301 Date Engine::GetLifeLengthInDays() const
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
302 {
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
303 /* 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
304 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
305 }
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
306
299a364a2abc (svn r16581) -Codechange: unify the access to Engine::lifelength.
rubidium <rubidium@openttd.org>
parents: 12164
diff changeset
307 /**
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
308 * 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
309 */
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
310 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
311 {
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
312 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
313 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
314 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
315 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
316 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
317 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
318 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
319 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
320 }
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
321 }
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
322 }
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
323
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
324 /**
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
325 * 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
326 * @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
327 * @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
328 * @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
329 * 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
330 * 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
331 * @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
332 */
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
333 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
334 {
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
335 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
336 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
337 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
338 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
339 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
340 }
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
341 }
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
342 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
343 }
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
344
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
345 /** 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
346 */
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
347 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
348 {
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
349 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
350
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
351 /* 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
352 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
353 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
354 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
355 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
356 }
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
357
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
358 /* 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
359 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
360 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
361 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
362 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
363 }
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
364
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
365 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
366 FOR_ALL_VEHICLES(v) {
12383
3c7e93b91c73 (svn r16813) -Codechange: make IsEngineCountable() member of Vehicle
smatz <smatz@openttd.org>
parents: 12232
diff changeset
367 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
368
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
369 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
370
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
371 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
372
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
373 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
374
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
375 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
376 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
377 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
378
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
379 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
380 }
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
381 }
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
382
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
383 void SetupEngines()
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
384 {
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
385 _engine_pool.CleanPool();
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
386
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
387 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
388 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
389 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
390 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
391 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
392 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
393 }
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
394 }
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
395
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
396
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
397 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
398
9468
07d40eb8252e (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents: 9417
diff changeset
399 /* 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
400 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
401 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
402 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
403 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
404 }
07d40eb8252e (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents: 9417
diff changeset
405
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
406 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
407 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
408 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
409
6606
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
410 /* 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
411 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
412 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
413 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
414 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
415 /* 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
416 e->company_avail = 0;
6606
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
417 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
418 }
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
419 }
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
420
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
421 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
422 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
423 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
424 } 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
425 /* 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
426 * 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
427 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
428 } 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
429 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
430 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
431 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
432 /* 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
433 * 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
434 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
435 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
436 /* 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
437 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
438 }
13034
6eb3f749890a (svn r17532) -Codechange: Rename several Invalidate functions to SetDirty for more consistency and distinguishability.
frosch <frosch@openttd.org>
parents: 12837
diff changeset
439 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
440 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
441 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
442
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
443 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
444 {
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
445 /* 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
446 _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
447
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
448 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
449 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
450 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
451
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
452 /* 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
453 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
454 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
455
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
456 /* 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
457 YearMonthDay ymd;
10744
0118ca646690 (svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents: 10696
diff changeset
458 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
459
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
460 _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
461 }
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
462 }
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
463
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
464 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
465 {
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
466 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
467 uint32 r;
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
468
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
469 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
470 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
471 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
472
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
473 /* 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
474 * 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
475 * Note: TTDP uses fixed 1922 */
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
476 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
477 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
478 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
479 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
480 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
481 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
482 }
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
483
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
484 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
485 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
486 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
487 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
488
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
489 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
490 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
491 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
492 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
493
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
494 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
495
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
496 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
497
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
498 /* 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
499 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
500 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
501 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
502 }
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
503 }
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
504
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6209
diff changeset
505 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
506 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
507 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
508 /* 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
509 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
510
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
511 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
512 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
513 }
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
514
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
515 /* 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
516 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
517 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
518 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
519 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
520 }
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 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
522
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
523 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
524 {
11922
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
525 Engine *e = Engine::Get(eid);
0a4b63f3f3c3 (svn r16325) -Codechange: replace GetPoolItem(index) by PoolItem::Get(index)
smatz <smatz@openttd.org>
parents: 11730
diff changeset
526 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
527
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
528 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
529 if (e->type == VEH_TRAIN) {
5823
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
530 const RailVehicleInfo *rvi = RailVehInfo(eid);
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
531
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
532 assert(rvi->railtype < RAILTYPE_END);
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
533 SetBit(c->avail_railtypes, rvi->railtype);
6685
91a7c42b133c (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium <rubidium@openttd.org>
parents: 6643
diff changeset
534 } else if (e->type == VEH_ROAD) {
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
535 SetBit(c->avail_roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
5823
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
536 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
537
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
538 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
539 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
540 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
541 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
542 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
543
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
544 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
545 {
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
546 const Company *c;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
547 int32 best_hist;
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
548 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
549 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
550
8572
8a95003be848 (svn r12150) -Fix (r12143): compiler warnings - possible use of uninitialised variable
smatz <smatz@openttd.org>
parents: 8565
diff changeset
551 do {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
552 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
553 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
554 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
555 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
556 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
557 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
558 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
559 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
560 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
561
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
562 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
563
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
564 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
565 } 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
566
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
567 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
568 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
569
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6209
diff changeset
570 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
571 {
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
572 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
573
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
574 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
575 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
576 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
577 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
578 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
579 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
580 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
581 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
582 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
583 }
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
584 } 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
585 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
586
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
587 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
588 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
589 continue;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
590 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
591
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
592 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
593 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
594 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
595 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
596 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
597 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
598 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
599 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
600
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
601 /** 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
602 * 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
603 * @param tile unused
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6259
diff changeset
604 * @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
605 * @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
606 * @param p2 unused
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
607 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11071
diff changeset
608 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
609 {
11951
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
610 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
611 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
612
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 10148
diff changeset
613 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
614
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
615 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
616 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
617
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
618 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
619 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
620 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
621 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
622 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
623
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
624 /* 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
625 * 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
626 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
627 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
628 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
629
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
630 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
631
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
632 /* 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
633 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
634
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
635 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
636 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
637 (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
638 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
639 /* 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
640 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
641 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
642 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
643 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
644 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
645 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
646 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
647
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
648 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
649 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
650
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
651 /* 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
652 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
653
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
654 /* 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
655 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
656
8220
01778382728c (svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138 <peter1138@openttd.org>
parents: 8214
diff changeset
657 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
658 /* 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
659 RailType railtype = e->u.rail.railtype;
5823
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
660 assert(railtype < RAILTYPE_END);
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
661 FOR_ALL_COMPANIES(c) SetBit(c->avail_railtypes, railtype);
8220
01778382728c (svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138 <peter1138@openttd.org>
parents: 8214
diff changeset
662 } 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
663 /* 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
664 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
665 }
9199
dbe675dc54c4 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents: 9135
diff changeset
666
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
667 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
668
9199
dbe675dc54c4 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents: 9135
diff changeset
669 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
670 SetDParam(1, index);
12619
2f530108f787 (svn r17062) -Change: unify the naming of some 125 strings
rubidium <rubidium@openttd.org>
parents: 12492
diff changeset
671 AddNewsItem(STR_NEWS_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NS_NEW_VEHICLES, NR_ENGINE, 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
672 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
673
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6209
diff changeset
674 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
675 {
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
676 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
677 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
678 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
679 /* Age the vehicle */
12082
d092f17a921d (svn r16491) -Codechange: Added parentheses around bitwise operators for code style.
alberth <alberth@openttd.org>
parents: 12010
diff changeset
680 if ((e->flags & ENGINE_AVAILABLE) && e->age != 0xFFFF) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
681 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
682 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
683 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
684
10744
0118ca646690 (svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents: 10696
diff changeset
685 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
686 /* 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
687 NewVehicleAvailable(e);
11361
02313cc6114e (svn r15711) -Codechange: lots of whitespace cleanup/fixes
rubidium <rubidium@openttd.org>
parents: 11296
diff changeset
688 } 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
689 /* 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
690 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
691
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
692 /* Do not introduce new rail wagons */
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
693 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
694 e->preview_company_rank = 1; // Give to the company with the highest rating.
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
695 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
696 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
697 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
698 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
699
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
700 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
701 {
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
702 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
703
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
704 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
705 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
706 }
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
707
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
708 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
709 }
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
710
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 /** Rename an engine.
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
712 * @param tile unused
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6259
diff changeset
713 * @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
714 * @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
715 * @param p2 unused
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
716 */
11090
df23c4e04638 (svn r15434) -Codechange: bit of type safety for the DC_xxx flags.
rubidium <rubidium@openttd.org>
parents: 11071
diff changeset
717 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
718 {
11951
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
719 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
720 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
721
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
722 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
723
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
724 if (!reset) {
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
725 if (strlen(text) >= MAX_LENGTH_ENGINE_NAME_BYTES) 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
726 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
727 }
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
728
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
729 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
730 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
731
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
732 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
733 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
734 } 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
735 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
736 }
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
737
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
738 MarkWholeScreenDirty();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
739 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
740
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
741 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
742 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
743
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
744
8479
689d2708728a (svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138 <peter1138@openttd.org>
parents: 8401
diff changeset
745 /** 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
746 * @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
747 * @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
748 * @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
749 * @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
750 * 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
751 */
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
752 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
753 {
11951
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
754 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
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 /* 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
757 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
758
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
759 /* 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
760 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
761
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
762 /* 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
763 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
764
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
765 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
766 /* 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
767 const Company *c = Company::Get(company);
12808
c2410803b553 (svn r17296) -Fix/feature [FS#3152]: allow rail wagons to be build when only el rail engines are available
rubidium <rubidium@openttd.org>
parents: 12778
diff changeset
768 if (((GetRailTypeInfo(RailVehInfo(engine)->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
769 }
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
770
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
771 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
772 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
773
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
774 /**
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
775 * 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
776 * 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
777 * @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
778 * @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
779 */
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
780 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
781 {
11951
8bbe44fa53e2 (svn r16354) -Codechange: use 'new' pool accessors and methods for Engine too
smatz <smatz@openttd.org>
parents: 11923
diff changeset
782 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
783
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
784 /* 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
785 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
786
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
787 if (e->type == VEH_SHIP && !e->u.ship.refittable) 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
788
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
789 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
790
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
791 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
792 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
793
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
794 /* 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
795 * 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
796 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
797
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
798 /* 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
799 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
800 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
801 }