engine.c
author tron
Mon, 10 Apr 2006 07:15:58 +0000
changeset 3491 35d747bb5e82
parent 3222 6de22e06a1e9
child 3585 43461f26b729
permissions -rw-r--r--
(svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
Remove DoCommandByTile(), because now it does the same as DoCommand()
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1883
diff changeset
     4
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1197
diff changeset
     5
#include "debug.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     6
#include "functions.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 485
diff changeset
     7
#include "table/strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     8
#include "engine.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "table/engines.h"
1009
75140dc68759 (svn r1508) Remove duplicate declarations and include proper headers where necessary
tron
parents: 964
diff changeset
    10
#include "gfx.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "player.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "news.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "saveload.h"
405
415546028e8d (svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents: 369
diff changeset
    16
#include "sprite.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2147
diff changeset
    17
#include "variables.h"
2708
48714bad9499 (svn r3252) - NewGRF: Map new train subtypes to old types for rail vehicles.
peter1138
parents: 2639
diff changeset
    18
#include "train.h"
2962
f0a49b646c48 (svn r3524) - Split newgrf features from engine.[ch] into newgrf_engine.[ch], and add the new files to project files.
peter1138
parents: 2951
diff changeset
    19
#include "newgrf_engine.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
2763
a4d065e3261b (svn r3308) BAD
tron
parents: 2708
diff changeset
    21
EngineInfo _engine_info[TOTAL_NUM_ENGINES];
a4d065e3261b (svn r3308) BAD
tron
parents: 2708
diff changeset
    22
RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
a4d065e3261b (svn r3308) BAD
tron
parents: 2708
diff changeset
    23
ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
a4d065e3261b (svn r3308) BAD
tron
parents: 2708
diff changeset
    24
AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
a4d065e3261b (svn r3308) BAD
tron
parents: 2708
diff changeset
    25
RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
a4d065e3261b (svn r3308) BAD
tron
parents: 2708
diff changeset
    26
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
enum {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	ENGINE_AVAILABLE = 1,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	ENGINE_INTRODUCING = 2,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	ENGINE_PREVIEWING = 4,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    33
/** TRANSLATE FROM LOCAL CARGO TO GLOBAL CARGO ID'S.
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    34
 * This maps the per-landscape cargo ID's to globally unique cargo ID's usable ie. in
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    35
 * the custom GRF  files. It is basically just a transcribed table from TTDPatch's newgrf.txt.
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    36
 */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    37
const CargoID _global_cargo_id[NUM_LANDSCAPE][NUM_CARGO] = {
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    38
	/* LT_NORMAL */ {GC_PASSENGERS, GC_COAL,  GC_MAIL, GC_OIL, GC_LIVESTOCK, GC_GOODS, GC_GRAIN, GC_WOOD, GC_IRON_ORE,    GC_STEEL,  GC_VALUABLES, GC_PAPER_TEMP},
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    39
	/* LT_HILLY */  {GC_PASSENGERS, GC_COAL,  GC_MAIL, GC_OIL, GC_LIVESTOCK, GC_GOODS, GC_GRAIN, GC_WOOD, GC_INVALID,     GC_PAPER,  GC_VALUABLES, GC_FOOD },
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    40
	/* LT_DESERT */ {GC_PASSENGERS, GC_RUBBER,GC_MAIL, GC_OIL, GC_FRUIT,     GC_GOODS, GC_GRAIN, GC_WOOD, GC_COPPER_ORE,  GC_WATER,  GC_VALUABLES, GC_FOOD },
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    41
	/* LT_CANDY */  {GC_PASSENGERS, GC_SUGAR, GC_MAIL, GC_TOYS,GC_BATTERIES, GC_CANDY, GC_TOFFEE,GC_COLA, GC_COTTON_CANDY,GC_BUBBLES,GC_PLASTIC,   GC_FIZZY_DRINKS },
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    42
	/**
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    43
	 * - GC_INVALID (255) means that  cargo is not available for that climate
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    44
	 * - GC_PAPER_TEMP (27) is paper in  temperate climate in TTDPatch
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    45
	 * Following can  be renumbered:
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    46
	 * - GC_DEFAULT (29) is the defa ult cargo for the purpose of spritesets
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    47
	 * - GC_PURCHASE (30) is the purchase list image (the equivalent of 0xff) for the purpose of spritesets
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    48
	 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    51
/** BEGIN --- TRANSLATE FROM GLOBAL CARGO TO LOCAL CARGO ID'S **/
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    52
/** Map global cargo ID's to local-cargo ID's */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    53
const CargoID _local_cargo_id_ctype[NUM_GLOBAL_CID] = {
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    54
	CT_PASSENGERS,CT_COAL,   CT_MAIL,        CT_OIL,      CT_LIVESTOCK,CT_GOODS,  CT_GRAIN,      CT_WOOD,         /*  0- 7 */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    55
	CT_IRON_ORE,  CT_STEEL,  CT_VALUABLES,   CT_PAPER,    CT_FOOD,     CT_FRUIT,  CT_COPPER_ORE, CT_WATER,        /*  8-15 */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    56
	CT_RUBBER,    CT_SUGAR,  CT_TOYS,        CT_BATTERIES,CT_CANDY,    CT_TOFFEE, CT_COLA,       CT_COTTON_CANDY, /* 16-23 */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    57
	CT_BUBBLES,   CT_PLASTIC,CT_FIZZY_DRINKS,CT_PAPER     /* unsup. */,CT_HILLY_UNUSED,                           /* 24-28 */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    58
	CT_INVALID,   CT_INVALID                                                                                      /* 29-30 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    61
#define MC(cargo) (1 << cargo)
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    62
/** Bitmasked value where the global cargo ID is available in landscape
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    63
 * 0: LT_NORMAL, 1: LT_HILLY, 2: LT_DESERT, 3: LT_CANDY */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    64
const uint32 _landscape_global_cargo_mask[NUM_LANDSCAPE] =
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    65
{ /* LT_NORMAL: temperate */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    66
	MC(GC_PASSENGERS)|MC(GC_COAL)|MC(GC_MAIL)|MC(GC_OIL)|MC(GC_LIVESTOCK)|MC(GC_GOODS)|MC(GC_GRAIN)|MC(GC_WOOD)|
2611
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
    67
	MC(GC_IRON_ORE)|MC(GC_STEEL)|MC(GC_VALUABLES),
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    68
	/* LT_HILLY: arctic */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    69
	MC(GC_PASSENGERS)|MC(GC_COAL)|MC(GC_MAIL)|MC(GC_OIL)|MC(GC_LIVESTOCK)|MC(GC_GOODS)|
2611
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
    70
	MC(GC_GRAIN)|MC(GC_WOOD)|MC(GC_VALUABLES)|MC(GC_PAPER)|MC(GC_FOOD),
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    71
	/* LT_DESERT: rainforest/desert */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    72
	MC(GC_PASSENGERS)|MC(GC_MAIL)|MC(GC_OIL)|MC(GC_GOODS)|MC(GC_GRAIN)|MC(GC_WOOD)|
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    73
	MC(GC_VALUABLES)|MC(GC_FOOD)|MC(GC_FRUIT)|MC(GC_COPPER_ORE)|MC(GC_WATER)|MC(GC_RUBBER),
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    74
	/* LT_CANDY: toyland */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    75
	MC(GC_PASSENGERS)|MC(GC_MAIL)|MC(GC_SUGAR)|MC(GC_TOYS)|MC(GC_BATTERIES)|MC(GC_CANDY)|
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    76
	MC(GC_TOFFEE)|MC(GC_COLA)|MC(GC_COTTON_CANDY)|MC(GC_BUBBLES)|MC(GC_PLASTIC)|MC(GC_FIZZY_DRINKS)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
};
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    78
/** END   --- TRANSLATE FROM GLOBAL CARGO TO LOCAL CARGO ID'S **/
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    79
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    80
/** Bitmasked values of what type of cargo is refittable for the given vehicle-type.
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    81
 * This coupled with the landscape information (_landscape_global_cargo_mask) gives
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    82
 * us exactly what is refittable and what is not */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    83
const uint32 _default_refitmasks[NUM_VEHICLE_TYPES] = {
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    84
	/* Trains */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    85
	MC(GC_PASSENGERS)|MC(GC_COAL)|MC(GC_MAIL)|MC(GC_LIVESTOCK)|MC(GC_GOODS)|MC(GC_GRAIN)|MC(GC_WOOD)|MC(GC_IRON_ORE)|
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    86
	MC(GC_STEEL)|MC(GC_VALUABLES)|MC(GC_PAPER)|MC(GC_FOOD)|MC(GC_FRUIT)|MC(GC_COPPER_ORE)|MC(GC_WATER)|MC(GC_SUGAR)|
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    87
	MC(GC_TOYS)|MC(GC_CANDY)|MC(GC_TOFFEE)|MC(GC_COLA)|MC(GC_COTTON_CANDY)|MC(GC_BUBBLES)|MC(GC_PLASTIC)|MC(GC_FIZZY_DRINKS),
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    88
	/* Road vehicles (not refittable by default) */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    89
	0,
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    90
	/* Ships */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    91
	MC(GC_COAL)|MC(GC_MAIL)|MC(GC_LIVESTOCK)|MC(GC_GOODS)|MC(GC_GRAIN)|MC(GC_WOOD)|MC(GC_IRON_ORE)|MC(GC_STEEL)|MC(GC_VALUABLES)|
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    92
	MC(GC_PAPER)|MC(GC_FOOD)|MC(GC_FRUIT)|MC(GC_COPPER_ORE)|MC(GC_WATER)|MC(GC_RUBBER)|MC(GC_SUGAR)|MC(GC_TOYS)|MC(GC_BATTERIES)|
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    93
	MC(GC_CANDY)|MC(GC_TOFFEE)|MC(GC_COLA)|MC(GC_COTTON_CANDY)|MC(GC_BUBBLES)|MC(GC_PLASTIC)|MC(GC_FIZZY_DRINKS),
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    94
	/* Aircraft */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    95
	MC(GC_PASSENGERS)|MC(GC_MAIL)|MC(GC_GOODS)|MC(GC_VALUABLES)|MC(GC_FOOD)|MC(GC_FRUIT)|MC(GC_SUGAR)|MC(GC_TOYS)|
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    96
	MC(GC_BATTERIES)|MC(GC_CANDY)|MC(GC_TOFFEE)|MC(GC_COLA)|MC(GC_COTTON_CANDY)|MC(GC_BUBBLES)|MC(GC_PLASTIC)|MC(GC_FIZZY_DRINKS),
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    97
	/* Special/Disaster */
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    98
	0,0
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
    99
};
2611
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   100
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   101
/**
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   102
 * Bitmask of classes for cargo types.
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   103
 */
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   104
const uint32 cargo_classes[16] = {
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   105
	/* Passengers */ MC(GC_PASSENGERS),
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   106
	/* Mail       */ MC(GC_MAIL),
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   107
	/* Express    */ MC(GC_GOODS)|MC(GC_FOOD)|MC(GC_CANDY),
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   108
	/* Armoured   */ MC(GC_VALUABLES),
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   109
	/* Bulk       */ MC(GC_COAL)|MC(GC_GRAIN)|MC(GC_IRON_ORE)|MC(GC_COPPER_ORE)|MC(GC_FRUIT)|MC(GC_SUGAR)|MC(GC_TOFFEE)|MC(GC_COTTON_CANDY),
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   110
	/* Piece      */ MC(GC_LIVESTOCK)|MC(GC_WOOD)|MC(GC_STEEL)|MC(GC_PAPER)|MC(GC_TOYS)|MC(GC_BATTERIES)|MC(GC_BUBBLES)|MC(GC_FIZZY_DRINKS),
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   111
	/* Liquids    */ MC(GC_OIL)|MC(GC_WATER)|MC(GC_RUBBER)|MC(GC_COLA)|MC(GC_PLASTIC),
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   112
	/* Chilled    */ MC(GC_FOOD)|MC(GC_FRUIT),
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   113
	/* Undefined  */ 0, 0, 0, 0, 0, 0, 0, 0
36aa372eeb34 (svn r3148) -NewGRF, Feature: Add support for cargo refitting specification by cargo classes.
peter1138
parents: 2602
diff changeset
   114
};
1802
da61740cc1e7 (svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Darkvater
parents: 1786
diff changeset
   115
#undef MC
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2469
diff changeset
   117
void ShowEnginePreviewWindow(EngineID engine);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1009
diff changeset
   119
void DeleteCustomEngineNames(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
	uint i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
	StringID old;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1329
diff changeset
   124
	for (i = 0; i != TOTAL_NUM_ENGINES; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
		old = _engine_name_strings[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
		_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
   127
		DeleteName(old);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	_vehicle_design_names &= ~1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1009
diff changeset
   133
void LoadCustomEngineNames(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
	// XXX: not done */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
	DEBUG(misc, 1) ("LoadCustomEngineNames: not done");
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1009
diff changeset
   139
static void SetupEngineNames(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
{
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1329
diff changeset
   141
	StringID *name;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1329
diff changeset
   143
	for (name = _engine_name_strings; name != endof(_engine_name_strings); name++)
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1329
diff changeset
   144
		*name = STR_SV_EMPTY;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
	DeleteCustomEngineNames();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	LoadCustomEngineNames();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1009
diff changeset
   150
static void AdjustAvailAircraft(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	uint16 date = _date;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
	byte avail = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	if (date >= 12784) avail |= 2; // big airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
	if (date < 14610 || _patches.always_small_airport) avail |= 1;  // small airport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
	if (date >= 15706) avail |= 4; // enable heliport
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	if (avail != _avail_aircraft) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
		_avail_aircraft = avail;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
		InvalidateWindow(WC_BUILD_STATION, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
static void CalcEngineReliability(Engine *e)
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
	uint age = e->age;
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
	if (age < e->duration_phase_1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
		uint start = e->reliability_start;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
		e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
	} else if ((age -= e->duration_phase_1) < e->duration_phase_2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
		e->reliability = e->reliability_max;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
	} 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
   174
		uint max = e->reliability_max;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
		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
   176
	} else {
292
16c136eaffcb (svn r298) Fix: Engines from other climates do not appear any more when never_expire_vehicles is enabled
dominik
parents: 257
diff changeset
   177
		// time's up for this engine
16c136eaffcb (svn r298) Fix: Engines from other climates do not appear any more when never_expire_vehicles is enabled
dominik
parents: 257
diff changeset
   178
		// make it either available to all players (if never_expire_vehicles is enabled and if it was available earlier)
16c136eaffcb (svn r298) Fix: Engines from other climates do not appear any more when never_expire_vehicles is enabled
dominik
parents: 257
diff changeset
   179
		// or disable this engine completely
16c136eaffcb (svn r298) Fix: Engines from other climates do not appear any more when never_expire_vehicles is enabled
dominik
parents: 257
diff changeset
   180
		e->player_avail = (_patches.never_expire_vehicles && e->player_avail)? -1 : 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
		e->reliability = e->reliability_final;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1009
diff changeset
   185
void AddTypeToEngines(void)
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 819
diff changeset
   186
{
2242
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   187
	Engine* e = _engines;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 819
diff changeset
   188
2242
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   189
	do e->type = VEH_Train;    while (++e < &_engines[ROAD_ENGINES_INDEX]);
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   190
	do e->type = VEH_Road;     while (++e < &_engines[SHIP_ENGINES_INDEX]);
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   191
	do e->type = VEH_Ship;     while (++e < &_engines[AIRCRAFT_ENGINES_INDEX]);
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   192
	do e->type = VEH_Aircraft; while (++e < &_engines[TOTAL_NUM_ENGINES]);
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   193
	do e->type = VEH_Special;  while (++e < endof(_engines));
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 819
diff changeset
   194
}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 819
diff changeset
   195
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1009
diff changeset
   196
void StartupEngines(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	Engine *e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
	const EngineInfo *ei;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	SetupEngineNames();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
2242
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   203
	for (e = _engines, ei = _engine_info; e != endof(_engines); e++, ei++) {
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   204
		uint32 r;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
		e->age = 0;
2530
df14798edc40 (svn r3059) Use bitfields to encode railtype and climates of engines instead of manual shifting/anding
tron
parents: 2491
diff changeset
   207
		e->railtype = ei->railtype;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
		e->flags = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
		e->player_avail = 0;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   210
2875
8d939bcf7784 (svn r3423) - NewGRF: Update the base_intro age at which an engine will have a randomized intro date, as per (the now updated) spec.
peter1138
parents: 2862
diff changeset
   211
		// The magic value of 729 days below comes from the NewGRF spec. If the
8d939bcf7784 (svn r3423) - NewGRF: Update the base_intro age at which an engine will have a randomized intro date, as per (the now updated) spec.
peter1138
parents: 2862
diff changeset
   212
		// base intro date is before 1922 then the random number of days is not
8d939bcf7784 (svn r3423) - NewGRF: Update the base_intro age at which an engine will have a randomized intro date, as per (the now updated) spec.
peter1138
parents: 2862
diff changeset
   213
		// added.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
		r = Random();
2875
8d939bcf7784 (svn r3423) - NewGRF: Update the base_intro age at which an engine will have a randomized intro date, as per (the now updated) spec.
peter1138
parents: 2862
diff changeset
   215
		e->intro_date = ei->base_intro <= 729 ? ei->base_intro : GB(r, 0, 9) + ei->base_intro;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
		if (e->intro_date <= _date) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
			e->age = (_date - e->intro_date) >> 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
			e->player_avail = (byte)-1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
			e->flags |= ENGINE_AVAILABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 1988
diff changeset
   222
		e->reliability_start = GB(r, 16, 14) + 0x7AE0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
		r = Random();
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 1988
diff changeset
   224
		e->reliability_max   = GB(r,  0, 14) + 0xBFFF;
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 1988
diff changeset
   225
		e->reliability_final = GB(r, 16, 14) + 0x3FFF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
		r = Random();
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 1988
diff changeset
   228
		e->duration_phase_1 = GB(r, 0, 5) + 7;
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 1988
diff changeset
   229
		e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96;
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 1988
diff changeset
   230
		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
   231
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
		e->reliability_spd_dec = (ei->unk2&0x7F) << 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
		/* my invented flag for something that is a wagon */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
		if (ei->unk2 & 0x80) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
			e->age = 0xFFFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
			CalcEngineReliability(e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
		e->lifelength = ei->lifelength + _patches.extend_vehicle_life;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
		// prevent certain engines from ever appearing.
2530
df14798edc40 (svn r3059) Use bitfields to encode railtype and climates of engines instead of manual shifting/anding
tron
parents: 2491
diff changeset
   244
		if (!HASBIT(ei->climates, _opt.landscape)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
			e->flags |= ENGINE_AVAILABLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
			e->player_avail = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
		}
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 842
diff changeset
   248
819
c425b7e22f6a (svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents: 740
diff changeset
   249
		/* This sets up type for the engine
c425b7e22f6a (svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents: 740
diff changeset
   250
		   It is needed if you want to ask the engine what type it is
c425b7e22f6a (svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents: 740
diff changeset
   251
		   It should hopefully be the same as when you ask a vehicle what it is
c425b7e22f6a (svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents: 740
diff changeset
   252
		   but using this, you can ask what type an engine number is
c425b7e22f6a (svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents: 740
diff changeset
   253
		   even if it is not a vehicle (yet)*/
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
	AdjustAvailAircraft();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2769
diff changeset
   259
static void AcceptEnginePreview(Engine *e, PlayerID player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
{
1962
8254df1b359b (svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents: 1926
diff changeset
   261
	Player *p = GetPlayer(player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   263
	assert(e->railtype < RAILTYPE_END);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
	SETBIT(e->player_avail, player);
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   265
	SETBIT(p->avail_railtypes, e->railtype);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
	e->preview_player = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	InvalidateWindowClasses(WC_BUILD_VEHICLE);
1096
87415b0c6fdb (svn r1597) fix: autoreplace vehicle lists are now redrawn when a new vehicle becomes available (thanks LordOfThePigs for pointing this one out)
bjarni
parents: 1093
diff changeset
   269
	InvalidateWindowClasses(WC_REPLACE_VEHICLE);
0
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
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   272
static PlayerID GetBestPlayer(PlayerID pp)
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   273
{
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   274
	const Player *p;
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   275
	int32 best_hist;
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   276
	PlayerID best_player;
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   277
	uint mask = 0;
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   278
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   279
	do {
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   280
		best_hist = -1;
2469
59a0073914d8 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2242
diff changeset
   281
		best_player = OWNER_SPECTATOR;
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   282
		FOR_ALL_PLAYERS(p) {
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   283
			if (p->is_active && p->block_preview == 0 && !HASBIT(mask, p->index) &&
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   284
					p->old_economy[0].performance_history > best_hist) {
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   285
				best_hist = p->old_economy[0].performance_history;
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   286
				best_player = p->index;
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   287
			}
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   288
		}
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   289
2469
59a0073914d8 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2242
diff changeset
   290
		if (best_player == OWNER_SPECTATOR) return OWNER_SPECTATOR;
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   291
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   292
		SETBIT(mask, best_player);
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   293
	} while (--pp != 0);
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   294
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   295
	return best_player;
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   296
}
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   297
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1009
diff changeset
   298
void EnginesDailyLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
{
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2469
diff changeset
   300
	EngineID i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   302
	if (_cur_year >= 130) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
2242
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   304
	for (i = 0; i != lengthof(_engines); i++) {
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   305
		Engine* e = &_engines[i];
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   306
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
		if (e->flags & ENGINE_INTRODUCING) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
			if (e->flags & ENGINE_PREVIEWING) {
740
ab84ecdf86a2 (svn r1196) -Fix: Preview Vehicle had a small glitch. Fixed now.
truelight
parents: 555
diff changeset
   309
				if (e->preview_player != 0xFF && !--e->preview_wait) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
					e->flags &= ~ENGINE_PREVIEWING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
					DeleteWindowById(WC_ENGINE_PREVIEW, i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
					e->preview_player++;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   313
				}
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   314
 			} else if (e->preview_player != 0xFF) {
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   315
				PlayerID best_player = GetBestPlayer(e->preview_player);
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   316
2469
59a0073914d8 (svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
tron
parents: 2242
diff changeset
   317
				if (best_player == OWNER_SPECTATOR) {
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   318
					e->preview_player = 0xFF;
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   319
					continue;
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   320
				}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   321
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
				if (!IS_HUMAN_PLAYER(best_player)) {
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   323
					/* XXX - TTDBUG: TTD has a bug here ???? */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
					AcceptEnginePreview(e, best_player);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
				} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
					e->flags |= ENGINE_PREVIEWING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
					e->preview_wait = 20;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2611
diff changeset
   328
					if (IS_INTERACTIVE_PLAYER(best_player)) ShowEnginePreviewWindow(i);
0
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
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   335
/** Accept an engine prototype. XXX - it is possible that the top-player
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   336
 * changes while you are waiting to accept the offer? Then it becomes invalid
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3222
diff changeset
   337
 * @param tile unused
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   338
 * @param p1 engine-prototype offered
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   339
 * @param p2 unused
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   340
 */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3222
diff changeset
   341
int32 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
   342
{
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   343
	Engine *e;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2875
diff changeset
   344
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   345
	if (!IsEngineIndex(p1)) return CMD_ERROR;
1926
530480d14685 (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1908
diff changeset
   346
	e = GetEngine(p1);
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   347
	if (GetBestPlayer(e->preview_player) != _current_player) return CMD_ERROR;
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   348
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2875
diff changeset
   349
	if (flags & DC_EXEC) AcceptEnginePreview(e, _current_player);
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   350
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
257
0ff8a2e60a0d (svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents: 220
diff changeset
   354
// Determine if an engine type is a wagon (and not a loco)
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2469
diff changeset
   355
static bool IsWagon(EngineID index)
257
0ff8a2e60a0d (svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents: 220
diff changeset
   356
{
964
fe9e7b220b9f (svn r1456) Simplify isWagon(), make it static and give it a canonical name (IsWagon)
tron
parents: 938
diff changeset
   357
	return index < NUM_TRAIN_ENGINES && RailVehInfo(index)->flags & RVI_WAGON;
257
0ff8a2e60a0d (svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents: 220
diff changeset
   358
}
0ff8a2e60a0d (svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents: 220
diff changeset
   359
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 408
diff changeset
   360
static void NewVehicleAvailable(Engine *e)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
	Vehicle *v;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
	Player *p;
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2469
diff changeset
   364
	EngineID index = e - _engines;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
	// In case the player didn't build the vehicle during the intro period,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
	// prevent that player from getting future intro periods for a while.
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2611
diff changeset
   368
	if (e->flags & ENGINE_INTRODUCING) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
		FOR_ALL_PLAYERS(p) {
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   370
			uint block_preview = p->block_preview;
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   371
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2611
diff changeset
   372
			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
   373
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   374
			/* We assume the user did NOT build it.. prove me wrong ;) */
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   375
			p->block_preview = 20;
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   376
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   377
			FOR_ALL_VEHICLES(v) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
				if (v->type == VEH_Train || v->type == VEH_Road || v->type == VEH_Ship ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
						(v->type == VEH_Aircraft && v->subtype <= 2)) {
919
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   380
					if (v->owner == p->index && v->engine_type == index) {
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   381
						/* The user did prove me wrong, so restore old value */
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   382
						p->block_preview = block_preview;
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   383
						break;
544f374ee392 (svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents: 915
diff changeset
   384
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
114
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   390
	e->flags = (e->flags & ~ENGINE_INTRODUCING) | ENGINE_AVAILABLE;
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   391
	InvalidateWindowClasses(WC_BUILD_VEHICLE);
1096
87415b0c6fdb (svn r1597) fix: autoreplace vehicle lists are now redrawn when a new vehicle becomes available (thanks LordOfThePigs for pointing this one out)
bjarni
parents: 1093
diff changeset
   392
	InvalidateWindowClasses(WC_REPLACE_VEHICLE);
114
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   393
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
	// Now available for all players
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
	e->player_avail = (byte)-1;
114
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   396
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   397
	// Do not introduce new rail wagons
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2611
diff changeset
   398
	if (IsWagon(index)) return;
114
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   399
6a2af0c2d0db (svn r115) Fix: monorail/maglev became available around 1927
dominik
parents: 0
diff changeset
   400
	// make maglev / monorail available
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
	FOR_ALL_PLAYERS(p) {
2147
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   402
		if (p->is_active) {
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   403
			assert(e->railtype < RAILTYPE_END);
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   404
			SETBIT(p->avail_railtypes, e->railtype);
eb6ba42fd216 (svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents: 2140
diff changeset
   405
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2469
diff changeset
   408
	if (index < NUM_TRAIN_ENGINES) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
		AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_TRAINAVAIL), 0, 0);
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2469
diff changeset
   410
	} else if (index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
		AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_ROADAVAIL), 0, 0);
2477
225b2916fe2a (svn r3003) Change int, uint, uin16 and byte to EngineID where appropriate, plus some related changes (mostly casts)
tron
parents: 2469
diff changeset
   412
	} else if (index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
		AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_SHIPAVAIL), 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
		AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_AIRCRAFTAVAIL), 0, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1009
diff changeset
   419
void EnginesMonthlyLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
	Engine *e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
	if (_cur_year < 130) {
2242
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   424
		for (e = _engines; e != endof(_engines); e++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
			// Age the vehicle
2242
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   426
			if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
				e->age++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
				CalcEngineReliability(e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
2990
2bbe7769ebd4 (svn r3565) - Fix: On loading a game, GetPlayerRailtypes() didn't account for the fact that vehicles are introduced a year after their introduction date. This will also relieve possible (rare) network desyncs.
peter1138
parents: 2962
diff changeset
   431
			if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + 365)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
				// Introduce it to all players
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
				NewVehicleAvailable(e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
			} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_INTRODUCING)) && _date >= e->intro_date) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
				// Introduction date has passed.. show introducing dialog to one player.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
				e->flags |= ENGINE_INTRODUCING;
257
0ff8a2e60a0d (svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents: 220
diff changeset
   437
0ff8a2e60a0d (svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents: 220
diff changeset
   438
				// Do not introduce new rail wagons
964
fe9e7b220b9f (svn r1456) Simplify isWagon(), make it static and give it a canonical name (IsWagon)
tron
parents: 938
diff changeset
   439
				if (!IsWagon(e - _engines))
257
0ff8a2e60a0d (svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents: 220
diff changeset
   440
					e->preview_player = 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
   441
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
	AdjustAvailAircraft();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   447
/** Rename an engine.
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3222
diff changeset
   448
 * @param tile unused
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   449
 * @param p1 engine ID to rename
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   450
 * @param p2 unused
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   451
 */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3222
diff changeset
   452
int32 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
   453
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
	StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
1840
ce40137a6ab4 (svn r2345) - Fix: Don't allow stuff to be renamed to nothing if we don't support it. Only valid ones are signs (delete) and waypoints (rename to default).
Darkvater
parents: 1820
diff changeset
   456
	if (!IsEngineIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   457
1820
d03c56850dc2 (svn r2324) Introduce _cmd_text for passing strings with a command instead of abusing _decode_parameters as text buffer. This should prevent several possible buffer overruns and is a bit cleaner to use. As bonus it reduces the size of most command packets by 79 bytes.
tron
parents: 1802
diff changeset
   458
	str = AllocateNameUnique(_cmd_text, 0);
1786
7cfd46c3fcc4 (svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents: 1560
diff changeset
   459
	if (str == 0) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 114
diff changeset
   460
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
		StringID old_str = _engine_name_strings[p1];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
		_engine_name_strings[p1] = str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
		DeleteName(old_str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
		_vehicle_design_names |= 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
		MarkWholeScreenDirty();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
		DeleteName(str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   475
/*
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   476
 * returns true if an engine is valid, of the specified type, and buildable by
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   477
 * the current player, false otherwise
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   478
 *
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   479
 * engine = index of the engine to check
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   480
 * type   = the type the engine should be of (VEH_xxx)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   481
 */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   482
bool IsEngineBuildable(uint engine, byte type)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   483
{
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   484
	const Engine *e;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   485
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   486
	// check if it's an engine that is in the engine array
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   487
	if (!IsEngineIndex(engine)) return false;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   488
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   489
	e = GetEngine(engine);
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   490
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   491
	// check if it's an engine of specified type
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   492
	if (e->type != type) return false;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   493
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   494
	// check if it's available
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   495
	if (!HASBIT(e->player_avail, _current_player)) return false;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   496
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   497
	return true;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   498
}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   499
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   500
/************************************************************************
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   501
 * Engine Replacement stuff
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   502
 ************************************************************************/
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   503
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   504
static void EngineRenewPoolNewBlock(uint start_item); /* Forward declare for initializer of _engine_renew_pool */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   505
enum {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   506
	ENGINE_RENEW_POOL_BLOCK_SIZE_BITS = 3,
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   507
	ENGINE_RENEW_POOL_MAX_BLOCKS      = 8000,
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   508
};
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   509
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   510
MemoryPool _engine_renew_pool = { "EngineRe", ENGINE_RENEW_POOL_MAX_BLOCKS, ENGINE_RENEW_POOL_BLOCK_SIZE_BITS, sizeof(EngineRenew), &EngineRenewPoolNewBlock, 0, 0, NULL };
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   511
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   512
static inline uint16 GetEngineRenewPoolSize(void)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   513
{
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   514
	return _engine_renew_pool.total_items;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   515
}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   516
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   517
#define FOR_ALL_ENGINE_RENEWS_FROM(er, start) for (er = GetEngineRenew(start); er != NULL; er = (er->index + 1 < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1) : NULL)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   518
#define FOR_ALL_ENGINE_RENEWS(er) FOR_ALL_ENGINE_RENEWS_FROM(er, 0)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   519
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   520
static void EngineRenewPoolNewBlock(uint start_item)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   521
{
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   522
	EngineRenew *er;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   523
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   524
	FOR_ALL_ENGINE_RENEWS_FROM(er, start_item) {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   525
		er->index = start_item++;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   526
		er->from = INVALID_ENGINE;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   527
	}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   528
}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   529
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   530
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   531
static EngineRenew *AllocateEngineRenew(void)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   532
{
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   533
	EngineRenew *er;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   534
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   535
	FOR_ALL_ENGINE_RENEWS(er) {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   536
		if (er->from == INVALID_ENGINE) {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   537
			er->to = INVALID_ENGINE;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   538
			er->next = NULL;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   539
			return er;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   540
		}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   541
	}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   542
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   543
	/* Check if we can add a block to the pool */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   544
	if (AddBlockToPool(&_engine_renew_pool)) return AllocateEngineRenew();
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   545
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   546
	return NULL;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   547
}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   548
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   549
/**
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   550
 * Retrieves the EngineRenew that specifies the replacement of the given
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   551
 * engine type from the given renewlist */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   552
static EngineRenew *GetEngineReplacement(EngineRenewList erl, EngineID engine)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   553
{
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   554
	EngineRenew* er = (EngineRenew*)erl; /* Fetch first element */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   555
	while (er) {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   556
		if (er->from == engine) return er;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   557
		er = er->next;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   558
	}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   559
	return NULL;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   560
}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   561
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   562
void RemoveAllEngineReplacement(EngineRenewList* erl)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   563
{
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   564
	EngineRenew* er = (EngineRenew*)(*erl); /* Fetch first element */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   565
	while (er) {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   566
		er->from = INVALID_ENGINE; /* "Deallocate" all elements */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   567
		er = er->next;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   568
	}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   569
	*erl = NULL; /* Empty list */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   570
}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   571
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   572
EngineID EngineReplacement(EngineRenewList erl, EngineID engine)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   573
{
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   574
	const EngineRenew *er = GetEngineReplacement(erl, engine);
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   575
	return er == NULL ? INVALID_ENGINE : er->to;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   576
}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   577
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   578
int32 AddEngineReplacement(EngineRenewList* erl, EngineID old_engine, EngineID new_engine, uint32 flags)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   579
{
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   580
	EngineRenew *er;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   581
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   582
	// Check if the old vehicle is already in the list
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   583
	er = GetEngineReplacement(*erl, old_engine);
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   584
	if (er != NULL) {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   585
		if (flags & DC_EXEC) er->to = new_engine;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   586
		return 0;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   587
	}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   588
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   589
	er = AllocateEngineRenew();
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   590
	if (er == NULL) return CMD_ERROR;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   591
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   592
	if (flags & DC_EXEC) {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   593
		er->from = old_engine;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   594
		er->to = new_engine;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   595
		er->next = (EngineRenew*)(*erl); /* Resolve the first element in the list */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   596
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   597
		*erl = (EngineRenewList)er; /* Insert before the first element */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   598
	}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   599
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   600
	return 0;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   601
}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   602
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   603
int32 RemoveEngineReplacement(EngineRenewList* erl, EngineID engine, uint32 flags)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   604
{
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   605
	EngineRenew* er = (EngineRenew*)(*erl); /* Start at the first element */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   606
	EngineRenew* prev = NULL;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   607
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   608
	while (er)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   609
	{
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   610
		if (er->from == engine) {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   611
			if (flags & DC_EXEC) {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   612
				if (prev == NULL) { /* First element */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   613
					(*erl) = (EngineRenewList)er->next; /* The second becomes the new first element */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   614
				} else {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   615
					prev->next = er->next; /* Cut this element out */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   616
				}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   617
				er->from = INVALID_ENGINE; /* Deallocate */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   618
			}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   619
			return 0;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   620
		}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   621
		prev = er;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   622
		er = er->next; /* Look at next element */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   623
	}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   624
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   625
	return CMD_ERROR; /* Not found? */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   626
}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   627
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   628
static const SaveLoad _engine_renew_desc[] = {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   629
	SLE_VAR(EngineRenew, from, SLE_UINT16),
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   630
	SLE_VAR(EngineRenew, to,   SLE_UINT16),
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   631
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   632
	SLE_REF(EngineRenew, next, REF_ENGINE_RENEWS),
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   633
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   634
	SLE_END()
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   635
};
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   636
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   637
static void Save_ERNW(void)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   638
{
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   639
	EngineRenew *er;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   640
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   641
	FOR_ALL_ENGINE_RENEWS(er) {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   642
		if (er->from != INVALID_ENGINE) {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   643
			SlSetArrayIndex(er->index);
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   644
			SlObject(er, _engine_renew_desc);
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   645
		}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   646
	}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   647
}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   648
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   649
static void Load_ERNW(void)
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   650
{
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   651
	int index;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   652
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   653
	while ((index = SlIterateArray()) != -1) {
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   654
		EngineRenew *er;
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   655
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   656
		if (!AddBlockIfNeeded(&_engine_renew_pool, index))
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   657
			error("EngineRenews: failed loading savegame: too many EngineRenews");
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   658
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   659
		er = GetEngineRenew(index);
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   660
		SlObject(er, _engine_renew_desc);
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   661
	}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   662
}
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   663
1881
435d39bd6ee0 (svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents: 1855
diff changeset
   664
static const SaveLoad _engine_desc[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
	SLE_VAR(Engine,intro_date,						SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
	SLE_VAR(Engine,age,										SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
	SLE_VAR(Engine,reliability,						SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
	SLE_VAR(Engine,reliability_spd_dec,		SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
	SLE_VAR(Engine,reliability_start,			SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
	SLE_VAR(Engine,reliability_max,				SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
	SLE_VAR(Engine,reliability_final,			SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
	SLE_VAR(Engine,duration_phase_1,			SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
	SLE_VAR(Engine,duration_phase_2,			SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
	SLE_VAR(Engine,duration_phase_3,			SLE_UINT16),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   676
	SLE_VAR(Engine,lifelength,						SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
	SLE_VAR(Engine,flags,									SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
	SLE_VAR(Engine,preview_player,				SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
	SLE_VAR(Engine,preview_wait,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
	SLE_VAR(Engine,railtype,							SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
	SLE_VAR(Engine,player_avail,					SLE_UINT8),
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
	// reserve extra space in savegame here. (currently 16 bytes)
3222
6de22e06a1e9 (svn r3895) - Add proper SLE(G)_CONDNULL macros for the empty space reservation in savegames and update where used
Darkvater
parents: 3047
diff changeset
   684
	SLE_CONDNULL(16, 2, SL_MAX_VERSION),
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
	SLE_END()
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1009
diff changeset
   689
static void Save_ENGN(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
{
2242
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   691
	uint i;
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   692
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   693
	for (i = 0; i != lengthof(_engines); i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
		SlSetArrayIndex(i);
2242
512eae2cf006 (svn r2762) Simplify a loop, remove an unused variable and add many consts
tron
parents: 2204
diff changeset
   695
		SlObject(&_engines[i], _engine_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1009
diff changeset
   699
static void Load_ENGN(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
	int index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
	while ((index = SlIterateArray()) != -1) {
1926
530480d14685 (svn r2432) Use GetEngine() instead of DEREF_ENGINE() or even _engines[]
tron
parents: 1908
diff changeset
   703
		SlObject(GetEngine(index), _engine_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1009
diff changeset
   707
static void LoadSave_ENGS(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
	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
   710
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   711
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
const ChunkHandler _engine_chunk_handlers[] = {
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   713
	{ 'ENGN', Save_ENGN,     Load_ENGN,     CH_ARRAY          },
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   714
	{ 'ENGS', LoadSave_ENGS, LoadSave_ENGS, CH_RIFF           },
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   715
	{ '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
   716
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   718
void InitializeEngines(void)
1197
433b4a05fa3e (svn r1701) Style police ^^
tron
parents: 1196
diff changeset
   719
{
2848
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   720
	/* Clean the engine renew pool and create 1 block in it */
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   721
	CleanPool(&_engine_renew_pool);
8f57563f8ddf (svn r3396) - Autoreplace changes:
peter1138
parents: 2830
diff changeset
   722
	AddBlockToPool(&_engine_renew_pool);
1196
67f7f3017d99 (svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents: 1096
diff changeset
   723
}