annotate src/engine.cpp @ 10744:0118ca646690 draft

(svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR -Change: when computing daily running cost, divide by 365 (instead of 364). Since r12134, the rounding errors don't need this correction anymore
author smatz <smatz@openttd.org>
date Tue, 13 Jan 2009 22:58:03 +0000
parents 7edccbb67398
children 8e9bff1a3e56
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
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
3 /** @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
4
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
5 #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
6 #include "openttd.h"
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
7 #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
8 #include "company_base.h"
39cf8eebfda5 (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
9 #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
10 #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
11 #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
12 #include "variables.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 "train.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
14 #include "aircraft.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
15 #include "newgrf_cargo.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
16 #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
17 #include "group.h"
8114
2d6af5d7a142 (svn r11675) -Codechange: split the string types from the string functions.
rubidium <rubidium@openttd.org>
parents: 7931
diff changeset
18 #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
19 #include "gfx_func.h"
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
20 #include "functions.h"
e300ac8001ae (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium <rubidium@openttd.org>
parents: 8121
diff changeset
21 #include "window_func.h"
8140
fb8a05d579da (svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents: 8131
diff changeset
22 #include "date_func.h"
8212
11263ebe590a (svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium <rubidium@openttd.org>
parents: 8144
diff changeset
23 #include "autoreplace_gui.h"
8214
6385dffc0b37 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium <rubidium@openttd.org>
parents: 8212
diff changeset
24 #include "string_func.h"
8270
5613b863190d (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium <rubidium@openttd.org>
parents: 8268
diff changeset
25 #include "settings_type.h"
8847
748b998a108e (svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
smatz <smatz@openttd.org>
parents: 8786
diff changeset
26 #include "oldpool_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
27 #include "ai/ai.hpp"
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
28 #include "core/alloc_func.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
29 #include "vehicle_func.h"
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
30
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
31 #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
32 #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
33
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
34 DEFINE_OLD_POOL_GENERIC(Engine, 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
35
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
36 /** 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
37 * 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
38 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
39
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
40 /** 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
41 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
42 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
43 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
44 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
45 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
46 };
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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 /** 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
49 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
50 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
51 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
52 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
53 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
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
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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 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
57 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
58 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
59 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
60 {
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
61 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
62
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
63 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
64 {
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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 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
66 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
67 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
68
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
69 /* 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
70 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
71 /* 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
72 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
73 /* 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
74 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
75 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
76 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
77
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
78 /* 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
79 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
80
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
81 /* 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
82 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
83 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
84
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
85 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
86 this->u.rail = _orig_rail_vehicle_info[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
87 this->image_index = this->u.rail.image_index;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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.string_id = STR_8000_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
89
4b216e04a76c (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents: 10208
diff changeset
90 /* 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
91 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
92
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
93 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
94
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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 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
96 this->u.road = _orig_road_vehicle_info[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
97 this->image_index = this->u.road.image_index;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
98 this->info.string_id = STR_8074_MPS_REGAL_BUS + 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
99 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
100
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
101 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
102 this->u.ship = _orig_ship_vehicle_info[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
103 this->image_index = this->u.ship.image_index;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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 this->info.string_id = STR_80CC_MPS_OIL_TANKER + 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
105 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
106
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
107 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
108 this->u.air = _orig_aircraft_vehicle_info[base];
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
109 this->image_index = this->u.air.image_index;
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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 this->info.string_id = STR_80D7_SAMPSON_U52 + 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
111 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
112 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
113 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
114
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
115 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
116 {
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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 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
118 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
119 }
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and 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
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
121 /** 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
122 */
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
123 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
124 {
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
125 uint engines = GetEnginePoolSize();
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
126
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
127 /* 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
128 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
129 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
130 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
131 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
132 }
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
133
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
134 /* 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
135 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
136 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
137 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
138 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
139 }
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
140
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
141 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
142 FOR_ALL_VEHICLES(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
143 if (!IsEngineCountable(v)) 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
144
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
145 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
146
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
147 GetCompany(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
148
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
149 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
150
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
151 g = GetGroup(v->group_id);
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
152 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
153 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
154
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
155 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
156 }
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
157 }
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
158
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
159 void SetupEngines()
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
160 {
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
161 _Engine_pool.CleanPool();
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
162 _Engine_pool.AddBlockToPool();
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
163
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
164 for (uint i = 0; i < lengthof(_orig_rail_vehicle_info); i++) new Engine(VEH_TRAIN, i);
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
165 for (uint i = 0; i < lengthof(_orig_road_vehicle_info); i++) new Engine(VEH_ROAD, i);
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
166 for (uint i = 0; i < lengthof(_orig_ship_vehicle_info); i++) new Engine(VEH_SHIP, i);
11b5b3f4175d (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138 <peter1138@openttd.org>
parents: 9036
diff changeset
167 for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++) new Engine(VEH_AIRCRAFT, i);
8221
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
168 }
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
169
188d5ea22361 (svn r11784) -Codechange: set up initial engine data in one place
peter1138 <peter1138@openttd.org>
parents: 8220
diff changeset
170
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
171 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
172
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6209
diff changeset
173 void DeleteCustomEngineNames()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
174 {
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
175 Engine *e;
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
176 FOR_ALL_ENGINES(e) {
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
177 free(e->name);
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
178 e->name = NULL;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
179 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
180
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
181 _vehicle_design_names &= ~1;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
182 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
183
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6209
diff changeset
184 void LoadCustomEngineNames()
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
185 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
186 /* XXX: not done */
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
187 DEBUG(misc, 1, "LoadCustomEngineNames: not done");
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
188 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
189
9468
07d40eb8252e (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents: 9417
diff changeset
190 /* 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
191 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
192 {
07d40eb8252e (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents: 9417
diff changeset
193 const Engine *e = GetEngine(index);
07d40eb8252e (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents: 9417
diff changeset
194 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
195 }
07d40eb8252e (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents: 9417
diff changeset
196
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
197 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
198 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
199 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
200
6606
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
201 /* 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
202 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
203 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
204 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
205 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
206 /* 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
207 e->company_avail = 0;
6606
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
208 AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
209 }
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
210 }
a06a7d24392b (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138 <peter1138@openttd.org>
parents: 6530
diff changeset
211
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
212 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
213 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
214 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
215 } 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
216 /* 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
217 * 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
218 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
219 } 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
220 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
221 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
222 } else {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
223 /* 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
224 * 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
225 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
226 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
227 /* 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
228 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
229 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
230 InvalidateWindowClasses(WC_BUILD_VEHICLE); // Update to show the new reliability
5944
ca95cde4d1b4 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni <bjarni@openttd.org>
parents: 5868
diff changeset
231 InvalidateWindowClasses(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
232 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
233
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
234 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
235 {
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
236 /* 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
237 _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
238
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
239 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
240 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
241 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
242
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
243 /* 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
244 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
245 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
246
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
247 /* 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
248 YearMonthDay ymd;
10744
0118ca646690 (svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents: 10696
diff changeset
249 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
250
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
251 _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
252 }
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
253 }
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
254
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6209
diff changeset
255 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
256 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
257 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
258 /* 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
259 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
260
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
261 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
262 const EngineInfo *ei = &e->info;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
263 uint32 r;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
264
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
265 e->age = 0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
266 e->flags = 0;
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
267 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
268
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
269 /* The magic value of 729 days below comes from the NewGRF spec. If the
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 5971
diff changeset
270 * base intro date is before 1922 then the random number of days is not
46d001ebacf6 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents: 5971
diff changeset
271 * added. */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
272 r = Random();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
273 e->intro_date = ei->base_intro <= ConvertYMDToDate(1922, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
274 if (e->intro_date <= _date) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
275 e->age = (aging_date - e->intro_date) >> 5;
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
276 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
277 e->flags |= ENGINE_AVAILABLE;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
278 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
279
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
280 e->reliability_start = GB(r, 16, 14) + 0x7AE0;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
281 r = Random();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
282 e->reliability_max = GB(r, 0, 14) + 0xBFFF;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
283 e->reliability_final = GB(r, 16, 14) + 0x3FFF;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
284
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
285 r = Random();
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
286 e->duration_phase_1 = GB(r, 0, 5) + 7;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
287 e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
288 e->duration_phase_3 = GB(r, 9, 7) + 120;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
289
9468
07d40eb8252e (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138 <peter1138@openttd.org>
parents: 9417
diff changeset
290 e->reliability_spd_dec = ei->decay_speed << 2;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
291
10427
4b216e04a76c (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch <frosch@openttd.org>
parents: 10208
diff changeset
292 CalcEngineReliability(e);
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
293
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9380
diff changeset
294 e->lifelength = ei->lifelength + _settings_game.vehicle.extend_vehicle_life;
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
295
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
296 /* prevent certain engines from ever appearing. */
9413
512ea64da840 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents: 9380
diff changeset
297 if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) {
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
298 e->flags |= ENGINE_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
299 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
300 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
301 }
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
302
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
303 /* 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
304 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
305 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
306 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
307 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
308 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
309 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
310
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
311 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
312 {
5823
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
313 Engine *e = GetEngine(eid);
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
314 Company *c = GetCompany(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
315
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
316 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
317 if (e->type == VEH_TRAIN) {
5823
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
318 const RailVehicleInfo *rvi = RailVehInfo(eid);
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
319
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
320 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
321 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
322 } 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
323 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
324 }
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
325
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
326 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
327 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
328 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
329 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
330 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
331
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
332 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
333 {
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
334 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
335 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
336 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
337 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
338
8572
8a95003be848 (svn r12150) -Fix (r12143): compiler warnings - possible use of uninitialised variable
smatz <smatz@openttd.org>
parents: 8565
diff changeset
339 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
340 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
341 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
342 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
343 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
344 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
345 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
346 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
347 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
348 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
349
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
350 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
351
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
352 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
353 } 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
354
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
355 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
356 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
357
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6209
diff changeset
358 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
359 {
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
360 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
361
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
362 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
363 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
364 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
365 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
366 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
367 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
368 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
369 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
370 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
371 }
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
372 } 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
373 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
374
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
375 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
376 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
377 continue;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
378 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
379
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
380 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
381 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
382 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
383 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
384 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
385 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
386 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
387 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
388
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
389 /** 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
390 * 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
391 * @param tile unused
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6259
diff changeset
392 * @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
393 * @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
394 * @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
395 */
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
396 CommandCost CmdWantEnginePreview(TileIndex tile, uint32 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
397 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
398 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
399
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
400 if (!IsEngineIndex(p1)) return CMD_ERROR;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
401 e = GetEngine(p1);
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
402 if (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
403
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
404 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
405
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
406 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
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
9199
dbe675dc54c4 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents: 9135
diff changeset
409 StringID GetEngineCategoryName(EngineID engine);
dbe675dc54c4 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents: 9135
diff changeset
410
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
411 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
412 {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
413 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
414 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
415 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
416
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
417 /* 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
418 * 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
419 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
420 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
421 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
422
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
423 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
424
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 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
426 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
427
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
428 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
429 if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
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
430 (v->type == VEH_AIRCRAFT && IsNormalAircraft(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
431 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
432 /* 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
433 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
434 break;
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
435 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
436 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
437 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
438 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
439 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
440
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
441 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
442 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
443
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
444 /* 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
445 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
446
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
447 /* 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
448 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
449
8220
01778382728c (svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138 <peter1138@openttd.org>
parents: 8214
diff changeset
450 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
451 /* 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
452 RailType railtype = e->u.rail.railtype;
5823
4f8ecdfccbd3 (svn r8385) -Fix
tron <tron@openttd.org>
parents: 5763
diff changeset
453 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
454 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
455 } 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
456 /* 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
457 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
458 }
9199
dbe675dc54c4 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents: 9135
diff changeset
459
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
460 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
461
9199
dbe675dc54c4 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium <rubidium@openttd.org>
parents: 9135
diff changeset
462 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
463 SetDParam(1, index);
9234
02827bf3dc03 (svn r13100) -Codechange: reduce the amount of parameters passed via AddNewsMessage as there is (for each news message type) a tuple of 4 parameters that is the same for all calls.
rubidium <rubidium@openttd.org>
parents: 9223
diff changeset
464 AddNewsItem(STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NS_NEW_VEHICLES, index, 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
465 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
466
6247
57363e064324 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents: 6209
diff changeset
467 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
468 {
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
469 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
470 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
471 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
472 /* Age the 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
473 if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) {
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
474 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
475 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
476 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
477
10744
0118ca646690 (svn r15077) -Codechange: enumify DAYS_IN_YEAR and DAYS_IN_LEAP_YEAR
smatz <smatz@openttd.org>
parents: 10696
diff changeset
478 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
479 /* 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
480 NewVehicleAvailable(e);
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
481 } 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
482 /* 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
483 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
484
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
485 /* 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
486 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
487 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
488 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
489 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
490 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
491 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
492
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
493 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
494 {
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
495 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
496
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
497 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
498 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
499 }
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
500
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
501 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
502 }
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
503
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
504 /** 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
505 * @param tile unused
6481
85a1a79387a2 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas <belugas@openttd.org>
parents: 6259
diff changeset
506 * @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
507 * @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
508 * @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
509 */
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
510 CommandCost CmdRenameEngine(TileIndex tile, uint32 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
511 {
9914
711da94fe0d7 (svn r14064) -Fix [FS#1752]: check for the length of strings (in bytes) in the command. Checking for the length in pixels is impossible because that differs per client.
rubidium <rubidium@openttd.org>
parents: 9712
diff changeset
512 if (!IsEngineIndex(p1)) 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
513
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
514 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
515
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
516 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
517 if (strlen(text) >= MAX_LENGTH_ENGINE_NAME_BYTES) return CMD_ERROR;
45ca88a8de7d (svn r14754) -Codechange: get rid of _cmd_text and just pass it as (optional) parameter.
rubidium <rubidium@openttd.org>
parents: 10480
diff changeset
518 if (!IsUniqueEngineName(text)) return_cmd_error(STR_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
519 }
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
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 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
522 Engine *e = GetEngine(p1);
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
523 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
524
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
525 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
526 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
527 /* if we removed the last custom name, disable the 'Save custom names' button */
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
528 _vehicle_design_names &= ~1;
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
529 FOR_ALL_ENGINES(e) {
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
530 if (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
531 _vehicle_design_names |= 1;
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
532 break;
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
533 }
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
534 }
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
535 } 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
536 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
537 _vehicle_design_names |= 3;
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
538 }
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
539
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
540 MarkWholeScreenDirty();
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
6950
d2846442a133 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium <rubidium@openttd.org>
parents: 6943
diff changeset
543 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
544 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
545
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
546
8479
689d2708728a (svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138 <peter1138@openttd.org>
parents: 8401
diff changeset
547 /** 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
548 * @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
549 * @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
550 * @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
551 * @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
552 * 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
553 */
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
554 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
555 {
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
556 /* check if it's an engine that is in the engine array */
5584
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
557 if (!IsEngineIndex(engine)) 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
558
8479
689d2708728a (svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138 <peter1138@openttd.org>
parents: 8401
diff changeset
559 const Engine *e = GetEngine(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
560
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
561 /* 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
562 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
563
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
564 /* 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
565 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
566
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
567 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
568 /* Check if the rail type is available to this 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
569 const Company *c = GetCompany(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
570 if (!HasBit(c->avail_railtypes, RailVehInfo(engine)->railtype)) 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
571 }
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
572
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 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
574 }
4b26bd55bd24 (svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff changeset
575
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
576 /**
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
577 * Check if an 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
578 * @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
579 * @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
580 */
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
581 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
582 {
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
583 /* check if it's an engine that is in the engine array */
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
584 if (!IsEngineIndex(engine)) 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
585
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
586 const Engine *e = GetEngine(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
587
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
588 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
589
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
590 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
591 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
592
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
593 /* 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
594 * Note: This does not mean the suffixes are actually available for every consist at any time. */
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
595 if (HasBit(ei->callbackmask, CBM_VEHICLE_CARGO_SUFFIX)) return true;
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
596
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
597 /* Is there any cargo except the 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
598 CargoID default_cargo = GetEngineCargoType(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
599 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
600 }
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
601
6505
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
602 /** Get the default cargo type for a certain engine type
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
603 * @param engine The ID to get the cargo for
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
604 * @return The cargo type. CT_INVALID means no cargo capacity
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
605 */
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
606 CargoID GetEngineCargoType(EngineID engine)
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
607 {
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
608 assert(IsEngineIndex(engine));
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
609
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
610 switch (GetEngine(engine)->type) {
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
611 case VEH_TRAIN:
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
612 if (RailVehInfo(engine)->capacity == 0) return CT_INVALID;
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
613 return RailVehInfo(engine)->cargo_type;
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
614
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
615 case VEH_ROAD:
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
616 if (RoadVehInfo(engine)->capacity == 0) return CT_INVALID;
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
617 return RoadVehInfo(engine)->cargo_type;
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
618
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
619 case VEH_SHIP:
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
620 if (ShipVehInfo(engine)->capacity == 0) return CT_INVALID;
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
621 return ShipVehInfo(engine)->cargo_type;
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
622
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
623 case VEH_AIRCRAFT:
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
624 /* all aircraft starts as passenger planes with cargo capacity */
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
625 return CT_PASSENGERS;
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
626
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
627 default: NOT_REACHED(); return CT_INVALID;
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
628 }
14da45e0e4be (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni <bjarni@openttd.org>
parents: 6481
diff changeset
629 }