src/engine.cpp
author peter1138
Tue, 08 Jan 2008 18:25:51 +0000
changeset 8717 de56e5ec3aec
parent 8716 5e53a939e256
child 8721 b7971ad9bdd9
permissions -rw-r--r--
(svn r11784) -Codechange: set up initial engine data in one place
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
     3
/** @file engine.cpp */
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1883
diff changeset
     6
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1197
diff changeset
     7
#include "debug.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 485
diff changeset
     8
#include "table/strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "player.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8610
diff changeset
    11
#include "command_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "saveload.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2147
diff changeset
    14
#include "variables.h"
2708
9d1a8d5dc3ea (svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents: 2639
diff changeset
    15
#include "train.h"
6105
761d393829d6 (svn r8428) -Codechange: Add proper names to aircraft subtypes instead of magic numbers and add a function IsNormalAircraft() which tells us whether the aircraft is in fact some flying device or a rotor/shadow.
Darkvater
parents: 6091
diff changeset
    16
#include "aircraft.h"
3866
113de2b20059 (svn r4902) Newgrf : Introduction of the newgrf_cargo files.
belugas
parents: 3865
diff changeset
    17
#include "newgrf_cargo.h"
4322
0bee6d9bc452 (svn r5975) -Cleanup: use ORIGINAL_BASE_YEAR & ORIGINAL_MAX_YEAR where the functions really depend on the original date format.
rubidium
parents: 4300
diff changeset
    18
#include "table/engines.h"
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
    19
#include "group.h"
7884
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
    20
#include "misc/autoptr.hpp"
8610
17cc343a23dd (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8427
diff changeset
    21
#include "strings_func.h"
8617
931e0970d509 (svn r11682) -Codechange: move some 'generic' geometry related types into a single file and do not include gfx.h everywhere to get a Point type.
rubidium
parents: 8612
diff changeset
    22
#include "viewport.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8617
diff changeset
    23
#include "functions.h"
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8617
diff changeset
    24
#include "window_func.h"
8636
2b158acb649c (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8627
diff changeset
    25
#include "date_func.h"
8708
0c29fbc79be4 (svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents: 8640
diff changeset
    26
#include "autoreplace_base.h"
0c29fbc79be4 (svn r11775) -Codechange: move all autoreplace/autorenew functions to a single location.
rubidium
parents: 8640
diff changeset
    27
#include "autoreplace_gui.h"
8710
52015340050c (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8708
diff changeset
    28
#include "string_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
2763
d579caf58b59 (svn r3308) BAD
tron
parents: 2708
diff changeset
    30
EngineInfo _engine_info[TOTAL_NUM_ENGINES];
d579caf58b59 (svn r3308) BAD
tron
parents: 2708
diff changeset
    31
RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
d579caf58b59 (svn r3308) BAD
tron
parents: 2708
diff changeset
    32
ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
d579caf58b59 (svn r3308) BAD
tron
parents: 2708
diff changeset
    33
AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
d579caf58b59 (svn r3308) BAD
tron
parents: 2708
diff changeset
    34
RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
d579caf58b59 (svn r3308) BAD
tron
parents: 2708
diff changeset
    35
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
enum {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
    37
	YEAR_ENGINE_AGING_STOPS = 2050,
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
    38
};
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
    39
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
8717
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    41
void SetupEngines()
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    42
{
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    43
	/* Copy original static engine data */
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    44
	memcpy(&_engine_info, &orig_engine_info, sizeof(orig_engine_info));
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    45
	memcpy(&_rail_vehicle_info, &orig_rail_vehicle_info, sizeof(orig_rail_vehicle_info));
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    46
	memcpy(&_ship_vehicle_info, &orig_ship_vehicle_info, sizeof(orig_ship_vehicle_info));
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    47
	memcpy(&_aircraft_vehicle_info, &orig_aircraft_vehicle_info, sizeof(orig_aircraft_vehicle_info));
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    48
	memcpy(&_road_vehicle_info, &orig_road_vehicle_info, sizeof(orig_road_vehicle_info));
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    49
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    50
	/* Add type to engines */
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    51
	Engine* e = _engines;
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    52
	do e->type = VEH_TRAIN;    while (++e < &_engines[ROAD_ENGINES_INDEX]);
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    53
	do e->type = VEH_ROAD;     while (++e < &_engines[SHIP_ENGINES_INDEX]);
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    54
	do e->type = VEH_SHIP;     while (++e < &_engines[AIRCRAFT_ENGINES_INDEX]);
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    55
	do e->type = VEH_AIRCRAFT; while (++e < &_engines[TOTAL_NUM_ENGINES]);
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    56
}
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    57
de56e5ec3aec (svn r11784) -Codechange: set up initial engine data in one place
peter1138
parents: 8716
diff changeset
    58
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2469
diff changeset
    59
void ShowEnginePreviewWindow(EngineID engine);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6535
diff changeset
    61
void DeleteCustomEngineNames()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
	uint i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	StringID old;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1329
diff changeset
    66
	for (i = 0; i != TOTAL_NUM_ENGINES; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
		old = _engine_name_strings[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
		_engine_name_strings[i] = i + STR_8000_KIRBY_PAUL_TANK_STEAM;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
		DeleteName(old);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	_vehicle_design_names &= ~1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6535
diff changeset
    75
void LoadCustomEngineNames()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
{
4432
33631ac88c40 (svn r6195) -Codechange: do not use '//' in '/* ... */' style comments and '/*' or '*/' in '//' style comments.
rubidium
parents: 4384
diff changeset
    77
	/* XXX: not done */
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5216
diff changeset
    78
	DEBUG(misc, 1, "LoadCustomEngineNames: not done");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6535
diff changeset
    81
static void SetupEngineNames()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
{
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1329
diff changeset
    83
	StringID *name;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1329
diff changeset
    85
	for (name = _engine_name_strings; name != endof(_engine_name_strings); name++)
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1329
diff changeset
    86
		*name = STR_SV_EMPTY;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
	DeleteCustomEngineNames();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	LoadCustomEngineNames();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
static void CalcEngineReliability(Engine *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
	uint age = e->age;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
7102
ea95244a6027 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 7026
diff changeset
    97
	/* Check for early retirement */
ea95244a6027 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 7026
diff changeset
    98
	if (e->player_avail != 0 && !_patches.never_expire_vehicles) {
ea95244a6027 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 7026
diff changeset
    99
		uint retire_early = EngInfo(e - _engines)->retire_early;
ea95244a6027 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 7026
diff changeset
   100
		if (retire_early > 0 && age >= e->duration_phase_1 + e->duration_phase_2 - retire_early * 12) {
ea95244a6027 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 7026
diff changeset
   101
			/* Early retirement is enabled and we're past the date... */
ea95244a6027 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 7026
diff changeset
   102
			e->player_avail = 0;
ea95244a6027 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 7026
diff changeset
   103
			AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
ea95244a6027 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 7026
diff changeset
   104
		}
ea95244a6027 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 7026
diff changeset
   105
	}
ea95244a6027 (svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
peter1138
parents: 7026
diff changeset
   106
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	if (age < e->duration_phase_1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
		uint start = e->reliability_start;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
		e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start;
4767
7621bec94f99 (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   110
	} else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _patches.never_expire_vehicles) {
7621bec94f99 (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   111
		/* We are at the peak of this engines life. It will have max reliability.
7621bec94f99 (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   112
		 * 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
   113
		e->reliability = e->reliability_max;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
	} 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
   115
		uint max = e->reliability_max;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
		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
   117
	} else {
4767
7621bec94f99 (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   118
		/* time's up for this engine.
7621bec94f99 (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   119
		 * We will now completely retire this design */
7621bec94f99 (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   120
		e->player_avail = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
		e->reliability = e->reliability_final;
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6119
diff changeset
   122
		/* Kick this engine out of the lists */
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6119
diff changeset
   123
		AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	}
4767
7621bec94f99 (svn r6681) -Fix: when vehicles never expire they will stay at peak reliability instead of the lowest to make them useful even when old
bjarni
parents: 4766
diff changeset
   125
	InvalidateWindowClasses(WC_BUILD_VEHICLE); // Update to show the new reliability
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6119
diff changeset
   126
	InvalidateWindowClasses(WC_REPLACE_VEHICLE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6535
diff changeset
   129
void StartupEngines()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
	Engine *e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
	const EngineInfo *ei;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
   133
	/* Aging of vehicles stops, so account for that when starting late */
4322
0bee6d9bc452 (svn r5975) -Cleanup: use ORIGINAL_BASE_YEAR & ORIGINAL_MAX_YEAR where the functions really depend on the original date format.
rubidium
parents: 4300
diff changeset
   134
	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
   135
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
	SetupEngineNames();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
2242
27fa4807cd61 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   138
	for (e = _engines, ei = _engine_info; e != endof(_engines); e++, ei++) {
27fa4807cd61 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   139
		uint32 r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
		e->age = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
		e->flags = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
		e->player_avail = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   144
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   145
		/* The magic value of 729 days below comes from the NewGRF spec. If the
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   146
		 * base intro date is before 1922 then the random number of days is not
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   147
		 * added. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
		r = Random();
4297
47ce9665b4af (svn r5934) -Cleanup: forgot some conversions to Year and to Date
rubidium
parents: 4293
diff changeset
   149
		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
   150
		if (e->intro_date <= _date) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
   151
			e->age = (aging_date - e->intro_date) >> 5;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
			e->player_avail = (byte)-1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
			e->flags |= ENGINE_AVAILABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
2140
d708eb80ab8b (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 1988
diff changeset
   156
		e->reliability_start = GB(r, 16, 14) + 0x7AE0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
		r = Random();
2140
d708eb80ab8b (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 1988
diff changeset
   158
		e->reliability_max   = GB(r,  0, 14) + 0xBFFF;
d708eb80ab8b (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 1988
diff changeset
   159
		e->reliability_final = GB(r, 16, 14) + 0x3FFF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
		r = Random();
2140
d708eb80ab8b (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 1988
diff changeset
   162
		e->duration_phase_1 = GB(r, 0, 5) + 7;
d708eb80ab8b (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 1988
diff changeset
   163
		e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96;
d708eb80ab8b (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 1988
diff changeset
   164
		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
   165
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
		e->reliability_spd_dec = (ei->unk2&0x7F) << 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
		/* my invented flag for something that is a wagon */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
		if (ei->unk2 & 0x80) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
			e->age = 0xFFFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
			CalcEngineReliability(e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
		e->lifelength = ei->lifelength + _patches.extend_vehicle_life;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   177
		/* prevent certain engines from ever appearing. */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7884
diff changeset
   178
		if (!HasBit(ei->climates, _opt.landscape)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
			e->flags |= ENGINE_AVAILABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
			e->player_avail = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
		}
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 842
diff changeset
   182
819
02e9296ccdca (svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents: 740
diff changeset
   183
		/* This sets up type for the engine
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4432
diff changeset
   184
		 * It is needed if you want to ask the engine what type it is
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4432
diff changeset
   185
		 * It should hopefully be the same as when you ask a vehicle what it is
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4432
diff changeset
   186
		 * but using this, you can ask what type an engine number is
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4432
diff changeset
   187
		 * even if it is not a vehicle (yet)*/
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6014
diff changeset
   191
static void AcceptEnginePreview(EngineID eid, PlayerID player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
{
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6014
diff changeset
   193
	Engine *e = GetEngine(eid);
7181
f966d75af3a6 (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents: 7139
diff changeset
   194
	Player *p = GetPlayer(player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   196
	SetBit(e->player_avail, player);
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6573
diff changeset
   197
	if (e->type == VEH_TRAIN) {
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6014
diff changeset
   198
		const RailVehicleInfo *rvi = RailVehInfo(eid);
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6014
diff changeset
   199
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6014
diff changeset
   200
		assert(rvi->railtype < RAILTYPE_END);
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   201
		SetBit(p->avail_railtypes, rvi->railtype);
7181
f966d75af3a6 (svn r9917) -Codechange: prepare some more areas for more road types.
rubidium
parents: 7139
diff changeset
   202
	} else if (e->type == VEH_ROAD) {
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   203
		SetBit(p->avail_roadtypes, HasBit(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6014
diff changeset
   204
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   206
	e->preview_player = INVALID_PLAYER;
4766
a23183d868d1 (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4549
diff changeset
   207
	if (player == _local_player) {
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6119
diff changeset
   208
		AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
4766
a23183d868d1 (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4549
diff changeset
   209
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   212
static PlayerID GetBestPlayer(PlayerID pp)
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   213
{
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   214
	const Player *p;
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   215
	int32 best_hist;
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   216
	PlayerID best_player;
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   217
	uint mask = 0;
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   218
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   219
	do {
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   220
		best_hist = -1;
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4845
diff changeset
   221
		best_player = PLAYER_SPECTATOR;
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   222
		FOR_ALL_PLAYERS(p) {
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7884
diff changeset
   223
			if (p->is_active && p->block_preview == 0 && !HasBit(mask, p->index) &&
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   224
					p->old_economy[0].performance_history > best_hist) {
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   225
				best_hist = p->old_economy[0].performance_history;
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   226
				best_player = p->index;
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   227
			}
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   228
		}
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   229
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4845
diff changeset
   230
		if (best_player == PLAYER_SPECTATOR) return PLAYER_SPECTATOR;
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   231
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   232
		SetBit(mask, best_player);
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   233
	} while (pp--, pp != 0);
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   234
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   235
	return best_player;
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   236
}
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   237
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6535
diff changeset
   238
void EnginesDailyLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
{
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2469
diff changeset
   240
	EngineID i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
   242
	if (_cur_year >= YEAR_ENGINE_AGING_STOPS) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
2242
27fa4807cd61 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   244
	for (i = 0; i != lengthof(_engines); i++) {
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   245
		Engine *e = &_engines[i];
2242
27fa4807cd61 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   246
6500
08ea5741ee39 (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6451
diff changeset
   247
		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
08ea5741ee39 (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6451
diff changeset
   248
			if (e->flags & ENGINE_OFFER_WINDOW_OPEN) {
740
c1d06749846b (svn r1196) -Fix: Preview Vehicle had a small glitch. Fixed now.
truelight
parents: 555
diff changeset
   249
				if (e->preview_player != 0xFF && !--e->preview_wait) {
6500
08ea5741ee39 (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6451
diff changeset
   250
					e->flags &= ~ENGINE_OFFER_WINDOW_OPEN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
					DeleteWindowById(WC_ENGINE_PREVIEW, i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
					e->preview_player++;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   253
				}
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 3866
diff changeset
   254
			} else if (e->preview_player != 0xFF) {
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   255
				PlayerID best_player = GetBestPlayer(e->preview_player);
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   256
4848
56549aa3e234 (svn r6774) -Codechange: Rename the badly named OWNER_SPECTATOR to PLAYER_SPECTATOR and
Darkvater
parents: 4845
diff changeset
   257
				if (best_player == PLAYER_SPECTATOR) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   258
					e->preview_player = INVALID_PLAYER;
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   259
					continue;
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   260
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   261
4845
49105d3b5a9a (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4792
diff changeset
   262
				if (!IsHumanPlayer(best_player)) {
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   263
					/* XXX - TTDBUG: TTD has a bug here ???? */
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6014
diff changeset
   264
					AcceptEnginePreview(i, best_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
				} else {
6500
08ea5741ee39 (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6451
diff changeset
   266
					e->flags |= ENGINE_OFFER_WINDOW_OPEN;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
					e->preview_wait = 20;
4845
49105d3b5a9a (svn r6771) -Codechange: Replace two macros with functions. IS_HUMAN_PLAYER and
Darkvater
parents: 4792
diff changeset
   268
					if (IsInteractivePlayer(best_player)) ShowEnginePreviewWindow(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   275
/** Accept an engine prototype. XXX - it is possible that the top-player
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   276
 * changes while you are waiting to accept the offer? Then it becomes invalid
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3222
diff changeset
   277
 * @param tile unused
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6585
diff changeset
   278
 * @param flags operation to perfom
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   279
 * @param p1 engine-prototype offered
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   280
 * @param p2 unused
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   281
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7182
diff changeset
   282
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
   283
{
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   284
	Engine *e;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2875
diff changeset
   285
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   286
	if (!IsEngineIndex(p1)) return CMD_ERROR;
1926
68d60188a22f (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1908
diff changeset
   287
	e = GetEngine(p1);
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   288
	if (GetBestPlayer(e->preview_player) != _current_player) return CMD_ERROR;
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   289
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6014
diff changeset
   290
	if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_player);
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   291
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   292
	return CommandCost();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   295
/* Determine if an engine type is a wagon (and not a loco) */
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2469
diff changeset
   296
static bool IsWagon(EngineID index)
257
8d83db6716ea (svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents: 220
diff changeset
   297
{
6119
b47985557d1e (svn r8455) -Codechange: Give a more meaningful name (railveh_type)to member flags of RailVehInfo, as well as changing the code to reflect the fact that it was not a flag but rather a one value only variable. Doing so, some evaluations have been simplified.
belugas
parents: 6105
diff changeset
   298
	return index < NUM_TRAIN_ENGINES && RailVehInfo(index)->railveh_type == RAILVEH_WAGON;
257
8d83db6716ea (svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents: 220
diff changeset
   299
}
8d83db6716ea (svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents: 220
diff changeset
   300
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 408
diff changeset
   301
static void NewVehicleAvailable(Engine *e)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	Player *p;
2477
d454d5152386 (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2469
diff changeset
   305
	EngineID index = e - _engines;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   307
	/* In case the player didn't build the vehicle during the intro period,
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   308
	 * prevent that player from getting future intro periods for a while. */
6500
08ea5741ee39 (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6451
diff changeset
   309
	if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
		FOR_ALL_PLAYERS(p) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   311
			uint block_preview = p->block_preview;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   312
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7884
diff changeset
   313
			if (!HasBit(e->player_avail, p->index)) continue;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   314
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   315
			/* We assume the user did NOT build it.. prove me wrong ;) */
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   316
			p->block_preview = 20;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   317
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   318
			FOR_ALL_VEHICLES(v) {
6585
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6573
diff changeset
   319
				if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
7da94b26498a (svn r9068) -Codechange: capitalize the VEH_Train etc. enums to match the coding style (and rest of the code).
rubidium
parents: 6573
diff changeset
   320
						(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) {
919
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   321
					if (v->owner == p->index && v->engine_type == index) {
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   322
						/* The user did prove me wrong, so restore old value */
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   323
						p->block_preview = block_preview;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   324
						break;
b0d6c7642f99 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   325
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
6500
08ea5741ee39 (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6451
diff changeset
   331
	e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
6195
b90cf92697b9 (svn r8610) -Codechange/Feature: rewrote the list handling in the autoreplace window
bjarni
parents: 6119
diff changeset
   332
	AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
114
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   333
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   334
	/* Now available for all players */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
	e->player_avail = (byte)-1;
114
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   336
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   337
	/* Do not introduce new rail wagons */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2611
diff changeset
   338
	if (IsWagon(index)) return;
114
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   339
8716
5e53a939e256 (svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138
parents: 8710
diff changeset
   340
	if (e->type == VEH_TRAIN) {
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   341
		/* maybe make another rail type available */
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6014
diff changeset
   342
		RailType railtype = RailVehInfo(index)->railtype;
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6014
diff changeset
   343
		assert(railtype < RAILTYPE_END);
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6014
diff changeset
   344
		FOR_ALL_PLAYERS(p) {
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   345
			if (p->is_active) SetBit(p->avail_railtypes, railtype);
2147
42efdf5020d1 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   346
		}
8716
5e53a939e256 (svn r11783) -Codechange: compare engine type with its type property, not by its index
peter1138
parents: 8710
diff changeset
   347
	} else if (e->type == VEH_ROAD) {
7182
644a1d06f2be (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 7181
diff changeset
   348
		/* maybe make another road type available */
644a1d06f2be (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 7181
diff changeset
   349
		FOR_ALL_PLAYERS(p) {
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
   350
			if (p->is_active) SetBit(p->avail_roadtypes, HasBit(EngInfo(index)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
7182
644a1d06f2be (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 7181
diff changeset
   351
		}
644a1d06f2be (svn r9918) -Fix: the available roadtypes/railtypes were not updated on GRF updates.
rubidium
parents: 7181
diff changeset
   352
	}
6535
1a5437f36d78 (svn r9001) -Codechange: remove duplication of functions and strings with respect to the news of new vehicles.
rubidium
parents: 6500
diff changeset
   353
	AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_VEHICLEAVAIL), 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6535
diff changeset
   356
void EnginesMonthlyLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
	Engine *e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4297
diff changeset
   360
	if (_cur_year < YEAR_ENGINE_AGING_STOPS) {
2242
27fa4807cd61 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   361
		for (e = _engines; e != endof(_engines); e++) {
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   362
			/* Age the vehicle */
2242
27fa4807cd61 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   363
			if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
				e->age++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
				CalcEngineReliability(e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
2990
352b4590ee1c (svn r3565) - Fix: On loading a game, GetPlayerRailtypes() didn't account for the fact that vehicles are introduced a year after their introduction date. This will also relieve possible (rare) network desyncs.
peter1138
parents: 2962
diff changeset
   368
			if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + 365)) {
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   369
				/* Introduce it to all players */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
				NewVehicleAvailable(e);
6500
08ea5741ee39 (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6451
diff changeset
   371
			} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) {
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   372
				/* Introduction date has passed.. show introducing dialog to one player. */
6500
08ea5741ee39 (svn r8944) -Codechange: Move the enum describing the bitmask of Engine.flags to engine.h and give the enum values better names.
maedhros
parents: 6451
diff changeset
   373
				e->flags |= ENGINE_EXCLUSIVE_PREVIEW;
257
8d83db6716ea (svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents: 220
diff changeset
   374
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   375
				/* Do not introduce new rail wagons */
964
4bd472539a4e (svn r1456) Simplify isWagon(), make it static and give it a canonical name (IsWagon)
tron
parents: 938
diff changeset
   376
				if (!IsWagon(e - _engines))
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   377
					e->preview_player = (PlayerID)1; // Give to the player with the highest rating.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
7593
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   383
static bool IsUniqueEngineName(const char *name)
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   384
{
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   385
	char buf[512];
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   386
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   387
	for (EngineID i = 0; i < TOTAL_NUM_ENGINES; i++) {
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   388
		SetDParam(0, i);
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   389
		GetString(buf, STR_ENGINE_NAME, lastof(buf));
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   390
		if (strcmp(buf, name) == 0) return false;
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   391
	}
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   392
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   393
	return true;
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   394
}
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   395
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   396
/** Rename an engine.
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3222
diff changeset
   397
 * @param tile unused
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6585
diff changeset
   398
 * @param flags operation to perfom
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   399
 * @param p1 engine ID to rename
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   400
 * @param p2 unused
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   401
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7182
diff changeset
   402
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
   403
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
	StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
7593
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   406
	if (!IsEngineIndex(p1) || StrEmpty(_cmd_text)) return CMD_ERROR;
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   407
7593
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   408
	if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   409
cfce84f8995c (svn r10364) -Fix [FS#706]: checking for duplicate custom names was inconsistent, and tested all 'namespaces'. now only check names of the same type.
peter1138
parents: 7446
diff changeset
   410
	str = AllocateName(_cmd_text, 0);
1786
a54634efeb98 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   411
	if (str == 0) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   412
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
		StringID old_str = _engine_name_strings[p1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
		_engine_name_strings[p1] = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
		DeleteName(old_str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
		_vehicle_design_names |= 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
		DeleteName(str);
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
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   423
	return CommandCost();
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   427
/*
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   428
 * returns true if an engine is valid, of the specified type, and buildable by
5215
439d5ca71311 (svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents: 5037
diff changeset
   429
 * the given player, false otherwise
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   430
 *
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   431
 * engine = index of the engine to check
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   432
 * type   = the type the engine should be of (VEH_xxx)
5215
439d5ca71311 (svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents: 5037
diff changeset
   433
 * player = index of the player
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   434
 */
5215
439d5ca71311 (svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents: 5037
diff changeset
   435
bool IsEngineBuildable(EngineID engine, byte type, PlayerID player)
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   436
{
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   437
	const Engine *e;
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   438
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   439
	/* check if it's an engine that is in the engine array */
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   440
	if (!IsEngineIndex(engine)) return false;
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   441
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   442
	e = GetEngine(engine);
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   443
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   444
	/* check if it's an engine of specified type */
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   445
	if (e->type != type) return false;
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   446
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   447
	/* check if it's available */
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7884
diff changeset
   448
	if (!HasBit(e->player_avail, player)) return false;
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   449
7026
7ef9437cf867 (svn r9718) -Fix: Don't allow building of rail vehicles whose railtype isn't available yet. This also affects the rail purchase window.
peter1138
parents: 7001
diff changeset
   450
	if (type == VEH_TRAIN) {
7ef9437cf867 (svn r9718) -Fix: Don't allow building of rail vehicles whose railtype isn't available yet. This also affects the rail purchase window.
peter1138
parents: 7001
diff changeset
   451
		/* Check if the rail type is available to this player */
7ef9437cf867 (svn r9718) -Fix: Don't allow building of rail vehicles whose railtype isn't available yet. This also affects the rail purchase window.
peter1138
parents: 7001
diff changeset
   452
		const Player *p = GetPlayer(player);
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7884
diff changeset
   453
		if (!HasBit(p->avail_railtypes, RailVehInfo(engine)->railtype)) return false;
7026
7ef9437cf867 (svn r9718) -Fix: Don't allow building of rail vehicles whose railtype isn't available yet. This also affects the rail purchase window.
peter1138
parents: 7001
diff changeset
   454
	}
7ef9437cf867 (svn r9718) -Fix: Don't allow building of rail vehicles whose railtype isn't available yet. This also affects the rail purchase window.
peter1138
parents: 7001
diff changeset
   455
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   456
	return true;
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   457
}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   458
7001
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   459
/** Get the default cargo type for a certain engine type
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   460
 * @param engine The ID to get the cargo for
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   461
 * @return The cargo type. CT_INVALID means no cargo capacity
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   462
 */
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   463
CargoID GetEngineCargoType(EngineID engine)
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   464
{
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   465
	assert(IsEngineIndex(engine));
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   466
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   467
	switch (GetEngine(engine)->type) {
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   468
		case VEH_TRAIN:
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   469
			if (RailVehInfo(engine)->capacity == 0) return CT_INVALID;
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   470
			return RailVehInfo(engine)->cargo_type;
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   471
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   472
		case VEH_ROAD:
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   473
			if (RoadVehInfo(engine)->capacity == 0) return CT_INVALID;
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   474
			return RoadVehInfo(engine)->cargo_type;
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   475
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   476
		case VEH_SHIP:
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   477
			if (ShipVehInfo(engine)->capacity == 0) return CT_INVALID;
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   478
			return ShipVehInfo(engine)->cargo_type;
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   479
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   480
		case VEH_AIRCRAFT:
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   481
			/* all aircraft starts as passenger planes with cargo capacity */
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   482
			return CT_PASSENGERS;
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   483
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   484
		default: NOT_REACHED(); return CT_INVALID;
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   485
	}
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   486
}
d5f19455d650 (svn r9688) -Codechange: Created a function to get default cargo type for a cargo type
bjarni
parents: 6977
diff changeset
   487
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   488
/************************************************************************
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   489
 * Engine Replacement stuff
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   490
 ************************************************************************/
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   491
7884
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
   492
DEFINE_OLD_POOL_GENERIC(EngineRenew, EngineRenew)
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   493
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   494
/**
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   495
 * Retrieves the EngineRenew that specifies the replacement of the given
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   496
 * engine type from the given renewlist */
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
   497
static EngineRenew *GetEngineReplacement(EngineRenewList erl, EngineID engine, GroupID group)
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   498
{
4348
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   499
	EngineRenew *er = (EngineRenew *)erl;
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   500
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   501
	while (er) {
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
   502
		if (er->from == engine && er->group_id == group) return er;
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   503
		er = er->next;
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   504
	}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   505
	return NULL;
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   506
}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   507
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   508
void RemoveAllEngineReplacement(EngineRenewList *erl)
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   509
{
4348
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   510
	EngineRenew *er = (EngineRenew *)(*erl);
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4358
diff changeset
   511
	EngineRenew *next;
4348
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   512
7884
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
   513
	while (er != NULL) {
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4358
diff changeset
   514
		next = er->next;
7884
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
   515
		delete er;
4384
293c0d26294c (svn r6137) -Codechange: some very minor cleanups:
truelight
parents: 4358
diff changeset
   516
		er = next;
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   517
	}
4348
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   518
	*erl = NULL; // Empty list
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   519
}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   520
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
   521
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group)
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   522
{
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
   523
	const EngineRenew *er = GetEngineReplacement(erl, engine, group);
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   524
	return er == NULL ? INVALID_ENGINE : er->to;
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   525
}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   526
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7182
diff changeset
   527
CommandCost AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags)
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   528
{
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   529
	EngineRenew *er;
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   530
4348
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   531
	/* Check if the old vehicle is already in the list */
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
   532
	er = GetEngineReplacement(*erl, old_engine, group);
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   533
	if (er != NULL) {
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   534
		if (flags & DC_EXEC) er->to = new_engine;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   535
		return CommandCost();
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   536
	}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   537
7884
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
   538
	er = new EngineRenew(old_engine, new_engine);
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   539
	if (er == NULL) return CMD_ERROR;
7884
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
   540
	AutoPtrT<EngineRenew> er_auto_delete = er;
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
   541
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   542
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   543
	if (flags & DC_EXEC) {
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
   544
		er->group_id = group;
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   545
4348
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   546
		/* Insert before the first element */
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   547
		er->next = (EngineRenew *)(*erl);
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   548
		*erl = (EngineRenewList)er;
7884
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
   549
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
   550
		er_auto_delete.Detach();
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   551
	}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   552
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   553
	return CommandCost();
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   554
}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   555
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7182
diff changeset
   556
CommandCost RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags)
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   557
{
4348
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   558
	EngineRenew *er = (EngineRenew *)(*erl);
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   559
	EngineRenew *prev = NULL;
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   560
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   561
	while (er)
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   562
	{
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
   563
		if (er->from == engine && er->group_id == group) {
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   564
			if (flags & DC_EXEC) {
4348
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   565
				if (prev == NULL) { // First element
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   566
					/* The second becomes the new first element */
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   567
					*erl = (EngineRenewList)er->next;
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   568
				} else {
4348
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   569
					/* Cut this element out */
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   570
					prev->next = er->next;
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   571
				}
7884
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
   572
				delete er;
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   573
			}
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   574
			return CommandCost();
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   575
		}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   576
		prev = er;
4348
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   577
		er = er->next;
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   578
	}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   579
4348
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   580
	return CMD_ERROR;
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   581
}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   582
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   583
static const SaveLoad _engine_renew_desc[] = {
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
   584
	    SLE_VAR(EngineRenew, from,     SLE_UINT16),
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
   585
	    SLE_VAR(EngineRenew, to,       SLE_UINT16),
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   586
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
   587
	    SLE_REF(EngineRenew, next,     REF_ENGINE_RENEWS),
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
   588
	SLE_CONDVAR(EngineRenew, group_id, SLE_UINT16, 60, SL_MAX_VERSION),
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   589
	SLE_END()
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   590
};
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   591
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6535
diff changeset
   592
static void Save_ERNW()
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   593
{
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   594
	EngineRenew *er;
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   595
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   596
	FOR_ALL_ENGINE_RENEWS(er) {
4348
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   597
		SlSetArrayIndex(er->index);
95ba9ff1612e (svn r6049) -Codechange: forgot EngineRenew in r6047
truelight
parents: 4346
diff changeset
   598
		SlObject(er, _engine_renew_desc);
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   599
	}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   600
}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   601
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6535
diff changeset
   602
static void Load_ERNW()
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   603
{
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   604
	int index;
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   605
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   606
	while ((index = SlIterateArray()) != -1) {
7884
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
   607
		EngineRenew *er = new (index) EngineRenew();
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   608
		SlObject(er, _engine_renew_desc);
7139
4ae3ab180d05 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 7102
diff changeset
   609
7754
8e7205edd6c7 (svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents: 7593
diff changeset
   610
		/* Advanced vehicle lists, ungrouped vehicles got added */
8e7205edd6c7 (svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents: 7593
diff changeset
   611
		if (CheckSavegameVersion(60)) {
8e7205edd6c7 (svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents: 7593
diff changeset
   612
			er->group_id = ALL_GROUP;
8e7205edd6c7 (svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents: 7593
diff changeset
   613
		} else if (CheckSavegameVersion(71)) {
8e7205edd6c7 (svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents: 7593
diff changeset
   614
			if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_GROUP;
8e7205edd6c7 (svn r10567) -Add [FS#915]: a "group" with ungrouped vehicles. Patch by Matthias Wolf.
rubidium
parents: 7593
diff changeset
   615
		}
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   616
	}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   617
}
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   618
1881
023a134a4b12 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1855
diff changeset
   619
static const SaveLoad _engine_desc[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   620
	SLE_CONDVAR(Engine, intro_date,          SLE_FILE_U16 | SLE_VAR_I32,  0,  30),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   621
	SLE_CONDVAR(Engine, intro_date,          SLE_INT32,                  31, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   622
	SLE_CONDVAR(Engine, age,                 SLE_FILE_U16 | SLE_VAR_I32,  0,  30),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   623
	SLE_CONDVAR(Engine, age,                 SLE_INT32,                  31, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   624
	    SLE_VAR(Engine, reliability,         SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   625
	    SLE_VAR(Engine, reliability_spd_dec, SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   626
	    SLE_VAR(Engine, reliability_start,   SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   627
	    SLE_VAR(Engine, reliability_max,     SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   628
	    SLE_VAR(Engine, reliability_final,   SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   629
	    SLE_VAR(Engine, duration_phase_1,    SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   630
	    SLE_VAR(Engine, duration_phase_2,    SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   631
	    SLE_VAR(Engine, duration_phase_3,    SLE_UINT16),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   633
	    SLE_VAR(Engine, lifelength,          SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   634
	    SLE_VAR(Engine, flags,               SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   635
	    SLE_VAR(Engine, preview_player,      SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   636
	    SLE_VAR(Engine, preview_wait,        SLE_UINT8),
6074
e70d63ef4d62 (svn r8385) -Fix
tron
parents: 6014
diff changeset
   637
	SLE_CONDNULL(1, 0, 44),
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   638
	    SLE_VAR(Engine, player_avail,        SLE_UINT8),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
6451
7baba06b4b85 (svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents: 6222
diff changeset
   640
	/* reserve extra space in savegame here. (currently 16 bytes) */
3222
8bfed4267cba (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3047
diff changeset
   641
	SLE_CONDNULL(16, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6535
diff changeset
   646
static void Save_ENGN()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
{
2242
27fa4807cd61 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   648
	uint i;
27fa4807cd61 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   649
27fa4807cd61 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   650
	for (i = 0; i != lengthof(_engines); i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
		SlSetArrayIndex(i);
2242
27fa4807cd61 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   652
		SlObject(&_engines[i], _engine_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6535
diff changeset
   656
static void Load_ENGN()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
	while ((index = SlIterateArray()) != -1) {
1926
68d60188a22f (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1908
diff changeset
   660
		SlObject(GetEngine(index), _engine_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6535
diff changeset
   664
static void LoadSave_ENGS()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
	SlArray(_engine_name_strings, lengthof(_engine_name_strings), SLE_STRINGID);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   669
extern const ChunkHandler _engine_chunk_handlers[] = {
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   670
	{ 'ENGN', Save_ENGN,     Load_ENGN,     CH_ARRAY          },
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   671
	{ 'ENGS', LoadSave_ENGS, LoadSave_ENGS, CH_RIFF           },
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   672
	{ 'ERNW', Save_ERNW,     Load_ERNW,     CH_ARRAY | CH_LAST},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6535
diff changeset
   675
void InitializeEngines()
1197
4322cf8d6ae7 (svn r1701) Style police ^^
tron
parents: 1196
diff changeset
   676
{
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   677
	/* Clean the engine renew pool and create 1 block in it */
7884
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
   678
	_EngineRenew_pool.CleanPool();
79fa68c2a6ae (svn r10757) -Codechange: make the engine renew struct use the pool item class as super class.
rubidium
parents: 7754
diff changeset
   679
	_EngineRenew_pool.AddBlockToPool();
1196
115f46e3807d (svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents: 1096
diff changeset
   680
}