author | Tero Marttila <terom@fixme.fi> |
Fri, 18 Jul 2008 21:28:42 +0300 | |
changeset 11175 | 020c61e39c94 |
parent 10837 | 90f01f8fd55d |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
10429
1b99254f9607
(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
parents:
10382
diff
changeset
|
3 |
/** @file engine.cpp Base for all engine handling. */ |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1883
diff
changeset
|
6 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1197
diff
changeset
|
7 |
#include "debug.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8722
diff
changeset
|
8 |
#include "player_base.h" |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8722
diff
changeset
|
9 |
#include "player_func.h" |
8612
6414fc21c2f3
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8610
diff
changeset
|
10 |
#include "command_func.h" |
9259
088d3649dd4f
(svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents:
9129
diff
changeset
|
11 |
#include "news_func.h" |
0 | 12 |
#include "saveload.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2147
diff
changeset
|
13 |
#include "variables.h" |
2708
9d1a8d5dc3ea
(svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents:
2639
diff
changeset
|
14 |
#include "train.h" |
6105
761d393829d6
(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
parents:
6091
diff
changeset
|
15 |
#include "aircraft.h" |
3866
113de2b20059
(svn r4902) Newgrf : Introduction of the newgrf_cargo files.
belugas
parents:
3865
diff
changeset
|
16 |
#include "newgrf_cargo.h" |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
17 |
#include "newgrf_engine.h" |
7139
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
18 |
#include "group.h" |
8610
17cc343a23dd
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8427
diff
changeset
|
19 |
#include "strings_func.h" |
8721
b7971ad9bdd9
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8717
diff
changeset
|
20 |
#include "gfx_func.h" |
8627
448ebf3a8291
(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
parents:
8617
diff
changeset
|
21 |
#include "functions.h" |
448ebf3a8291
(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
parents:
8617
diff
changeset
|
22 |
#include "window_func.h" |
8636
2b158acb649c
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8627
diff
changeset
|
23 |
#include "date_func.h" |
8708
0c29fbc79be4
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents:
8640
diff
changeset
|
24 |
#include "autoreplace_base.h" |
0c29fbc79be4
(svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents:
8640
diff
changeset
|
25 |
#include "autoreplace_gui.h" |
8710
52015340050c
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
8708
diff
changeset
|
26 |
#include "string_func.h" |
8766
c86cfa3a7580
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8764
diff
changeset
|
27 |
#include "settings_type.h" |
9343
c30fd350dd8c
(svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
smatz
parents:
9282
diff
changeset
|
28 |
#include "oldpool_func.h" |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
29 |
#include "core/alloc_func.hpp" |
10533
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
30 |
#include "vehicle_func.h" |
10781
200f2f88fe49
(svn r13331) -Fix (r12924): Wrong include type for (sdt::)map
peter1138
parents:
10775
diff
changeset
|
31 |
#include <map> |
0 | 32 |
|
8760
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
33 |
#include "table/strings.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
34 |
#include "table/engines.h" |
ce0891c412ce
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8754
diff
changeset
|
35 |
|
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
36 |
DEFINE_OLD_POOL_GENERIC(Engine, Engine) |
2763 | 37 |
|
0 | 38 |
enum { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
39 |
YEAR_ENGINE_AGING_STOPS = 2050, |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
40 |
}; |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
41 |
|
0 | 42 |
|
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
43 |
/** Number of engines of each vehicle type in original engine data */ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
44 |
const uint8 _engine_counts[4] = { |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
45 |
lengthof(_orig_rail_vehicle_info), |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
46 |
lengthof(_orig_road_vehicle_info), |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
47 |
lengthof(_orig_ship_vehicle_info), |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
48 |
lengthof(_orig_aircraft_vehicle_info), |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
49 |
}; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
50 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
51 |
/** Offset of the first engine of each vehicle type in original engine data */ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
52 |
const uint8 _engine_offsets[4] = { |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
53 |
0, |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
54 |
lengthof(_orig_rail_vehicle_info), |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
55 |
lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info), |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
56 |
lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info), |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
57 |
}; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
58 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
59 |
Engine::Engine() : |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
60 |
name(NULL), |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
61 |
overrides_count(0), |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
62 |
overrides(NULL) |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
63 |
{ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
64 |
} |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
65 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
66 |
Engine::Engine(VehicleType type, EngineID base) |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
67 |
{ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
68 |
this->type = type; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
69 |
this->internal_id = base; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
70 |
this->list_position = base; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
71 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
72 |
/* Check if this base engine is within the original engine data range */ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
73 |
if (base >= _engine_counts[type]) { |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
74 |
/* Mark engine as valid anyway */ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
75 |
this->info.climates = 0x80; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
76 |
return; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
77 |
} |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
78 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
79 |
/* Copy the original engine info for this slot */ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
80 |
this->info = _orig_engine_info[_engine_offsets[type] + base]; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
81 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
82 |
/* Copy the original engine data for this slot */ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
83 |
switch (type) { |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
84 |
default: NOT_REACHED(); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
85 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
86 |
case VEH_TRAIN: |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
87 |
this->u.rail = _orig_rail_vehicle_info[base]; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
88 |
this->image_index = this->u.rail.image_index; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
89 |
this->info.string_id = STR_8000_KIRBY_PAUL_TANK_STEAM + base; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
90 |
break; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
91 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
92 |
case VEH_ROAD: |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
93 |
this->u.road = _orig_road_vehicle_info[base]; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
94 |
this->image_index = this->u.road.image_index; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
95 |
this->info.string_id = STR_8074_MPS_REGAL_BUS + base; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
96 |
break; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
97 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
98 |
case VEH_SHIP: |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
99 |
this->u.ship = _orig_ship_vehicle_info[base]; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
100 |
this->image_index = this->u.ship.image_index; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
101 |
this->info.string_id = STR_80CC_MPS_OIL_TANKER + base; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
102 |
break; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
103 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
104 |
case VEH_AIRCRAFT: |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
105 |
this->u.air = _orig_aircraft_vehicle_info[base]; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
106 |
this->image_index = this->u.air.image_index; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
107 |
this->info.string_id = STR_80D7_SAMPSON_U52 + base; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
108 |
break; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
109 |
} |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
110 |
} |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
111 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
112 |
Engine::~Engine() |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
113 |
{ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
114 |
UnloadWagonOverrides(this); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
115 |
free(this->name); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
116 |
} |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
117 |
|
10542
57d05d8c2b7c
(svn r13086) -Fix: do not crash badly after loading a newgrf with engines in-game that often
smatz
parents:
10533
diff
changeset
|
118 |
/** Sets cached values in Player::num_vehicles and Group::num_vehicles |
57d05d8c2b7c
(svn r13086) -Fix: do not crash badly after loading a newgrf with engines in-game that often
smatz
parents:
10533
diff
changeset
|
119 |
*/ |
10533
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
120 |
void SetCachedEngineCounts() |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
121 |
{ |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
122 |
uint engines = GetEnginePoolSize(); |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
123 |
|
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
124 |
/* Set up the engine count for all players */ |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
125 |
Player *p; |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
126 |
FOR_ALL_PLAYERS(p) { |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
127 |
free(p->num_engines); |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
128 |
p->num_engines = CallocT<EngineID>(engines); |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
129 |
} |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
130 |
|
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
131 |
/* Recalculate */ |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
132 |
Group *g; |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
133 |
FOR_ALL_GROUPS(g) { |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
134 |
free(g->num_engines); |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
135 |
g->num_engines = CallocT<EngineID>(engines); |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
136 |
} |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
137 |
|
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
138 |
const Vehicle *v; |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
139 |
FOR_ALL_VEHICLES(v) { |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
140 |
if (!IsEngineCountable(v)) continue; |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
141 |
|
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
142 |
assert(v->engine_type < engines); |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
143 |
|
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
144 |
GetPlayer(v->owner)->num_engines[v->engine_type]++; |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
145 |
|
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
146 |
if (v->group_id == DEFAULT_GROUP) continue; |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
147 |
|
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
148 |
g = GetGroup(v->group_id); |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
149 |
assert(v->type == g->vehicle_type); |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
150 |
assert(v->owner == g->owner); |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
151 |
|
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
152 |
g->num_engines[v->engine_type]++; |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
153 |
} |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
154 |
} |
24b0b6e1e8e9
(svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents:
10528
diff
changeset
|
155 |
|
8717
de56e5ec3aec
(svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents:
8716
diff
changeset
|
156 |
void SetupEngines() |
de56e5ec3aec
(svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents:
8716
diff
changeset
|
157 |
{ |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
158 |
_Engine_pool.CleanPool(); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
159 |
_Engine_pool.AddBlockToPool(); |
8717
de56e5ec3aec
(svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents:
8716
diff
changeset
|
160 |
|
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
161 |
for (uint i = 0; i < lengthof(_orig_rail_vehicle_info); i++) new Engine(VEH_TRAIN, i); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
162 |
for (uint i = 0; i < lengthof(_orig_road_vehicle_info); i++) new Engine(VEH_ROAD, i); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
163 |
for (uint i = 0; i < lengthof(_orig_ship_vehicle_info); i++) new Engine(VEH_SHIP, i); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
164 |
for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++) new Engine(VEH_AIRCRAFT, i); |
8717
de56e5ec3aec
(svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents:
8716
diff
changeset
|
165 |
} |
de56e5ec3aec
(svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents:
8716
diff
changeset
|
166 |
|
de56e5ec3aec
(svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents:
8716
diff
changeset
|
167 |
|
2477
d454d5152386
(svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents:
2469
diff
changeset
|
168 |
void ShowEnginePreviewWindow(EngineID engine); |
0 | 169 |
|
6573 | 170 |
void DeleteCustomEngineNames() |
0 | 171 |
{ |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
172 |
Engine *e; |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
173 |
FOR_ALL_ENGINES(e) { |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
174 |
free(e->name); |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
175 |
e->name = NULL; |
0 | 176 |
} |
177 |
||
178 |
_vehicle_design_names &= ~1; |
|
179 |
} |
|
180 |
||
6573 | 181 |
void LoadCustomEngineNames() |
0 | 182 |
{ |
4432
33631ac88c40
(svn r6195) -Codechange: do not use '//' in '/* ... */' style comments and '/*' or '*/' in '//' style comments.
rubidium
parents:
4384
diff
changeset
|
183 |
/* XXX: not done */ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5216
diff
changeset
|
184 |
DEBUG(misc, 1, "LoadCustomEngineNames: not done"); |
0 | 185 |
} |
186 |
||
10837
90f01f8fd55d
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents:
10781
diff
changeset
|
187 |
/* Determine if an engine type is a wagon (and not a loco) */ |
90f01f8fd55d
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents:
10781
diff
changeset
|
188 |
static bool IsWagon(EngineID index) |
90f01f8fd55d
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents:
10781
diff
changeset
|
189 |
{ |
90f01f8fd55d
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents:
10781
diff
changeset
|
190 |
const Engine *e = GetEngine(index); |
90f01f8fd55d
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents:
10781
diff
changeset
|
191 |
return e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON; |
90f01f8fd55d
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents:
10781
diff
changeset
|
192 |
} |
90f01f8fd55d
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents:
10781
diff
changeset
|
193 |
|
0 | 194 |
static void CalcEngineReliability(Engine *e) |
195 |
{ |
|
196 |
uint age = e->age; |
|
197 |
||
7102
ea95244a6027
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents:
7026
diff
changeset
|
198 |
/* Check for early retirement */ |
10775
7061477bfbcf
(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
parents:
10737
diff
changeset
|
199 |
if (e->player_avail != 0 && !_settings_game.vehicle.never_expire_vehicles) { |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
200 |
int retire_early = e->info.retire_early; |
9005
d4f2f08337db
(svn r12084) -Fix: 'Early retirement'-properties are signed.
frosch
parents:
8975
diff
changeset
|
201 |
uint retire_early_max_age = max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12); |
d4f2f08337db
(svn r12084) -Fix: 'Early retirement'-properties are signed.
frosch
parents:
8975
diff
changeset
|
202 |
if (retire_early != 0 && age >= retire_early_max_age) { |
7102
ea95244a6027
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents:
7026
diff
changeset
|
203 |
/* Early retirement is enabled and we're past the date... */ |
ea95244a6027
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents:
7026
diff
changeset
|
204 |
e->player_avail = 0; |
ea95244a6027
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents:
7026
diff
changeset
|
205 |
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
ea95244a6027
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents:
7026
diff
changeset
|
206 |
} |
ea95244a6027
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents:
7026
diff
changeset
|
207 |
} |
ea95244a6027
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents:
7026
diff
changeset
|
208 |
|
0 | 209 |
if (age < e->duration_phase_1) { |
210 |
uint start = e->reliability_start; |
|
211 |
e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start; |
|
10775
7061477bfbcf
(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
parents:
10737
diff
changeset
|
212 |
} else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _settings_game.vehicle.never_expire_vehicles) { |
4767
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
213 |
/* We are at the peak of this engines life. It will have max reliability. |
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
214 |
* This is also true if the engines never expire. They will not go bad over time */ |
0 | 215 |
e->reliability = e->reliability_max; |
216 |
} else if ((age -= e->duration_phase_2) < e->duration_phase_3) { |
|
217 |
uint max = e->reliability_max; |
|
218 |
e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max; |
|
219 |
} else { |
|
4767
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
220 |
/* time's up for this engine. |
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
221 |
* We will now completely retire this design */ |
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
222 |
e->player_avail = 0; |
0 | 223 |
e->reliability = e->reliability_final; |
6195
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6119
diff
changeset
|
224 |
/* Kick this engine out of the lists */ |
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6119
diff
changeset
|
225 |
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
0 | 226 |
} |
4767
7621bec94f99
(svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents:
4766
diff
changeset
|
227 |
InvalidateWindowClasses(WC_BUILD_VEHICLE); // Update to show the new reliability |
6195
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6119
diff
changeset
|
228 |
InvalidateWindowClasses(WC_REPLACE_VEHICLE); |
0 | 229 |
} |
230 |
||
6573 | 231 |
void StartupEngines() |
0 | 232 |
{ |
233 |
Engine *e; |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
234 |
/* Aging of vehicles stops, so account for that when starting late */ |
4322
0bee6d9bc452
(svn r5975) -Cleanup: use ORIGINAL_BASE_YEAR & ORIGINAL_MAX_YEAR where the functions really depend on the original date format.
rubidium
parents:
4300
diff
changeset
|
235 |
const Date aging_date = min(_date, ConvertYMDToDate(YEAR_ENGINE_AGING_STOPS, 0, 1)); |
0 | 236 |
|
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
237 |
FOR_ALL_ENGINES(e) { |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
238 |
const EngineInfo *ei = &e->info; |
2242
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
239 |
uint32 r; |
0 | 240 |
|
241 |
e->age = 0; |
|
242 |
e->flags = 0; |
|
243 |
e->player_avail = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
244 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
245 |
/* The magic value of 729 days below comes from the NewGRF spec. If the |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
246 |
* base intro date is before 1922 then the random number of days is not |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
247 |
* added. */ |
0 | 248 |
r = Random(); |
4297
47ce9665b4af
(svn r5934) -Cleanup: forgot some conversions to Year and to Date
rubidium
parents:
4293
diff
changeset
|
249 |
e->intro_date = ei->base_intro <= ConvertYMDToDate(1922, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro; |
0 | 250 |
if (e->intro_date <= _date) { |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
251 |
e->age = (aging_date - e->intro_date) >> 5; |
0 | 252 |
e->player_avail = (byte)-1; |
253 |
e->flags |= ENGINE_AVAILABLE; |
|
254 |
} |
|
255 |
||
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
1988
diff
changeset
|
256 |
e->reliability_start = GB(r, 16, 14) + 0x7AE0; |
0 | 257 |
r = Random(); |
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
1988
diff
changeset
|
258 |
e->reliability_max = GB(r, 0, 14) + 0xBFFF; |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
1988
diff
changeset
|
259 |
e->reliability_final = GB(r, 16, 14) + 0x3FFF; |
0 | 260 |
|
261 |
r = Random(); |
|
2140
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
1988
diff
changeset
|
262 |
e->duration_phase_1 = GB(r, 0, 5) + 7; |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
1988
diff
changeset
|
263 |
e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96; |
d708eb80ab8b
(svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents:
1988
diff
changeset
|
264 |
e->duration_phase_3 = GB(r, 9, 7) + 120; |
0 | 265 |
|
10837
90f01f8fd55d
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents:
10781
diff
changeset
|
266 |
e->reliability_spd_dec = ei->decay_speed << 2; |
0 | 267 |
|
10837
90f01f8fd55d
(svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents:
10781
diff
changeset
|
268 |
if (IsWagon(e->index)) { |
0 | 269 |
e->age = 0xFFFF; |
270 |
} else { |
|
271 |
CalcEngineReliability(e); |
|
272 |
} |
|
273 |
||
10775
7061477bfbcf
(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
parents:
10737
diff
changeset
|
274 |
e->lifelength = ei->lifelength + _settings_game.vehicle.extend_vehicle_life; |
0 | 275 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
276 |
/* prevent certain engines from ever appearing. */ |
10775
7061477bfbcf
(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
parents:
10737
diff
changeset
|
277 |
if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) { |
0 | 278 |
e->flags |= ENGINE_AVAILABLE; |
279 |
e->player_avail = 0; |
|
280 |
} |
|
281 |
} |
|
282 |
} |
|
283 |
||
6074 | 284 |
static void AcceptEnginePreview(EngineID eid, PlayerID player) |
0 | 285 |
{ |
6074 | 286 |
Engine *e = GetEngine(eid); |
7181
f966d75af3a6
(svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents:
7139
diff
changeset
|
287 |
Player *p = GetPlayer(player); |
0 | 288 |
|
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
289 |
SetBit(e->player_avail, player); |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6573
diff
changeset
|
290 |
if (e->type == VEH_TRAIN) { |
6074 | 291 |
const RailVehicleInfo *rvi = RailVehInfo(eid); |
292 |
||
293 |
assert(rvi->railtype < RAILTYPE_END); |
|
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
294 |
SetBit(p->avail_railtypes, rvi->railtype); |
7181
f966d75af3a6
(svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents:
7139
diff
changeset
|
295 |
} else if (e->type == VEH_ROAD) { |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
296 |
SetBit(p->avail_roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD); |
6074 | 297 |
} |
0 | 298 |
|
9061
fe9f2555d02e
(svn r12143) -Fix (r8038): Engine::preview_player does not contain a Player ID. Rename this to preview_player_rank and change back to a uint8 to avoid confusion.
peter1138
parents:
9005
diff
changeset
|
299 |
e->preview_player_rank = 0xFF; |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4549
diff
changeset
|
300 |
if (player == _local_player) { |
6195
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6119
diff
changeset
|
301 |
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4549
diff
changeset
|
302 |
} |
0 | 303 |
} |
304 |
||
9061
fe9f2555d02e
(svn r12143) -Fix (r8038): Engine::preview_player does not contain a Player ID. Rename this to preview_player_rank and change back to a uint8 to avoid confusion.
peter1138
parents:
9005
diff
changeset
|
305 |
static PlayerID GetBestPlayer(uint8 pp) |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
306 |
{ |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
307 |
const Player *p; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
308 |
int32 best_hist; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
309 |
PlayerID best_player; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
310 |
uint mask = 0; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
311 |
|
9068
ae69d946347e
(svn r12150) -Fix (r12143): compiler warnings - possible use of uninitialised variable
smatz
parents:
9061
diff
changeset
|
312 |
do { |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
313 |
best_hist = -1; |
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
314 |
best_player = PLAYER_SPECTATOR; |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
315 |
FOR_ALL_PLAYERS(p) { |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7884
diff
changeset
|
316 |
if (p->is_active && p->block_preview == 0 && !HasBit(mask, p->index) && |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
317 |
p->old_economy[0].performance_history > best_hist) { |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
318 |
best_hist = p->old_economy[0].performance_history; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
319 |
best_player = p->index; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
320 |
} |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
321 |
} |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
322 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
323 |
if (best_player == PLAYER_SPECTATOR) return PLAYER_SPECTATOR; |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
324 |
|
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
325 |
SetBit(mask, best_player); |
9129
e4a00ee7237b
(svn r12244) -Fix (r12150): typo resulting in no players are given the engine preview offer
smatz
parents:
9068
diff
changeset
|
326 |
} while (--pp != 0); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
327 |
|
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
328 |
return best_player; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
329 |
} |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
330 |
|
6573 | 331 |
void EnginesDailyLoop() |
0 | 332 |
{ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
333 |
if (_cur_year >= YEAR_ENGINE_AGING_STOPS) return; |
0 | 334 |
|
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
335 |
Engine *e; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
336 |
FOR_ALL_ENGINES(e) { |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
337 |
EngineID i = e->index; |
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
338 |
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) { |
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
339 |
if (e->flags & ENGINE_OFFER_WINDOW_OPEN) { |
9061
fe9f2555d02e
(svn r12143) -Fix (r8038): Engine::preview_player does not contain a Player ID. Rename this to preview_player_rank and change back to a uint8 to avoid confusion.
peter1138
parents:
9005
diff
changeset
|
340 |
if (e->preview_player_rank != 0xFF && !--e->preview_wait) { |
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
341 |
e->flags &= ~ENGINE_OFFER_WINDOW_OPEN; |
0 | 342 |
DeleteWindowById(WC_ENGINE_PREVIEW, i); |
9061
fe9f2555d02e
(svn r12143) -Fix (r8038): Engine::preview_player does not contain a Player ID. Rename this to preview_player_rank and change back to a uint8 to avoid confusion.
peter1138
parents:
9005
diff
changeset
|
343 |
e->preview_player_rank++; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
344 |
} |
9061
fe9f2555d02e
(svn r12143) -Fix (r8038): Engine::preview_player does not contain a Player ID. Rename this to preview_player_rank and change back to a uint8 to avoid confusion.
peter1138
parents:
9005
diff
changeset
|
345 |
} else if (e->preview_player_rank != 0xFF) { |
fe9f2555d02e
(svn r12143) -Fix (r8038): Engine::preview_player does not contain a Player ID. Rename this to preview_player_rank and change back to a uint8 to avoid confusion.
peter1138
parents:
9005
diff
changeset
|
346 |
PlayerID best_player = GetBestPlayer(e->preview_player_rank); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
347 |
|
4848
56549aa3e234
(svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents:
4845
diff
changeset
|
348 |
if (best_player == PLAYER_SPECTATOR) { |
9061
fe9f2555d02e
(svn r12143) -Fix (r8038): Engine::preview_player does not contain a Player ID. Rename this to preview_player_rank and change back to a uint8 to avoid confusion.
peter1138
parents:
9005
diff
changeset
|
349 |
e->preview_player_rank = 0xFF; |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
350 |
continue; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
351 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
352 |
|
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4792
diff
changeset
|
353 |
if (!IsHumanPlayer(best_player)) { |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
354 |
/* XXX - TTDBUG: TTD has a bug here ???? */ |
6074 | 355 |
AcceptEnginePreview(i, best_player); |
0 | 356 |
} else { |
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
357 |
e->flags |= ENGINE_OFFER_WINDOW_OPEN; |
0 | 358 |
e->preview_wait = 20; |
4845
49105d3b5a9a
(svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents:
4792
diff
changeset
|
359 |
if (IsInteractivePlayer(best_player)) ShowEnginePreviewWindow(i); |
0 | 360 |
} |
361 |
} |
|
362 |
} |
|
363 |
} |
|
364 |
} |
|
365 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
366 |
/** Accept an engine prototype. XXX - it is possible that the top-player |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
367 |
* changes while you are waiting to accept the offer? Then it becomes invalid |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
368 |
* @param tile unused |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6585
diff
changeset
|
369 |
* @param flags operation to perfom |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
370 |
* @param p1 engine-prototype offered |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
371 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
372 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7182
diff
changeset
|
373 |
CommandCost CmdWantEnginePreview(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 374 |
{ |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
375 |
Engine *e; |
2951 | 376 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
377 |
if (!IsEngineIndex(p1)) return CMD_ERROR; |
1926
68d60188a22f
(svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents:
1908
diff
changeset
|
378 |
e = GetEngine(p1); |
9061
fe9f2555d02e
(svn r12143) -Fix (r8038): Engine::preview_player does not contain a Player ID. Rename this to preview_player_rank and change back to a uint8 to avoid confusion.
peter1138
parents:
9005
diff
changeset
|
379 |
if (GetBestPlayer(e->preview_player_rank) != _current_player) return CMD_ERROR; |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
380 |
|
6074 | 381 |
if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_player); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
382 |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
383 |
return CommandCost(); |
0 | 384 |
} |
385 |
||
10521
79e3bb000aed
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
10453
diff
changeset
|
386 |
StringID GetEngineCategoryName(EngineID engine); |
79e3bb000aed
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
10453
diff
changeset
|
387 |
|
410 | 388 |
static void NewVehicleAvailable(Engine *e) |
0 | 389 |
{ |
390 |
Vehicle *v; |
|
391 |
Player *p; |
|
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
392 |
EngineID index = e->index; |
0 | 393 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
394 |
/* In case the player didn't build the vehicle during the intro period, |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
395 |
* prevent that player from getting future intro periods for a while. */ |
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
396 |
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) { |
0 | 397 |
FOR_ALL_PLAYERS(p) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
398 |
uint block_preview = p->block_preview; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
399 |
|
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7884
diff
changeset
|
400 |
if (!HasBit(e->player_avail, p->index)) continue; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
401 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
402 |
/* We assume the user did NOT build it.. prove me wrong ;) */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
403 |
p->block_preview = 20; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
404 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
405 |
FOR_ALL_VEHICLES(v) { |
6585
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6573
diff
changeset
|
406 |
if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP || |
7da94b26498a
(svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents:
6573
diff
changeset
|
407 |
(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) { |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
408 |
if (v->owner == p->index && v->engine_type == index) { |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
409 |
/* The user did prove me wrong, so restore old value */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
410 |
p->block_preview = block_preview; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
411 |
break; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
412 |
} |
0 | 413 |
} |
414 |
} |
|
415 |
} |
|
416 |
} |
|
417 |
||
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
418 |
e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE; |
6195
b90cf92697b9
(svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents:
6119
diff
changeset
|
419 |
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type); |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
420 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
421 |
/* Now available for all players */ |
0 | 422 |
e->player_avail = (byte)-1; |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
423 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
424 |
/* Do not introduce new rail wagons */ |
2639 | 425 |
if (IsWagon(index)) return; |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
426 |
|
8716
5e53a939e256
(svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138
parents:
8710
diff
changeset
|
427 |
if (e->type == VEH_TRAIN) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
428 |
/* maybe make another rail type available */ |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
429 |
RailType railtype = e->u.rail.railtype; |
6074 | 430 |
assert(railtype < RAILTYPE_END); |
431 |
FOR_ALL_PLAYERS(p) { |
|
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
8424
diff
changeset
|
432 |
if (p->is_active) SetBit(p->avail_railtypes, railtype); |
2147
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
2140
diff
changeset
|
433 |
} |
8716
5e53a939e256
(svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138
parents:
8710
diff
changeset
|
434 |
} else if (e->type == VEH_ROAD) { |
7182
644a1d06f2be
(svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents:
7181
diff
changeset
|
435 |
/* maybe make another road type available */ |
644a1d06f2be
(svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents:
7181
diff
changeset
|
436 |
FOR_ALL_PLAYERS(p) { |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
437 |
if (p->is_active) SetBit(p->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD); |
7182
644a1d06f2be
(svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents:
7181
diff
changeset
|
438 |
} |
644a1d06f2be
(svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents:
7181
diff
changeset
|
439 |
} |
10521
79e3bb000aed
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
10453
diff
changeset
|
440 |
|
79e3bb000aed
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
10453
diff
changeset
|
441 |
SetDParam(0, GetEngineCategoryName(index)); |
79e3bb000aed
(svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents:
10453
diff
changeset
|
442 |
SetDParam(1, index); |
10556
ec733f5899fa
(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
parents:
10545
diff
changeset
|
443 |
AddNewsItem(STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NS_NEW_VEHICLES, index, 0); |
0 | 444 |
} |
445 |
||
6573 | 446 |
void EnginesMonthlyLoop() |
0 | 447 |
{ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4297
diff
changeset
|
448 |
if (_cur_year < YEAR_ENGINE_AGING_STOPS) { |
8897
fe3716f7d205
(svn r11971) -Codechange: use of FOR_ALL_ENGINES/ENGINEIDS_OF_TYPE instead of for-loops
peter1138
parents:
8896
diff
changeset
|
449 |
Engine *e; |
fe3716f7d205
(svn r11971) -Codechange: use of FOR_ALL_ENGINES/ENGINEIDS_OF_TYPE instead of for-loops
peter1138
parents:
8896
diff
changeset
|
450 |
FOR_ALL_ENGINES(e) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
451 |
/* Age the vehicle */ |
2242
27fa4807cd61
(svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents:
2204
diff
changeset
|
452 |
if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) { |
0 | 453 |
e->age++; |
454 |
CalcEngineReliability(e); |
|
455 |
} |
|
456 |
||
2990
352b4590ee1c
(svn r3565) - Fix: On loading a game, GetPlayerRailtypes() didn't account for the fact that vehicles are introduced a year after their introduction date. This will also relieve possible (rare) network desyncs.
peter1138
parents:
2962
diff
changeset
|
457 |
if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + 365)) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
458 |
/* Introduce it to all players */ |
0 | 459 |
NewVehicleAvailable(e); |
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
460 |
} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) { |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
461 |
/* Introduction date has passed.. show introducing dialog to one player. */ |
6500
08ea5741ee39
(svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents:
6451
diff
changeset
|
462 |
e->flags |= ENGINE_EXCLUSIVE_PREVIEW; |
257
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
463 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
464 |
/* Do not introduce new rail wagons */ |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
465 |
if (!IsWagon(e->index)) |
9061
fe9f2555d02e
(svn r12143) -Fix (r8038): Engine::preview_player does not contain a Player ID. Rename this to preview_player_rank and change back to a uint8 to avoid confusion.
peter1138
parents:
9005
diff
changeset
|
466 |
e->preview_player_rank = 1; // Give to the player with the highest rating. |
0 | 467 |
} |
468 |
} |
|
469 |
} |
|
470 |
} |
|
471 |
||
7593
cfce84f8995c
(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
parents:
7446
diff
changeset
|
472 |
static bool IsUniqueEngineName(const char *name) |
cfce84f8995c
(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
parents:
7446
diff
changeset
|
473 |
{ |
cfce84f8995c
(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
parents:
7446
diff
changeset
|
474 |
char buf[512]; |
cfce84f8995c
(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
parents:
7446
diff
changeset
|
475 |
|
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
476 |
const Engine *e; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
477 |
FOR_ALL_ENGINES(e) { |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
478 |
SetDParam(0, e->index); |
7593
cfce84f8995c
(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
parents:
7446
diff
changeset
|
479 |
GetString(buf, STR_ENGINE_NAME, lastof(buf)); |
cfce84f8995c
(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
parents:
7446
diff
changeset
|
480 |
if (strcmp(buf, name) == 0) return false; |
cfce84f8995c
(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
parents:
7446
diff
changeset
|
481 |
} |
cfce84f8995c
(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
parents:
7446
diff
changeset
|
482 |
|
cfce84f8995c
(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
parents:
7446
diff
changeset
|
483 |
return true; |
cfce84f8995c
(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
parents:
7446
diff
changeset
|
484 |
} |
cfce84f8995c
(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
parents:
7446
diff
changeset
|
485 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
486 |
/** Rename an engine. |
3491
4c8427796c64
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents:
3222
diff
changeset
|
487 |
* @param tile unused |
6977
67b989528f3d
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6585
diff
changeset
|
488 |
* @param flags operation to perfom |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
489 |
* @param p1 engine ID to rename |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
490 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
491 |
*/ |
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7182
diff
changeset
|
492 |
CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
0 | 493 |
{ |
7593
cfce84f8995c
(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
parents:
7446
diff
changeset
|
494 |
if (!IsEngineIndex(p1) || StrEmpty(_cmd_text)) return CMD_ERROR; |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
495 |
|
7593
cfce84f8995c
(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
parents:
7446
diff
changeset
|
496 |
if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE); |
cfce84f8995c
(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
parents:
7446
diff
changeset
|
497 |
|
0 | 498 |
if (flags & DC_EXEC) { |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
499 |
Engine *e = GetEngine(p1); |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
500 |
free(e->name); |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
501 |
e->name = strdup(_cmd_text); |
0 | 502 |
_vehicle_design_names |= 3; |
503 |
MarkWholeScreenDirty(); |
|
504 |
} |
|
505 |
||
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
506 |
return CommandCost(); |
0 | 507 |
} |
508 |
||
509 |
||
8975
303deb99982d
(svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138
parents:
8897
diff
changeset
|
510 |
/** Check if an engine is buildable. |
303deb99982d
(svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138
parents:
8897
diff
changeset
|
511 |
* @param engine index of the engine to check. |
303deb99982d
(svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138
parents:
8897
diff
changeset
|
512 |
* @param type the type the engine should be. |
303deb99982d
(svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138
parents:
8897
diff
changeset
|
513 |
* @param player index of the player. |
303deb99982d
(svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138
parents:
8897
diff
changeset
|
514 |
* @return True if an engine is valid, of the specified type, and buildable by |
303deb99982d
(svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138
parents:
8897
diff
changeset
|
515 |
* the given player. |
2848 | 516 |
*/ |
8975
303deb99982d
(svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138
parents:
8897
diff
changeset
|
517 |
bool IsEngineBuildable(EngineID engine, VehicleType type, PlayerID player) |
2848 | 518 |
{ |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
519 |
/* check if it's an engine that is in the engine array */ |
2848 | 520 |
if (!IsEngineIndex(engine)) return false; |
521 |
||
8975
303deb99982d
(svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138
parents:
8897
diff
changeset
|
522 |
const Engine *e = GetEngine(engine); |
2848 | 523 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
524 |
/* check if it's an engine of specified type */ |
2848 | 525 |
if (e->type != type) return false; |
526 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
527 |
/* check if it's available */ |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7884
diff
changeset
|
528 |
if (!HasBit(e->player_avail, player)) return false; |
2848 | 529 |
|
7026
7ef9437cf867
(svn r9718) -Fix: Don't allow building of rail vehicles whose railtype isn't available yet. This also affects the rail purchase window.
peter1138
parents:
7001
diff
changeset
|
530 |
if (type == VEH_TRAIN) { |
7ef9437cf867
(svn r9718) -Fix: Don't allow building of rail vehicles whose railtype isn't available yet. This also affects the rail purchase window.
peter1138
parents:
7001
diff
changeset
|
531 |
/* Check if the rail type is available to this player */ |
7ef9437cf867
(svn r9718) -Fix: Don't allow building of rail vehicles whose railtype isn't available yet. This also affects the rail purchase window.
peter1138
parents:
7001
diff
changeset
|
532 |
const Player *p = GetPlayer(player); |
8424
4a488a90ccab
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7884
diff
changeset
|
533 |
if (!HasBit(p->avail_railtypes, RailVehInfo(engine)->railtype)) return false; |
7026
7ef9437cf867
(svn r9718) -Fix: Don't allow building of rail vehicles whose railtype isn't available yet. This also affects the rail purchase window.
peter1138
parents:
7001
diff
changeset
|
534 |
} |
7ef9437cf867
(svn r9718) -Fix: Don't allow building of rail vehicles whose railtype isn't available yet. This also affects the rail purchase window.
peter1138
parents:
7001
diff
changeset
|
535 |
|
2848 | 536 |
return true; |
537 |
} |
|
538 |
||
7001
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
539 |
/** Get the default cargo type for a certain engine type |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
540 |
* @param engine The ID to get the cargo for |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
541 |
* @return The cargo type. CT_INVALID means no cargo capacity |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
542 |
*/ |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
543 |
CargoID GetEngineCargoType(EngineID engine) |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
544 |
{ |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
545 |
assert(IsEngineIndex(engine)); |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
546 |
|
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
547 |
switch (GetEngine(engine)->type) { |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
548 |
case VEH_TRAIN: |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
549 |
if (RailVehInfo(engine)->capacity == 0) return CT_INVALID; |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
550 |
return RailVehInfo(engine)->cargo_type; |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
551 |
|
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
552 |
case VEH_ROAD: |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
553 |
if (RoadVehInfo(engine)->capacity == 0) return CT_INVALID; |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
554 |
return RoadVehInfo(engine)->cargo_type; |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
555 |
|
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
556 |
case VEH_SHIP: |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
557 |
if (ShipVehInfo(engine)->capacity == 0) return CT_INVALID; |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
558 |
return ShipVehInfo(engine)->cargo_type; |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
559 |
|
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
560 |
case VEH_AIRCRAFT: |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
561 |
/* all aircraft starts as passenger planes with cargo capacity */ |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
562 |
return CT_PASSENGERS; |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
563 |
|
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
564 |
default: NOT_REACHED(); return CT_INVALID; |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
565 |
} |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
566 |
} |
d5f19455d650
(svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents:
6977
diff
changeset
|
567 |
|
2848 | 568 |
/************************************************************************ |
569 |
* Engine Replacement stuff |
|
570 |
************************************************************************/ |
|
571 |
||
7884
79fa68c2a6ae
(svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents:
7754
diff
changeset
|
572 |
DEFINE_OLD_POOL_GENERIC(EngineRenew, EngineRenew) |
2848 | 573 |
|
574 |
/** |
|
575 |
* Retrieves the EngineRenew that specifies the replacement of the given |
|
576 |
* engine type from the given renewlist */ |
|
7139
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
577 |
static EngineRenew *GetEngineReplacement(EngineRenewList erl, EngineID engine, GroupID group) |
2848 | 578 |
{ |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
579 |
EngineRenew *er = (EngineRenew *)erl; |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
580 |
|
2848 | 581 |
while (er) { |
7139
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
582 |
if (er->from == engine && er->group_id == group) return er; |
2848 | 583 |
er = er->next; |
584 |
} |
|
585 |
return NULL; |
|
586 |
} |
|
587 |
||
4171 | 588 |
void RemoveAllEngineReplacement(EngineRenewList *erl) |
2848 | 589 |
{ |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
590 |
EngineRenew *er = (EngineRenew *)(*erl); |
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4358
diff
changeset
|
591 |
EngineRenew *next; |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
592 |
|
7884
79fa68c2a6ae
(svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents:
7754
diff
changeset
|
593 |
while (er != NULL) { |
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4358
diff
changeset
|
594 |
next = er->next; |
7884
79fa68c2a6ae
(svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents:
7754
diff
changeset
|
595 |
delete er; |
4384
293c0d26294c
(svn r6137) -Codechange: some very minor cleanups:
truelight
parents:
4358
diff
changeset
|
596 |
er = next; |
2848 | 597 |
} |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
598 |
*erl = NULL; // Empty list |
2848 | 599 |
} |
600 |
||
7139
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
601 |
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group) |
2848 | 602 |
{ |
7139
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
603 |
const EngineRenew *er = GetEngineReplacement(erl, engine, group); |
8803
0c8a0c6d9686
(svn r11872) -Fix (r9874): EngineHasReplacementForPlayer() didn't look in ALL_GROUP
bjarni
parents:
8766
diff
changeset
|
604 |
if (er == NULL && (group == DEFAULT_GROUP || (IsValidGroupID(group) && !GetGroup(group)->replace_protection))) { |
0c8a0c6d9686
(svn r11872) -Fix (r9874): EngineHasReplacementForPlayer() didn't look in ALL_GROUP
bjarni
parents:
8766
diff
changeset
|
605 |
/* We didn't find anything useful in the vehicle's own group so we will try ALL_GROUP */ |
0c8a0c6d9686
(svn r11872) -Fix (r9874): EngineHasReplacementForPlayer() didn't look in ALL_GROUP
bjarni
parents:
8766
diff
changeset
|
606 |
er = GetEngineReplacement(erl, engine, ALL_GROUP); |
0c8a0c6d9686
(svn r11872) -Fix (r9874): EngineHasReplacementForPlayer() didn't look in ALL_GROUP
bjarni
parents:
8766
diff
changeset
|
607 |
} |
2848 | 608 |
return er == NULL ? INVALID_ENGINE : er->to; |
609 |
} |
|
610 |
||
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7182
diff
changeset
|
611 |
CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags) |
2848 | 612 |
{ |
613 |
EngineRenew *er; |
|
614 |
||
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
615 |
/* Check if the old vehicle is already in the list */ |
7139
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
616 |
er = GetEngineReplacement(*erl, old_engine, group); |
2848 | 617 |
if (er != NULL) { |
618 |
if (flags & DC_EXEC) er->to = new_engine; |
|
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
619 |
return CommandCost(); |
2848 | 620 |
} |
621 |
||
10314
9cfcdd5b5ddb
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
9343
diff
changeset
|
622 |
if (!EngineRenew::CanAllocateItem()) return CMD_ERROR; |
2848 | 623 |
|
624 |
if (flags & DC_EXEC) { |
|
10314
9cfcdd5b5ddb
(svn r12855) -Codechange: do not use autoptr's for testing whether certain objects can be build, but check it directly in the pool so we do not have to call destructors in the testing phase. Stations still use the autoptr though.
rubidium
parents:
9343
diff
changeset
|
625 |
er = new EngineRenew(old_engine, new_engine); |
7139
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
626 |
er->group_id = group; |
2848 | 627 |
|
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
628 |
/* Insert before the first element */ |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
629 |
er->next = (EngineRenew *)(*erl); |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
630 |
*erl = (EngineRenewList)er; |
2848 | 631 |
} |
632 |
||
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
633 |
return CommandCost(); |
2848 | 634 |
} |
635 |
||
7439
0c0e2945c890
(svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents:
7182
diff
changeset
|
636 |
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags) |
2848 | 637 |
{ |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
638 |
EngineRenew *er = (EngineRenew *)(*erl); |
4171 | 639 |
EngineRenew *prev = NULL; |
2848 | 640 |
|
641 |
while (er) |
|
642 |
{ |
|
7139
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
643 |
if (er->from == engine && er->group_id == group) { |
2848 | 644 |
if (flags & DC_EXEC) { |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
645 |
if (prev == NULL) { // First element |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
646 |
/* The second becomes the new first element */ |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
647 |
*erl = (EngineRenewList)er->next; |
2848 | 648 |
} else { |
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
649 |
/* Cut this element out */ |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
650 |
prev->next = er->next; |
2848 | 651 |
} |
7884
79fa68c2a6ae
(svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents:
7754
diff
changeset
|
652 |
delete er; |
2848 | 653 |
} |
7446
1c4d469f986e
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
7439
diff
changeset
|
654 |
return CommandCost(); |
2848 | 655 |
} |
656 |
prev = er; |
|
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
657 |
er = er->next; |
2848 | 658 |
} |
659 |
||
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
660 |
return CMD_ERROR; |
2848 | 661 |
} |
662 |
||
663 |
static const SaveLoad _engine_renew_desc[] = { |
|
7139
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
664 |
SLE_VAR(EngineRenew, from, SLE_UINT16), |
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
665 |
SLE_VAR(EngineRenew, to, SLE_UINT16), |
2848 | 666 |
|
7139
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
667 |
SLE_REF(EngineRenew, next, REF_ENGINE_RENEWS), |
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
668 |
SLE_CONDVAR(EngineRenew, group_id, SLE_UINT16, 60, SL_MAX_VERSION), |
2848 | 669 |
SLE_END() |
670 |
}; |
|
671 |
||
6573 | 672 |
static void Save_ERNW() |
2848 | 673 |
{ |
674 |
EngineRenew *er; |
|
675 |
||
676 |
FOR_ALL_ENGINE_RENEWS(er) { |
|
4348
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
677 |
SlSetArrayIndex(er->index); |
95ba9ff1612e
(svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents:
4346
diff
changeset
|
678 |
SlObject(er, _engine_renew_desc); |
2848 | 679 |
} |
680 |
} |
|
681 |
||
6573 | 682 |
static void Load_ERNW() |
2848 | 683 |
{ |
684 |
int index; |
|
685 |
||
686 |
while ((index = SlIterateArray()) != -1) { |
|
7884
79fa68c2a6ae
(svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents:
7754
diff
changeset
|
687 |
EngineRenew *er = new (index) EngineRenew(); |
2848 | 688 |
SlObject(er, _engine_renew_desc); |
7139
4ae3ab180d05
(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
parents:
7102
diff
changeset
|
689 |
|
7754
8e7205edd6c7
(svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents:
7593
diff
changeset
|
690 |
/* Advanced vehicle lists, ungrouped vehicles got added */ |
8e7205edd6c7
(svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents:
7593
diff
changeset
|
691 |
if (CheckSavegameVersion(60)) { |
8e7205edd6c7
(svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents:
7593
diff
changeset
|
692 |
er->group_id = ALL_GROUP; |
8e7205edd6c7
(svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents:
7593
diff
changeset
|
693 |
} else if (CheckSavegameVersion(71)) { |
8e7205edd6c7
(svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents:
7593
diff
changeset
|
694 |
if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_GROUP; |
8e7205edd6c7
(svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents:
7593
diff
changeset
|
695 |
} |
2848 | 696 |
} |
697 |
} |
|
698 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1855
diff
changeset
|
699 |
static const SaveLoad _engine_desc[] = { |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
700 |
SLE_CONDVAR(Engine, intro_date, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
701 |
SLE_CONDVAR(Engine, intro_date, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
702 |
SLE_CONDVAR(Engine, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
703 |
SLE_CONDVAR(Engine, age, SLE_INT32, 31, SL_MAX_VERSION), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
704 |
SLE_VAR(Engine, reliability, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
705 |
SLE_VAR(Engine, reliability_spd_dec, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
706 |
SLE_VAR(Engine, reliability_start, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
707 |
SLE_VAR(Engine, reliability_max, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
708 |
SLE_VAR(Engine, reliability_final, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
709 |
SLE_VAR(Engine, duration_phase_1, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
710 |
SLE_VAR(Engine, duration_phase_2, SLE_UINT16), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
711 |
SLE_VAR(Engine, duration_phase_3, SLE_UINT16), |
0 | 712 |
|
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
713 |
SLE_VAR(Engine, lifelength, SLE_UINT8), |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
714 |
SLE_VAR(Engine, flags, SLE_UINT8), |
9061
fe9f2555d02e
(svn r12143) -Fix (r8038): Engine::preview_player does not contain a Player ID. Rename this to preview_player_rank and change back to a uint8 to avoid confusion.
peter1138
parents:
9005
diff
changeset
|
715 |
SLE_VAR(Engine, preview_player_rank, SLE_UINT8), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
716 |
SLE_VAR(Engine, preview_wait, SLE_UINT8), |
6074 | 717 |
SLE_CONDNULL(1, 0, 44), |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
718 |
SLE_VAR(Engine, player_avail, SLE_UINT8), |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
719 |
SLE_CONDSTR(Engine, name, SLE_STR, 0, 84, SL_MAX_VERSION), |
0 | 720 |
|
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
6222
diff
changeset
|
721 |
/* reserve extra space in savegame here. (currently 16 bytes) */ |
3222
8bfed4267cba
(svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents:
3047
diff
changeset
|
722 |
SLE_CONDNULL(16, 2, SL_MAX_VERSION), |
0 | 723 |
|
724 |
SLE_END() |
|
725 |
}; |
|
726 |
||
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
727 |
static std::map<EngineID, Engine> _temp_engine; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
728 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
729 |
Engine *GetTempDataEngine(EngineID index) |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
730 |
{ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
731 |
return &_temp_engine[index]; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
732 |
} |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
733 |
|
6573 | 734 |
static void Save_ENGN() |
0 | 735 |
{ |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
736 |
Engine *e; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
737 |
FOR_ALL_ENGINES(e) { |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
738 |
SlSetArrayIndex(e->index); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
739 |
SlObject(e, _engine_desc); |
0 | 740 |
} |
741 |
} |
|
742 |
||
6573 | 743 |
static void Load_ENGN() |
0 | 744 |
{ |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
745 |
/* As engine data is loaded before engines are initialized we need to load |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
746 |
* this information into a temporary array. This is then copied into the |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
747 |
* engine pool after processing NewGRFs by CopyTempEngineData(). */ |
0 | 748 |
int index; |
749 |
while ((index = SlIterateArray()) != -1) { |
|
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
750 |
Engine *e = GetTempDataEngine(index); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
751 |
SlObject(e, _engine_desc); |
0 | 752 |
} |
753 |
} |
|
754 |
||
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
755 |
/** |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
756 |
* Copy data from temporary engine array into the real engine pool. |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
757 |
*/ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
758 |
void CopyTempEngineData() |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
759 |
{ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
760 |
Engine *e; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
761 |
FOR_ALL_ENGINES(e) { |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
762 |
if (e->index >= _temp_engine.size()) break; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
763 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
764 |
const Engine *se = GetTempDataEngine(e->index); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
765 |
e->intro_date = se->intro_date; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
766 |
e->age = se->age; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
767 |
e->reliability = se->reliability; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
768 |
e->reliability_spd_dec = se->reliability_spd_dec; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
769 |
e->reliability_start = se->reliability_start; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
770 |
e->reliability_max = se->reliability_max; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
771 |
e->reliability_final = se->reliability_final; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
772 |
e->duration_phase_1 = se->duration_phase_1; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
773 |
e->duration_phase_2 = se->duration_phase_2; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
774 |
e->duration_phase_3 = se->duration_phase_3; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
775 |
e->lifelength = se->lifelength; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
776 |
e->flags = se->flags; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
777 |
e->preview_player_rank = se->preview_player_rank; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
778 |
e->preview_wait = se->preview_wait; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
779 |
e->player_avail = se->player_avail; |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
780 |
if (se->name != NULL) e->name = strdup(se->name); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
781 |
} |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
782 |
|
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
783 |
/* Get rid of temporary data */ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
784 |
_temp_engine.clear(); |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
785 |
} |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
786 |
|
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
787 |
static void Load_ENGS() |
0 | 788 |
{ |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
789 |
/* Load old separate String ID list into a temporary array. This |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
790 |
* was always 256 entries. */ |
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
791 |
StringID names[256]; |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
792 |
|
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
793 |
SlArray(names, lengthof(names), SLE_STRINGID); |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
794 |
|
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
795 |
/* Copy each string into the temporary engine array. */ |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
796 |
for (EngineID engine = 0; engine < lengthof(names); engine++) { |
10382
d1d4452acbfc
(svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents:
10314
diff
changeset
|
797 |
Engine *e = GetTempDataEngine(engine); |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
798 |
e->name = CopyFromOldName(names[engine]); |
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
799 |
} |
0 | 800 |
} |
801 |
||
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
802 |
extern const ChunkHandler _engine_chunk_handlers[] = { |
2848 | 803 |
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY }, |
8754
5dae65402806
(svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents:
8750
diff
changeset
|
804 |
{ 'ENGS', NULL, Load_ENGS, CH_RIFF }, |
2848 | 805 |
{ 'ERNW', Save_ERNW, Load_ERNW, CH_ARRAY | CH_LAST}, |
0 | 806 |
}; |
807 |
||
6573 | 808 |
void InitializeEngines() |
1197 | 809 |
{ |
2848 | 810 |
/* Clean the engine renew pool and create 1 block in it */ |
7884
79fa68c2a6ae
(svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents:
7754
diff
changeset
|
811 |
_EngineRenew_pool.CleanPool(); |
79fa68c2a6ae
(svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents:
7754
diff
changeset
|
812 |
_EngineRenew_pool.AddBlockToPool(); |
1196
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
813 |
} |