src/engine.cpp
author rubidium
Thu, 18 Dec 2008 12:23:08 +0000
changeset 10436 8d3a9fbe8f19
parent 10430 3125f2adebc5
permissions -rw-r--r--
(svn r14689) -Change: make configure die on commonly made user mistakes, like not having SDL development files or zlib headers installed; you can still compile a dedicated server or a binary without zlib, but you have to explicitly force it.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (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: 9070
diff changeset
     3
/** @file engine.cpp Base for all engine handling. */
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1883
diff changeset
     6
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1197
diff changeset
     7
#include "debug.h"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
     8
#include "company_base.h"
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
     9
#include "company_func.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8114
diff changeset
    10
#include "command_func.h"
8763
81fadd257f67 (svn r12459) -Codechange: split news.h into news_type.h and news_func.h.
rubidium
parents: 8633
diff changeset
    11
#include "news_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "saveload.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2147
diff changeset
    13
#include "variables.h"
2708
48714bad9499 (svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents: 2639
diff changeset
    14
#include "train.h"
5854
9eee280920f0 (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: 5840
diff changeset
    15
#include "aircraft.h"
3866
b13553406a0a (svn r4902) Newgrf : Introduction of the newgrf_cargo files.
belugas
parents: 3865
diff changeset
    16
#include "newgrf_cargo.h"
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    17
#include "newgrf_engine.h"
6643
f81bee57bc09 (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: 6606
diff changeset
    18
#include "group.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 7931
diff changeset
    19
#include "strings_func.h"
8225
cd84a95b6630 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8221
diff changeset
    20
#include "gfx_func.h"
8131
160939e24ed3 (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: 8121
diff changeset
    21
#include "functions.h"
160939e24ed3 (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: 8121
diff changeset
    22
#include "window_func.h"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8131
diff changeset
    23
#include "date_func.h"
8212
cf3fce5c7464 (svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents: 8144
diff changeset
    24
#include "autoreplace_gui.h"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8212
diff changeset
    25
#include "string_func.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8268
diff changeset
    26
#include "settings_type.h"
8847
426dd2d582e7 (svn r12599) -Codechange: force AllocateSafeRaw() to be linked to simplify compiler's decisions about inlining
smatz
parents: 8786
diff changeset
    27
#include "oldpool_func.h"
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    28
#include "core/alloc_func.hpp"
9211
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
    29
#include "vehicle_func.h"
9417
7ba17fb5110b (svn r13331) -Fix (r12924): Wrong include type for (sdt::)map
peter1138
parents: 9413
diff changeset
    30
#include <map>
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    32
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    33
#include "table/engines.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    34
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    35
DEFINE_OLD_POOL_GENERIC(Engine, Engine)
2763
a4d065e3261b (svn r3308) BAD
tron
parents: 2708
diff changeset
    36
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
enum {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
    38
	YEAR_ENGINE_AGING_STOPS = 2050,
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
    39
};
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
    40
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    42
/** Number of engines of each vehicle type in original engine data */
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    43
const uint8 _engine_counts[4] = {
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    44
	lengthof(_orig_rail_vehicle_info),
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    45
	lengthof(_orig_road_vehicle_info),
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    46
	lengthof(_orig_ship_vehicle_info),
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    47
	lengthof(_orig_aircraft_vehicle_info),
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    48
};
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    49
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    50
/** Offset of the first engine of each vehicle type in original engine data */
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    51
const uint8 _engine_offsets[4] = {
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    52
	0,
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    53
	lengthof(_orig_rail_vehicle_info),
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    54
	lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info),
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    55
	lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info),
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    56
};
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    57
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    58
Engine::Engine() :
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    59
	name(NULL),
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    60
	overrides_count(0),
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    61
	overrides(NULL)
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    62
{
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    63
}
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    64
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    65
Engine::Engine(VehicleType type, EngineID base)
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    66
{
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    67
	this->type = type;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    68
	this->internal_id = base;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    69
	this->list_position = base;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    70
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    71
	/* Check if this base engine is within the original engine data range */
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    72
	if (base >= _engine_counts[type]) {
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    73
		/* Mark engine as valid anyway */
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    74
		this->info.climates = 0x80;
10427
cf023efb9a97 (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch
parents: 10208
diff changeset
    75
		/* Set model life to maximum to make wagons available */
cf023efb9a97 (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch
parents: 10208
diff changeset
    76
		this->info.base_life = 0xFF;
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    77
		return;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    78
	}
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    79
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    80
	/* Copy the original engine info for this slot */
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    81
	this->info = _orig_engine_info[_engine_offsets[type] + base];
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    82
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    83
	/* Copy the original engine data for this slot */
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    84
	switch (type) {
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    85
		default: NOT_REACHED();
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    86
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    87
		case VEH_TRAIN:
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    88
			this->u.rail = _orig_rail_vehicle_info[base];
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    89
			this->image_index = this->u.rail.image_index;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    90
			this->info.string_id = STR_8000_KIRBY_PAUL_TANK_STEAM + base;
10427
cf023efb9a97 (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch
parents: 10208
diff changeset
    91
cf023efb9a97 (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch
parents: 10208
diff changeset
    92
			/* Set the default model life of original wagons to "infinite" */
cf023efb9a97 (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch
parents: 10208
diff changeset
    93
			if (this->u.rail.railveh_type == RAILVEH_WAGON) this->info.base_life = 0xFF;
cf023efb9a97 (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch
parents: 10208
diff changeset
    94
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    95
			break;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    96
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    97
		case VEH_ROAD:
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    98
			this->u.road = _orig_road_vehicle_info[base];
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
    99
			this->image_index = this->u.road.image_index;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   100
			this->info.string_id = STR_8074_MPS_REGAL_BUS + base;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   101
			break;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   102
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   103
		case VEH_SHIP:
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   104
			this->u.ship = _orig_ship_vehicle_info[base];
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   105
			this->image_index = this->u.ship.image_index;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   106
			this->info.string_id = STR_80CC_MPS_OIL_TANKER + base;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   107
			break;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   108
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   109
		case VEH_AIRCRAFT:
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   110
			this->u.air = _orig_aircraft_vehicle_info[base];
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   111
			this->image_index = this->u.air.image_index;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   112
			this->info.string_id = STR_80D7_SAMPSON_U52 + base;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   113
			break;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   114
	}
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   115
}
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   116
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   117
Engine::~Engine()
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   118
{
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   119
	UnloadWagonOverrides(this);
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   120
	free(this->name);
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   121
}
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   122
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   123
/** Sets cached values in Company::num_vehicles and Group::num_vehicles
9220
125a9aaf4b0a (svn r13086) -Fix: do not crash badly after loading a newgrf with engines in-game that often
smatz
parents: 9211
diff changeset
   124
 */
9211
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   125
void SetCachedEngineCounts()
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   126
{
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   127
	uint engines = GetEnginePoolSize();
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   128
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   129
	/* Set up the engine count for all companies */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   130
	Company *c;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   131
	FOR_ALL_COMPANIES(c) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   132
		free(c->num_engines);
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   133
		c->num_engines = CallocT<EngineID>(engines);
9211
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   134
	}
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   135
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   136
	/* Recalculate */
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   137
	Group *g;
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   138
	FOR_ALL_GROUPS(g) {
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   139
		free(g->num_engines);
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   140
		g->num_engines = CallocT<EngineID>(engines);
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   141
	}
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   142
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   143
	const Vehicle *v;
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   144
	FOR_ALL_VEHICLES(v) {
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   145
		if (!IsEngineCountable(v)) continue;
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   146
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   147
		assert(v->engine_type < engines);
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   148
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   149
		GetCompany(v->owner)->num_engines[v->engine_type]++;
9211
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   150
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   151
		if (v->group_id == DEFAULT_GROUP) continue;
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   152
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   153
		g = GetGroup(v->group_id);
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   154
		assert(v->type == g->vehicle_type);
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   155
		assert(v->owner == g->owner);
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   156
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   157
		g->num_engines[v->engine_type]++;
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   158
	}
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   159
}
a7347659b84a (svn r13077) -Codechange: move function that updates cached num_engines to engine.cpp, make it run only 1 loop
smatz
parents: 9206
diff changeset
   160
8221
59791d0e0c04 (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8220
diff changeset
   161
void SetupEngines()
59791d0e0c04 (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8220
diff changeset
   162
{
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   163
	_Engine_pool.CleanPool();
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   164
	_Engine_pool.AddBlockToPool();
8221
59791d0e0c04 (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8220
diff changeset
   165
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   166
	for (uint i = 0; i < lengthof(_orig_rail_vehicle_info); i++) new Engine(VEH_TRAIN, i);
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   167
	for (uint i = 0; i < lengthof(_orig_road_vehicle_info); i++) new Engine(VEH_ROAD, i);
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   168
	for (uint i = 0; i < lengthof(_orig_ship_vehicle_info); i++) new Engine(VEH_SHIP, i);
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   169
	for (uint i = 0; i < lengthof(_orig_aircraft_vehicle_info); i++) new Engine(VEH_AIRCRAFT, i);
8221
59791d0e0c04 (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8220
diff changeset
   170
}
59791d0e0c04 (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8220
diff changeset
   171
59791d0e0c04 (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8220
diff changeset
   172
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2469
diff changeset
   173
void ShowEnginePreviewWindow(EngineID engine);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   175
void DeleteCustomEngineNames()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
{
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   177
	Engine *e;
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   178
	FOR_ALL_ENGINES(e) {
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   179
		free(e->name);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   180
		e->name = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
	_vehicle_design_names &= ~1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   186
void LoadCustomEngineNames()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
{
4432
372316ca7924 (svn r6195) -Codechange: do not use '//' in '/* ... */' style comments and '/*' or '*/' in '//' style comments.
rubidium
parents: 4384
diff changeset
   188
	/* XXX: not done */
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5216
diff changeset
   189
	DEBUG(misc, 1, "LoadCustomEngineNames: not done");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
9468
7087fa70cfd4 (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 9417
diff changeset
   192
/* Determine if an engine type is a wagon (and not a loco) */
7087fa70cfd4 (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 9417
diff changeset
   193
static bool IsWagon(EngineID index)
7087fa70cfd4 (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 9417
diff changeset
   194
{
7087fa70cfd4 (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 9417
diff changeset
   195
	const Engine *e = GetEngine(index);
7087fa70cfd4 (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 9417
diff changeset
   196
	return e->type == VEH_TRAIN && e->u.rail.railveh_type == RAILVEH_WAGON;
7087fa70cfd4 (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 9417
diff changeset
   197
}
7087fa70cfd4 (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 9417
diff changeset
   198
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
static void CalcEngineReliability(Engine *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	uint age = e->age;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
6606
cc9f292f7223 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 6530
diff changeset
   203
	/* Check for early retirement */
10427
cf023efb9a97 (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch
parents: 10208
diff changeset
   204
	if (e->company_avail != 0 && !_settings_game.vehicle.never_expire_vehicles && e->info.base_life != 0xFF) {
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   205
		int retire_early = e->info.retire_early;
8509
84c0cc012ad3 (svn r12084) -Fix: 'Early retirement'-properties are signed.
frosch
parents: 8479
diff changeset
   206
		uint retire_early_max_age = max(0, e->duration_phase_1 + e->duration_phase_2 - retire_early * 12);
84c0cc012ad3 (svn r12084) -Fix: 'Early retirement'-properties are signed.
frosch
parents: 8479
diff changeset
   207
		if (retire_early != 0 && age >= retire_early_max_age) {
6606
cc9f292f7223 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 6530
diff changeset
   208
			/* Early retirement is enabled and we're past the date... */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   209
			e->company_avail = 0;
6606
cc9f292f7223 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 6530
diff changeset
   210
			AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
cc9f292f7223 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 6530
diff changeset
   211
		}
cc9f292f7223 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 6530
diff changeset
   212
	}
cc9f292f7223 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 6530
diff changeset
   213
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
	if (age < e->duration_phase_1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
		uint start = e->reliability_start;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
		e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start;
10427
cf023efb9a97 (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch
parents: 10208
diff changeset
   217
	} else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _settings_game.vehicle.never_expire_vehicles || e->info.base_life == 0xFF) {
4767
df84b7f59e5b (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
   218
		/* We are at the peak of this engines life. It will have max reliability.
df84b7f59e5b (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
   219
		 * This is also true if the engines never expire. They will not go bad over time */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
		e->reliability = e->reliability_max;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
	} else if ((age -= e->duration_phase_2) < e->duration_phase_3) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
		uint max = e->reliability_max;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
		e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
	} else {
4767
df84b7f59e5b (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
   225
		/* time's up for this engine.
df84b7f59e5b (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
   226
		 * We will now completely retire this design */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   227
		e->company_avail = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
		e->reliability = e->reliability_final;
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5868
diff changeset
   229
		/* Kick this engine out of the lists */
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5868
diff changeset
   230
		AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	}
4767
df84b7f59e5b (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
   232
	InvalidateWindowClasses(WC_BUILD_VEHICLE); // Update to show the new reliability
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5868
diff changeset
   233
	InvalidateWindowClasses(WC_REPLACE_VEHICLE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   236
void StartupEngines()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
	Engine *e;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
   239
	/* Aging of vehicles stops, so account for that when starting late */
4322
f40bbdf476b3 (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
   240
	const Date aging_date = min(_date, ConvertYMDToDate(YEAR_ENGINE_AGING_STOPS, 0, 1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   242
	FOR_ALL_ENGINES(e) {
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   243
		const EngineInfo *ei = &e->info;
2242
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   244
		uint32 r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
		e->age = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
		e->flags = 0;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   248
		e->company_avail = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   249
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
   250
		/* The magic value of 729 days below comes from the NewGRF spec. If the
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
   251
		 * base intro date is before 1922 then the random number of days is not
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
   252
		 * added. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
		r = Random();
4297
d0311b62255c (svn r5934) -Cleanup: forgot some conversions to Year and to Date
rubidium
parents: 4293
diff changeset
   254
		e->intro_date = ei->base_intro <= ConvertYMDToDate(1922, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
		if (e->intro_date <= _date) {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
   256
			e->age = (aging_date - e->intro_date) >> 5;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   257
			e->company_avail = (CompanyMask)-1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
			e->flags |= ENGINE_AVAILABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
2140
a04d0142ad65 (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
   261
		e->reliability_start = GB(r, 16, 14) + 0x7AE0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
		r = Random();
2140
a04d0142ad65 (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->reliability_max   = GB(r,  0, 14) + 0xBFFF;
a04d0142ad65 (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->reliability_final = GB(r, 16, 14) + 0x3FFF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
		r = Random();
2140
a04d0142ad65 (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
   267
		e->duration_phase_1 = GB(r, 0, 5) + 7;
a04d0142ad65 (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
   268
		e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96;
a04d0142ad65 (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
   269
		e->duration_phase_3 = GB(r, 9, 7) + 120;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
9468
7087fa70cfd4 (svn r13388) -Codechange: Remove "my invented flag for something that is a wagon"
peter1138
parents: 9417
diff changeset
   271
		e->reliability_spd_dec = ei->decay_speed << 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
10427
cf023efb9a97 (svn r14680) -Feature(ette) [FS#2434]: Use property 4 (model life) also for wagons.
frosch
parents: 10208
diff changeset
   273
		CalcEngineReliability(e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
9413
7042a8ec3fa8 (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: 9380
diff changeset
   275
		e->lifelength = ei->lifelength + _settings_game.vehicle.extend_vehicle_life;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
   277
		/* prevent certain engines from ever appearing. */
9413
7042a8ec3fa8 (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: 9380
diff changeset
   278
		if (!HasBit(ei->climates, _settings_game.game_creation.landscape)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
			e->flags |= ENGINE_AVAILABLE;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   280
			e->company_avail = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
	}
10023
d200e056524c (svn r14182) -Fix: After applying NewGRF settings, all rail and road types were available as the engine availability check was performed too early.
peter1138
parents: 9914
diff changeset
   283
d200e056524c (svn r14182) -Fix: After applying NewGRF settings, all rail and road types were available as the engine availability check was performed too early.
peter1138
parents: 9914
diff changeset
   284
	/* Update the bitmasks for the vehicle lists */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   285
	Company *c;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   286
	FOR_ALL_COMPANIES(c) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   287
		c->avail_railtypes = GetCompanyRailtypes(c->index);
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   288
		c->avail_roadtypes = GetCompanyRoadtypes(c->index);
10023
d200e056524c (svn r14182) -Fix: After applying NewGRF settings, all rail and road types were available as the engine availability check was performed too early.
peter1138
parents: 9914
diff changeset
   289
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   292
static void AcceptEnginePreview(EngineID eid, CompanyID company)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
{
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5763
diff changeset
   294
	Engine *e = GetEngine(eid);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   295
	Company *c = GetCompany(company);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   297
	SetBit(e->company_avail, company);
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
   298
	if (e->type == VEH_TRAIN) {
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5763
diff changeset
   299
		const RailVehicleInfo *rvi = RailVehInfo(eid);
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5763
diff changeset
   300
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5763
diff changeset
   301
		assert(rvi->railtype < RAILTYPE_END);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   302
		SetBit(c->avail_railtypes, rvi->railtype);
6685
00490513d7b1 (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents: 6643
diff changeset
   303
	} else if (e->type == VEH_ROAD) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   304
		SetBit(c->avail_roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5763
diff changeset
   305
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   307
	e->preview_company_rank = 0xFF;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   308
	if (company == _local_company) {
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5868
diff changeset
   309
		AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
4766
aa276d0ec2eb (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
   310
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   313
static CompanyID GetBestCompany(uint8 pp)
1786
7cfd46c3fcc4 (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
   314
{
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   315
	const Company *c;
1786
7cfd46c3fcc4 (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
   316
	int32 best_hist;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   317
	CompanyID best_company;
1786
7cfd46c3fcc4 (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
	uint mask = 0;
7cfd46c3fcc4 (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
8572
5042e9287ea1 (svn r12150) -Fix (r12143): compiler warnings - possible use of uninitialised variable
smatz
parents: 8565
diff changeset
   320
	do {
1786
7cfd46c3fcc4 (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
		best_hist = -1;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   322
		best_company = INVALID_COMPANY;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   323
		FOR_ALL_COMPANIES(c) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   324
			if (c->block_preview == 0 && !HasBit(mask, c->index) &&
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   325
					c->old_economy[0].performance_history > best_hist) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   326
				best_hist = c->old_economy[0].performance_history;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   327
				best_company = c->index;
1786
7cfd46c3fcc4 (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
			}
7cfd46c3fcc4 (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
		}
7cfd46c3fcc4 (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
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   331
		if (best_company == INVALID_COMPANY) return INVALID_COMPANY;
1786
7cfd46c3fcc4 (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
   332
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   333
		SetBit(mask, best_company);
8633
454accf1533b (svn r12244) -Fix (r12150): typo resulting in no players are given the engine preview offer
smatz
parents: 8572
diff changeset
   334
	} while (--pp != 0);
1786
7cfd46c3fcc4 (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
   335
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   336
	return best_company;
1786
7cfd46c3fcc4 (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
   337
}
7cfd46c3fcc4 (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
   338
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   339
void EnginesDailyLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
{
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
   341
	if (_cur_year >= YEAR_ENGINE_AGING_STOPS) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   343
	Engine *e;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   344
	FOR_ALL_ENGINES(e) {
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   345
		EngineID i = e->index;
6174
0c743995213f (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6125
diff changeset
   346
		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
0c743995213f (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6125
diff changeset
   347
			if (e->flags & ENGINE_OFFER_WINDOW_OPEN) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   348
				if (e->preview_company_rank != 0xFF && !--e->preview_wait) {
6174
0c743995213f (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6125
diff changeset
   349
					e->flags &= ~ENGINE_OFFER_WINDOW_OPEN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
					DeleteWindowById(WC_ENGINE_PREVIEW, i);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   351
					e->preview_company_rank++;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   352
				}
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   353
			} else if (e->preview_company_rank != 0xFF) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   354
				CompanyID best_company = GetBestCompany(e->preview_company_rank);
1786
7cfd46c3fcc4 (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
   355
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   356
				if (best_company == INVALID_COMPANY) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   357
					e->preview_company_rank = 0xFF;
1786
7cfd46c3fcc4 (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
   358
					continue;
7cfd46c3fcc4 (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
   359
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   360
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   361
				if (!IsHumanCompany(best_company)) {
1786
7cfd46c3fcc4 (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
   362
					/* XXX - TTDBUG: TTD has a bug here ???? */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   363
					AcceptEnginePreview(i, best_company);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
				} else {
6174
0c743995213f (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6125
diff changeset
   365
					e->flags |= ENGINE_OFFER_WINDOW_OPEN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
					e->preview_wait = 20;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   367
					if (IsInteractiveCompany(best_company)) ShowEnginePreviewWindow(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   374
/** Accept an engine prototype. XXX - it is possible that the top-company
1786
7cfd46c3fcc4 (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
 * changes while you are waiting to accept the offer? Then it becomes invalid
3491
35d747bb5e82 (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
   376
 * @param tile unused
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6259
diff changeset
   377
 * @param flags operation to perfom
1786
7cfd46c3fcc4 (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
   378
 * @param p1 engine-prototype offered
7cfd46c3fcc4 (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
   379
 * @param p2 unused
7cfd46c3fcc4 (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
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6686
diff changeset
   381
CommandCost CmdWantEnginePreview(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
{
1786
7cfd46c3fcc4 (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
   383
	Engine *e;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2875
diff changeset
   384
1786
7cfd46c3fcc4 (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
   385
	if (!IsEngineIndex(p1)) return CMD_ERROR;
1926
530480d14685 (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1908
diff changeset
   386
	e = GetEngine(p1);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   387
	if (GetBestCompany(e->preview_company_rank) != _current_company) return CMD_ERROR;
1786
7cfd46c3fcc4 (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
   388
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   389
	if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_company);
1786
7cfd46c3fcc4 (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
   390
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   391
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
9199
ce9fbdff6581 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 9135
diff changeset
   394
StringID GetEngineCategoryName(EngineID engine);
ce9fbdff6581 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 9135
diff changeset
   395
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 408
diff changeset
   396
static void NewVehicleAvailable(Engine *e)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
	Vehicle *v;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   399
	Company *c;
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   400
	EngineID index = e->index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   402
	/* In case the company didn't build the vehicle during the intro period,
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   403
	 * prevent that company from getting future intro periods for a while. */
6174
0c743995213f (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6125
diff changeset
   404
	if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   405
		FOR_ALL_COMPANIES(c) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   406
			uint block_preview = c->block_preview;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   407
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   408
			if (!HasBit(e->company_avail, c->index)) continue;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   409
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   410
			/* We assume the user did NOT build it.. prove me wrong ;) */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   411
			c->block_preview = 20;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   412
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   413
			FOR_ALL_VEHICLES(v) {
6259
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
   414
				if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
471b91a4b1d8 (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6247
diff changeset
   415
						(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   416
					if (v->owner == c->index && v->engine_type == index) {
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   417
						/* The user did prove me wrong, so restore old value */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   418
						c->block_preview = block_preview;
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   419
						break;
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   420
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
6174
0c743995213f (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6125
diff changeset
   426
	e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
5944
6d059cc8662b (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 5868
diff changeset
   427
	AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
114
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   428
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   429
	/* Now available for all companies */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   430
	e->company_avail = (CompanyMask)-1;
114
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   431
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
   432
	/* Do not introduce new rail wagons */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2611
diff changeset
   433
	if (IsWagon(index)) return;
114
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   434
8220
97fb9c6afd8d (svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138
parents: 8214
diff changeset
   435
	if (e->type == VEH_TRAIN) {
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
   436
		/* maybe make another rail type available */
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   437
		RailType railtype = e->u.rail.railtype;
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5763
diff changeset
   438
		assert(railtype < RAILTYPE_END);
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   439
		FOR_ALL_COMPANIES(c) SetBit(c->avail_railtypes, railtype);
8220
97fb9c6afd8d (svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138
parents: 8214
diff changeset
   440
	} else if (e->type == VEH_ROAD) {
6686
9e8b32366bd6 (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 6685
diff changeset
   441
		/* maybe make another road type available */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   442
		FOR_ALL_COMPANIES(c) SetBit(c->avail_roadtypes, HasBit(e->info.misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
6686
9e8b32366bd6 (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 6685
diff changeset
   443
	}
9199
ce9fbdff6581 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 9135
diff changeset
   444
ce9fbdff6581 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 9135
diff changeset
   445
	SetDParam(0, GetEngineCategoryName(index));
ce9fbdff6581 (svn r13065) -Codechange: remove the need for the news string callbacks. Patch by Cirdan.
rubidium
parents: 9135
diff changeset
   446
	SetDParam(1, index);
9234
bfc9d27d3d0d (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: 9223
diff changeset
   447
	AddNewsItem(STR_NEW_VEHICLE_NOW_AVAILABLE_WITH_TYPE, NS_NEW_VEHICLES, index, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   450
void EnginesMonthlyLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
{
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
   452
	if (_cur_year < YEAR_ENGINE_AGING_STOPS) {
8401
26fb10da8c68 (svn r11971) -Codechange: use of FOR_ALL_ENGINES/ENGINEIDS_OF_TYPE instead of for-loops
peter1138
parents: 8400
diff changeset
   453
		Engine *e;
26fb10da8c68 (svn r11971) -Codechange: use of FOR_ALL_ENGINES/ENGINEIDS_OF_TYPE instead of for-loops
peter1138
parents: 8400
diff changeset
   454
		FOR_ALL_ENGINES(e) {
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
   455
			/* Age the vehicle */
2242
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   456
			if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
				e->age++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
				CalcEngineReliability(e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
2990
2bbe7769ebd4 (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
   461
			if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + 365)) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   462
				/* Introduce it to all companies */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
				NewVehicleAvailable(e);
6174
0c743995213f (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6125
diff changeset
   464
			} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   465
				/* Introduction date has passed.. show introducing dialog to one companies. */
6174
0c743995213f (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6125
diff changeset
   466
				e->flags |= ENGINE_EXCLUSIVE_PREVIEW;
257
0ff8a2e60a0d (svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents: 220
diff changeset
   467
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
   468
				/* Do not introduce new rail wagons */
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   469
				if (!IsWagon(e->index))
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   470
					e->preview_company_rank = 1; // Give to the company with the highest rating.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
7097
bc497a49fb45 (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: 6950
diff changeset
   476
static bool IsUniqueEngineName(const char *name)
bc497a49fb45 (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: 6950
diff changeset
   477
{
bc497a49fb45 (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: 6950
diff changeset
   478
	char buf[512];
bc497a49fb45 (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: 6950
diff changeset
   479
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   480
	const Engine *e;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   481
	FOR_ALL_ENGINES(e) {
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   482
		SetDParam(0, e->index);
7097
bc497a49fb45 (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: 6950
diff changeset
   483
		GetString(buf, STR_ENGINE_NAME, lastof(buf));
bc497a49fb45 (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: 6950
diff changeset
   484
		if (strcmp(buf, name) == 0) return false;
bc497a49fb45 (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: 6950
diff changeset
   485
	}
bc497a49fb45 (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: 6950
diff changeset
   486
bc497a49fb45 (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: 6950
diff changeset
   487
	return true;
bc497a49fb45 (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: 6950
diff changeset
   488
}
bc497a49fb45 (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: 6950
diff changeset
   489
1786
7cfd46c3fcc4 (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
/** Rename an engine.
3491
35d747bb5e82 (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
   491
 * @param tile unused
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6259
diff changeset
   492
 * @param flags operation to perfom
1786
7cfd46c3fcc4 (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
   493
 * @param p1 engine ID to rename
7cfd46c3fcc4 (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
   494
 * @param p2 unused
7cfd46c3fcc4 (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
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6686
diff changeset
   496
CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
{
9914
c07d0352d8d5 (svn r14064) -Fix [FS#1752]: check for the length of strings (in bytes) in the command. Checking for the length in pixels is impossible because that differs per client.
rubidium
parents: 9712
diff changeset
   498
	if (!IsEngineIndex(p1)) return CMD_ERROR;
1786
7cfd46c3fcc4 (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
   499
10148
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   500
	bool reset = StrEmpty(_cmd_text);
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   501
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   502
	if (!reset) {
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   503
		if (strlen(_cmd_text) >= MAX_LENGTH_ENGINE_NAME_BYTES) return CMD_ERROR;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   504
		if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   505
	}
7097
bc497a49fb45 (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: 6950
diff changeset
   506
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
	if (flags & DC_EXEC) {
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   508
		Engine *e = GetEngine(p1);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   509
		free(e->name);
10148
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   510
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   511
		if (reset) {
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   512
			e->name = NULL;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   513
			/* if we removed the last custom name, disable the 'Save custom names' button */
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   514
			_vehicle_design_names &= ~1;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   515
			FOR_ALL_ENGINES(e) {
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   516
				if (e->name != NULL) {
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   517
					_vehicle_design_names |= 1;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   518
					break;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   519
				}
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   520
			}
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   521
		} else {
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   522
			e->name = strdup(_cmd_text);
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   523
			_vehicle_design_names |= 3;
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   524
		}
ad8e8a65f6a2 (svn r14334) -Feature: ability to reset name to default/automatic value (for vehicles, engines, towns, groups, stations, waypoints, managers and companies)
smatz
parents: 10127
diff changeset
   525
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   529
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
8479
05ee5ae44a55 (svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138
parents: 8401
diff changeset
   533
/** Check if an engine is buildable.
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   534
 * @param engine  index of the engine to check.
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   535
 * @param type    the type the engine should be.
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   536
 * @param company index of the company.
8479
05ee5ae44a55 (svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138
parents: 8401
diff changeset
   537
 * @return True if an engine is valid, of the specified type, and buildable by
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   538
 *              the given company.
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   539
 */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   540
bool IsEngineBuildable(EngineID engine, VehicleType type, CompanyID company)
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   541
{
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
   542
	/* check if it's an engine that is in the engine array */
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   543
	if (!IsEngineIndex(engine)) return false;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   544
8479
05ee5ae44a55 (svn r12054) -Cleanup: Use VehicleType instead of byte for vehicle types...
peter1138
parents: 8401
diff changeset
   545
	const Engine *e = GetEngine(engine);
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   546
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
   547
	/* check if it's an engine of specified type */
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   548
	if (e->type != type) return false;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   549
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
   550
	/* check if it's available */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   551
	if (!HasBit(e->company_avail, company)) return false;
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   552
6530
06785f74984c (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: 6505
diff changeset
   553
	if (type == VEH_TRAIN) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   554
		/* Check if the rail type is available to this company */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   555
		const Company *c = GetCompany(company);
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   556
		if (!HasBit(c->avail_railtypes, RailVehInfo(engine)->railtype)) return false;
6530
06785f74984c (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: 6505
diff changeset
   557
	}
06785f74984c (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: 6505
diff changeset
   558
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   559
	return true;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   560
}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   561
10430
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   562
/**
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   563
 * Check if an engine is refittable.
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   564
 * @param engine index of the engine to check.
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   565
 * @return true if the engine is refittable.
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   566
 */
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   567
bool IsEngineRefittable(EngineID engine)
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   568
{
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   569
	/* check if it's an engine that is in the engine array */
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   570
	if (!IsEngineIndex(engine)) return false;
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   571
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   572
	const Engine *e = GetEngine(engine);
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   573
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   574
	if (e->type == VEH_SHIP && !e->u.ship.refittable) return false;
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   575
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   576
	const EngineInfo *ei = &e->info;
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   577
	if (ei->refit_mask == 0) return false;
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   578
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   579
	/* Are there suffixes?
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   580
	 * Note: This does not mean the suffixes are actually available for every consist at any time. */
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   581
	if (HasBit(ei->callbackmask, CBM_VEHICLE_CARGO_SUFFIX)) return true;
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   582
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   583
	/* Is there any cargo except the default cargo? */
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   584
	CargoID default_cargo = GetEngineCargoType(engine);
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   585
	return default_cargo != CT_INVALID && ei->refit_mask != 1U << default_cargo;
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   586
}
3125f2adebc5 (svn r14683) -Change: only say a engine/vehicle is refittable when it can be refitted to at least two cargo type or when it has subcargos.
rubidium
parents: 10427
diff changeset
   587
6505
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   588
/** Get the default cargo type for a certain engine type
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   589
 * @param engine The ID to get the cargo for
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   590
 * @return The cargo type. CT_INVALID means no cargo capacity
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   591
 */
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   592
CargoID GetEngineCargoType(EngineID engine)
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   593
{
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   594
	assert(IsEngineIndex(engine));
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   595
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   596
	switch (GetEngine(engine)->type) {
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   597
		case VEH_TRAIN:
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   598
			if (RailVehInfo(engine)->capacity == 0) return CT_INVALID;
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   599
			return RailVehInfo(engine)->cargo_type;
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   600
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   601
		case VEH_ROAD:
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   602
			if (RoadVehInfo(engine)->capacity == 0) return CT_INVALID;
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   603
			return RoadVehInfo(engine)->cargo_type;
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   604
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   605
		case VEH_SHIP:
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   606
			if (ShipVehInfo(engine)->capacity == 0) return CT_INVALID;
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   607
			return ShipVehInfo(engine)->cargo_type;
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   608
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   609
		case VEH_AIRCRAFT:
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   610
			/* all aircraft starts as passenger planes with cargo capacity */
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   611
			return CT_PASSENGERS;
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   612
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   613
		default: NOT_REACHED(); return CT_INVALID;
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   614
	}
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   615
}
8b4c20ddacd3 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6481
diff changeset
   616
1881
435d39bd6ee0 (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
   617
static const SaveLoad _engine_desc[] = {
4344
7e123fec5b0b (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
   618
	SLE_CONDVAR(Engine, intro_date,          SLE_FILE_U16 | SLE_VAR_I32,  0,  30),
7e123fec5b0b (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
   619
	SLE_CONDVAR(Engine, intro_date,          SLE_INT32,                  31, SL_MAX_VERSION),
7e123fec5b0b (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
   620
	SLE_CONDVAR(Engine, age,                 SLE_FILE_U16 | SLE_VAR_I32,  0,  30),
7e123fec5b0b (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
   621
	SLE_CONDVAR(Engine, age,                 SLE_INT32,                  31, SL_MAX_VERSION),
7e123fec5b0b (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
   622
	    SLE_VAR(Engine, reliability,         SLE_UINT16),
7e123fec5b0b (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
   623
	    SLE_VAR(Engine, reliability_spd_dec, SLE_UINT16),
7e123fec5b0b (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
   624
	    SLE_VAR(Engine, reliability_start,   SLE_UINT16),
7e123fec5b0b (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
   625
	    SLE_VAR(Engine, reliability_max,     SLE_UINT16),
7e123fec5b0b (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
   626
	    SLE_VAR(Engine, reliability_final,   SLE_UINT16),
7e123fec5b0b (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
   627
	    SLE_VAR(Engine, duration_phase_1,    SLE_UINT16),
7e123fec5b0b (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
   628
	    SLE_VAR(Engine, duration_phase_2,    SLE_UINT16),
7e123fec5b0b (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
   629
	    SLE_VAR(Engine, duration_phase_3,    SLE_UINT16),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
4344
7e123fec5b0b (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
   631
	    SLE_VAR(Engine, lifelength,          SLE_UINT8),
7e123fec5b0b (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
   632
	    SLE_VAR(Engine, flags,               SLE_UINT8),
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   633
	    SLE_VAR(Engine, preview_company_rank,SLE_UINT8),
4344
7e123fec5b0b (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
   634
	    SLE_VAR(Engine, preview_wait,        SLE_UINT8),
5823
7aa8c2312103 (svn r8385) -Fix
tron
parents: 5763
diff changeset
   635
	SLE_CONDNULL(1, 0, 44),
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   636
	    SLE_VAR(Engine, company_avail,       SLE_UINT8),
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   637
	SLE_CONDSTR(Engine, name,                SLE_STR, 0,                 84, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
6125
a6fff965707c (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 5971
diff changeset
   639
	/* reserve extra space in savegame here. (currently 16 bytes) */
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3047
diff changeset
   640
	SLE_CONDNULL(16, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   645
static std::map<EngineID, Engine> _temp_engine;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   646
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   647
Engine *GetTempDataEngine(EngineID index)
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   648
{
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   649
	return &_temp_engine[index];
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   650
}
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   651
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   652
static void Save_ENGN()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
{
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   654
	Engine *e;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   655
	FOR_ALL_ENGINES(e) {
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   656
		SlSetArrayIndex(e->index);
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   657
		SlObject(e, _engine_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6209
diff changeset
   661
static void Load_ENGN()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
{
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   663
	/* As engine data is loaded before engines are initialized we need to load
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   664
	 * this information into a temporary array. This is then copied into the
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   665
	 * engine pool after processing NewGRFs by CopyTempEngineData(). */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
	while ((index = SlIterateArray()) != -1) {
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   668
		Engine *e = GetTempDataEngine(index);
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   669
		SlObject(e, _engine_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   673
/**
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   674
 * Copy data from temporary engine array into the real engine pool.
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   675
 */
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   676
void CopyTempEngineData()
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   677
{
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   678
	Engine *e;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   679
	FOR_ALL_ENGINES(e) {
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   680
		if (e->index >= _temp_engine.size()) break;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   681
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   682
		const Engine *se = GetTempDataEngine(e->index);
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   683
		e->intro_date          = se->intro_date;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   684
		e->age                 = se->age;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   685
		e->reliability         = se->reliability;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   686
		e->reliability_spd_dec = se->reliability_spd_dec;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   687
		e->reliability_start   = se->reliability_start;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   688
		e->reliability_max     = se->reliability_max;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   689
		e->reliability_final   = se->reliability_final;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   690
		e->duration_phase_1    = se->duration_phase_1;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   691
		e->duration_phase_2    = se->duration_phase_2;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   692
		e->duration_phase_3    = se->duration_phase_3;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   693
		e->lifelength          = se->lifelength;
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   694
		e->flags               = se->flags;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   695
		e->preview_company_rank= se->preview_company_rank;
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   696
		e->preview_wait        = se->preview_wait;
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10148
diff changeset
   697
		e->company_avail       = se->company_avail;
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   698
		if (se->name != NULL) e->name = strdup(se->name);
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   699
	}
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   700
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   701
	/* Get rid of temporary data */
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   702
	_temp_engine.clear();
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   703
}
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   704
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   705
static void Load_ENGS()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
{
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   707
	/* Load old separate String ID list into a temporary array. This
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   708
	 * was always 256 entries. */
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   709
	StringID names[256];
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   710
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   711
	SlArray(names, lengthof(names), SLE_STRINGID);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   712
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   713
	/* Copy each string into the temporary engine array. */
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   714
	for (EngineID engine = 0; engine < lengthof(names); engine++) {
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily 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: 9036
diff changeset
   715
		Engine *e = GetTempDataEngine(engine);
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   716
		e->name = CopyFromOldName(names[engine]);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   717
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   720
extern const ChunkHandler _engine_chunk_handlers[] = {
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   721
	{ 'ENGN', Save_ENGN,     Load_ENGN,     CH_ARRAY          },
10127
4f53c1cfcfe9 (svn r14313) -Codechange: Move functions dealing with the EngineRenew pool to their own file.
frosch
parents: 10023
diff changeset
   722
	{ 'ENGS', NULL,          Load_ENGS,     CH_RIFF | CH_LAST },
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
};