author | tron |
Mon, 10 Apr 2006 07:15:58 +0000 | |
changeset 3491 | 35d747bb5e82 |
parent 3222 | 6de22e06a1e9 |
child 3585 | 43461f26b729 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 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 | 8 |
#include "engine.h" |
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 | 11 |
#include "player.h" |
12 |
#include "command.h" |
|
13 |
#include "vehicle.h" |
|
14 |
#include "news.h" |
|
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 | 20 |
|
2763 | 21 |
EngineInfo _engine_info[TOTAL_NUM_ENGINES]; |
22 |
RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES]; |
|
23 |
ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES]; |
|
24 |
AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES]; |
|
25 |
RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES]; |
|
26 |
||
0 | 27 |
enum { |
28 |
ENGINE_AVAILABLE = 1, |
|
29 |
ENGINE_INTRODUCING = 2, |
|
30 |
ENGINE_PREVIEWING = 4, |
|
31 |
}; |
|
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 | 49 |
}; |
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 | 59 |
}; |
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 | 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 | 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 | 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 | 120 |
{ |
121 |
uint i; |
|
122 |
StringID old; |
|
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 | 125 |
old = _engine_name_strings[i]; |
126 |
_engine_name_strings[i] = i + STR_8000_KIRBY_PAUL_TANK_STEAM; |
|
127 |
DeleteName(old); |
|
128 |
} |
|
129 |
||
130 |
_vehicle_design_names &= ~1; |
|
131 |
} |
|
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 | 134 |
{ |
135 |
// XXX: not done */ |
|
136 |
DEBUG(misc, 1) ("LoadCustomEngineNames: not done"); |
|
137 |
} |
|
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 | 140 |
{ |
1474
a26a21fa10ef
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
141 |
StringID *name; |
0 | 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 | 145 |
|
146 |
DeleteCustomEngineNames(); |
|
147 |
LoadCustomEngineNames(); |
|
148 |
} |
|
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 | 151 |
{ |
152 |
uint16 date = _date; |
|
153 |
byte avail = 0; |
|
154 |
if (date >= 12784) avail |= 2; // big airport |
|
155 |
if (date < 14610 || _patches.always_small_airport) avail |= 1; // small airport |
|
156 |
if (date >= 15706) avail |= 4; // enable heliport |
|
157 |
||
158 |
if (avail != _avail_aircraft) { |
|
159 |
_avail_aircraft = avail; |
|
160 |
InvalidateWindow(WC_BUILD_STATION, 0); |
|
161 |
} |
|
162 |
} |
|
163 |
||
164 |
static void CalcEngineReliability(Engine *e) |
|
165 |
{ |
|
166 |
uint age = e->age; |
|
167 |
||
168 |
if (age < e->duration_phase_1) { |
|
169 |
uint start = e->reliability_start; |
|
170 |
e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start; |
|
171 |
} else if ((age -= e->duration_phase_1) < e->duration_phase_2) { |
|
172 |
e->reliability = e->reliability_max; |
|
173 |
} else if ((age -= e->duration_phase_2) < e->duration_phase_3) { |
|
174 |
uint max = e->reliability_max; |
|
175 |
e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max; |
|
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 | 181 |
e->reliability = e->reliability_final; |
182 |
} |
|
183 |
} |
|
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 | 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 | 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 | 194 |
} |
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 | 197 |
{ |
198 |
Engine *e; |
|
199 |
const EngineInfo *ei; |
|
200 |
||
201 |
SetupEngineNames(); |
|
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 | 205 |
|
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 | 208 |
e->flags = 0; |
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 | 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 | 216 |
if (e->intro_date <= _date) { |
217 |
e->age = (_date - e->intro_date) >> 5; |
|
218 |
e->player_avail = (byte)-1; |
|
219 |
e->flags |= ENGINE_AVAILABLE; |
|
220 |
} |
|
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 | 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 | 226 |
|
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 | 231 |
|
232 |
e->reliability_spd_dec = (ei->unk2&0x7F) << 2; |
|
233 |
||
234 |
/* my invented flag for something that is a wagon */ |
|
235 |
if (ei->unk2 & 0x80) { |
|
236 |
e->age = 0xFFFF; |
|
237 |
} else { |
|
238 |
CalcEngineReliability(e); |
|
239 |
} |
|
240 |
||
241 |
e->lifelength = ei->lifelength + _patches.extend_vehicle_life; |
|
242 |
||
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 | 245 |
e->flags |= ENGINE_AVAILABLE; |
246 |
e->player_avail = 0; |
|
247 |
} |
|
915 | 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 | 254 |
} |
255 |
||
256 |
AdjustAvailAircraft(); |
|
257 |
} |
|
258 |
||
2817 | 259 |
static void AcceptEnginePreview(Engine *e, PlayerID player) |
0 | 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 | 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 | 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 | 266 |
|
267 |
e->preview_player = 0xFF; |
|
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 | 270 |
} |
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 | 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 | 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 | 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 | 307 |
if (e->flags & ENGINE_INTRODUCING) { |
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 | 310 |
e->flags &= ~ENGINE_PREVIEWING; |
311 |
DeleteWindowById(WC_ENGINE_PREVIEW, i); |
|
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 | 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 | 324 |
AcceptEnginePreview(e, best_player); |
325 |
} else { |
|
326 |
e->flags |= ENGINE_PREVIEWING; |
|
327 |
e->preview_wait = 20; |
|
2639 | 328 |
if (IS_INTERACTIVE_PLAYER(best_player)) ShowEnginePreviewWindow(i); |
0 | 329 |
} |
330 |
} |
|
331 |
} |
|
332 |
} |
|
333 |
} |
|
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 | 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 | 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 | 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 | 351 |
return 0; |
352 |
} |
|
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 | 360 |
static void NewVehicleAvailable(Engine *e) |
0 | 361 |
{ |
362 |
Vehicle *v; |
|
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 | 365 |
|
366 |
// In case the player didn't build the vehicle during the intro period, |
|
367 |
// prevent that player from getting future intro periods for a while. |
|
2639 | 368 |
if (e->flags & ENGINE_INTRODUCING) { |
0 | 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 | 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 | 378 |
if (v->type == VEH_Train || v->type == VEH_Road || v->type == VEH_Ship || |
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 | 385 |
} |
386 |
} |
|
387 |
} |
|
388 |
} |
|
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 | 394 |
// Now available for all players |
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 | 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 | 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 | 406 |
} |
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 | 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 | 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 | 413 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_SHIPAVAIL), 0, 0); |
414 |
} else { |
|
415 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_AIRCRAFTAVAIL), 0, 0); |
|
416 |
} |
|
417 |
} |
|
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 | 420 |
{ |
421 |
Engine *e; |
|
422 |
||
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 | 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 | 427 |
e->age++; |
428 |
CalcEngineReliability(e); |
|
429 |
} |
|
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 | 432 |
// Introduce it to all players |
433 |
NewVehicleAvailable(e); |
|
434 |
} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_INTRODUCING)) && _date >= e->intro_date) { |
|
435 |
// Introduction date has passed.. show introducing dialog to one player. |
|
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 | 441 |
} |
442 |
} |
|
443 |
} |
|
444 |
AdjustAvailAircraft(); |
|
445 |
} |
|
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 | 453 |
{ |
454 |
StringID str; |
|
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 | 461 |
if (flags & DC_EXEC) { |
462 |
StringID old_str = _engine_name_strings[p1]; |
|
463 |
_engine_name_strings[p1] = str; |
|
464 |
DeleteName(old_str); |
|
465 |
_vehicle_design_names |= 3; |
|
466 |
MarkWholeScreenDirty(); |
|
467 |
} else { |
|
468 |
DeleteName(str); |
|
469 |
} |
|
470 |
||
471 |
return 0; |
|
472 |
} |
|
473 |
||
474 |
||
2848 | 475 |
/* |
476 |
* returns true if an engine is valid, of the specified type, and buildable by |
|
477 |
* the current player, false otherwise |
|
478 |
* |
|
479 |
* engine = index of the engine to check |
|
480 |
* type = the type the engine should be of (VEH_xxx) |
|
481 |
*/ |
|
482 |
bool IsEngineBuildable(uint engine, byte type) |
|
483 |
{ |
|
484 |
const Engine *e; |
|
485 |
||
486 |
// check if it's an engine that is in the engine array |
|
487 |
if (!IsEngineIndex(engine)) return false; |
|
488 |
||
489 |
e = GetEngine(engine); |
|
490 |
||
491 |
// check if it's an engine of specified type |
|
492 |
if (e->type != type) return false; |
|
493 |
||
494 |
// check if it's available |
|
495 |
if (!HASBIT(e->player_avail, _current_player)) return false; |
|
496 |
||
497 |
return true; |
|
498 |
} |
|
499 |
||
500 |
/************************************************************************ |
|
501 |
* Engine Replacement stuff |
|
502 |
************************************************************************/ |
|
503 |
||
504 |
static void EngineRenewPoolNewBlock(uint start_item); /* Forward declare for initializer of _engine_renew_pool */ |
|
505 |
enum { |
|
506 |
ENGINE_RENEW_POOL_BLOCK_SIZE_BITS = 3, |
|
507 |
ENGINE_RENEW_POOL_MAX_BLOCKS = 8000, |
|
508 |
}; |
|
509 |
||
510 |
MemoryPool _engine_renew_pool = { "EngineRe", ENGINE_RENEW_POOL_MAX_BLOCKS, ENGINE_RENEW_POOL_BLOCK_SIZE_BITS, sizeof(EngineRenew), &EngineRenewPoolNewBlock, 0, 0, NULL }; |
|
511 |
||
512 |
static inline uint16 GetEngineRenewPoolSize(void) |
|
513 |
{ |
|
514 |
return _engine_renew_pool.total_items; |
|
515 |
} |
|
516 |
||
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) |
|
518 |
#define FOR_ALL_ENGINE_RENEWS(er) FOR_ALL_ENGINE_RENEWS_FROM(er, 0) |
|
519 |
||
520 |
static void EngineRenewPoolNewBlock(uint start_item) |
|
521 |
{ |
|
522 |
EngineRenew *er; |
|
523 |
||
524 |
FOR_ALL_ENGINE_RENEWS_FROM(er, start_item) { |
|
525 |
er->index = start_item++; |
|
526 |
er->from = INVALID_ENGINE; |
|
527 |
} |
|
528 |
} |
|
529 |
||
530 |
||
531 |
static EngineRenew *AllocateEngineRenew(void) |
|
532 |
{ |
|
533 |
EngineRenew *er; |
|
534 |
||
535 |
FOR_ALL_ENGINE_RENEWS(er) { |
|
536 |
if (er->from == INVALID_ENGINE) { |
|
537 |
er->to = INVALID_ENGINE; |
|
538 |
er->next = NULL; |
|
539 |
return er; |
|
540 |
} |
|
541 |
} |
|
542 |
||
543 |
/* Check if we can add a block to the pool */ |
|
544 |
if (AddBlockToPool(&_engine_renew_pool)) return AllocateEngineRenew(); |
|
545 |
||
546 |
return NULL; |
|
547 |
} |
|
548 |
||
549 |
/** |
|
550 |
* Retrieves the EngineRenew that specifies the replacement of the given |
|
551 |
* engine type from the given renewlist */ |
|
552 |
static EngineRenew *GetEngineReplacement(EngineRenewList erl, EngineID engine) |
|
553 |
{ |
|
554 |
EngineRenew* er = (EngineRenew*)erl; /* Fetch first element */ |
|
555 |
while (er) { |
|
556 |
if (er->from == engine) return er; |
|
557 |
er = er->next; |
|
558 |
} |
|
559 |
return NULL; |
|
560 |
} |
|
561 |
||
562 |
void RemoveAllEngineReplacement(EngineRenewList* erl) |
|
563 |
{ |
|
564 |
EngineRenew* er = (EngineRenew*)(*erl); /* Fetch first element */ |
|
565 |
while (er) { |
|
566 |
er->from = INVALID_ENGINE; /* "Deallocate" all elements */ |
|
567 |
er = er->next; |
|
568 |
} |
|
569 |
*erl = NULL; /* Empty list */ |
|
570 |
} |
|
571 |
||
572 |
EngineID EngineReplacement(EngineRenewList erl, EngineID engine) |
|
573 |
{ |
|
574 |
const EngineRenew *er = GetEngineReplacement(erl, engine); |
|
575 |
return er == NULL ? INVALID_ENGINE : er->to; |
|
576 |
} |
|
577 |
||
578 |
int32 AddEngineReplacement(EngineRenewList* erl, EngineID old_engine, EngineID new_engine, uint32 flags) |
|
579 |
{ |
|
580 |
EngineRenew *er; |
|
581 |
||
582 |
// Check if the old vehicle is already in the list |
|
583 |
er = GetEngineReplacement(*erl, old_engine); |
|
584 |
if (er != NULL) { |
|
585 |
if (flags & DC_EXEC) er->to = new_engine; |
|
586 |
return 0; |
|
587 |
} |
|
588 |
||
589 |
er = AllocateEngineRenew(); |
|
590 |
if (er == NULL) return CMD_ERROR; |
|
591 |
||
592 |
if (flags & DC_EXEC) { |
|
593 |
er->from = old_engine; |
|
594 |
er->to = new_engine; |
|
595 |
er->next = (EngineRenew*)(*erl); /* Resolve the first element in the list */ |
|
596 |
||
597 |
*erl = (EngineRenewList)er; /* Insert before the first element */ |
|
598 |
} |
|
599 |
||
600 |
return 0; |
|
601 |
} |
|
602 |
||
603 |
int32 RemoveEngineReplacement(EngineRenewList* erl, EngineID engine, uint32 flags) |
|
604 |
{ |
|
605 |
EngineRenew* er = (EngineRenew*)(*erl); /* Start at the first element */ |
|
606 |
EngineRenew* prev = NULL; |
|
607 |
||
608 |
while (er) |
|
609 |
{ |
|
610 |
if (er->from == engine) { |
|
611 |
if (flags & DC_EXEC) { |
|
612 |
if (prev == NULL) { /* First element */ |
|
613 |
(*erl) = (EngineRenewList)er->next; /* The second becomes the new first element */ |
|
614 |
} else { |
|
615 |
prev->next = er->next; /* Cut this element out */ |
|
616 |
} |
|
617 |
er->from = INVALID_ENGINE; /* Deallocate */ |
|
618 |
} |
|
619 |
return 0; |
|
620 |
} |
|
621 |
prev = er; |
|
622 |
er = er->next; /* Look at next element */ |
|
623 |
} |
|
624 |
||
625 |
return CMD_ERROR; /* Not found? */ |
|
626 |
} |
|
627 |
||
628 |
static const SaveLoad _engine_renew_desc[] = { |
|
629 |
SLE_VAR(EngineRenew, from, SLE_UINT16), |
|
630 |
SLE_VAR(EngineRenew, to, SLE_UINT16), |
|
631 |
||
632 |
SLE_REF(EngineRenew, next, REF_ENGINE_RENEWS), |
|
633 |
||
634 |
SLE_END() |
|
635 |
}; |
|
636 |
||
637 |
static void Save_ERNW(void) |
|
638 |
{ |
|
639 |
EngineRenew *er; |
|
640 |
||
641 |
FOR_ALL_ENGINE_RENEWS(er) { |
|
642 |
if (er->from != INVALID_ENGINE) { |
|
643 |
SlSetArrayIndex(er->index); |
|
644 |
SlObject(er, _engine_renew_desc); |
|
645 |
} |
|
646 |
} |
|
647 |
} |
|
648 |
||
649 |
static void Load_ERNW(void) |
|
650 |
{ |
|
651 |
int index; |
|
652 |
||
653 |
while ((index = SlIterateArray()) != -1) { |
|
654 |
EngineRenew *er; |
|
655 |
||
656 |
if (!AddBlockIfNeeded(&_engine_renew_pool, index)) |
|
657 |
error("EngineRenews: failed loading savegame: too many EngineRenews"); |
|
658 |
||
659 |
er = GetEngineRenew(index); |
|
660 |
SlObject(er, _engine_renew_desc); |
|
661 |
} |
|
662 |
} |
|
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 | 665 |
SLE_VAR(Engine,intro_date, SLE_UINT16), |
666 |
SLE_VAR(Engine,age, SLE_UINT16), |
|
667 |
SLE_VAR(Engine,reliability, SLE_UINT16), |
|
668 |
SLE_VAR(Engine,reliability_spd_dec, SLE_UINT16), |
|
669 |
SLE_VAR(Engine,reliability_start, SLE_UINT16), |
|
670 |
SLE_VAR(Engine,reliability_max, SLE_UINT16), |
|
671 |
SLE_VAR(Engine,reliability_final, SLE_UINT16), |
|
672 |
SLE_VAR(Engine,duration_phase_1, SLE_UINT16), |
|
673 |
SLE_VAR(Engine,duration_phase_2, SLE_UINT16), |
|
674 |
SLE_VAR(Engine,duration_phase_3, SLE_UINT16), |
|
675 |
||
676 |
SLE_VAR(Engine,lifelength, SLE_UINT8), |
|
677 |
SLE_VAR(Engine,flags, SLE_UINT8), |
|
678 |
SLE_VAR(Engine,preview_player, SLE_UINT8), |
|
679 |
SLE_VAR(Engine,preview_wait, SLE_UINT8), |
|
680 |
SLE_VAR(Engine,railtype, SLE_UINT8), |
|
681 |
SLE_VAR(Engine,player_avail, SLE_UINT8), |
|
682 |
||
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 | 685 |
|
686 |
SLE_END() |
|
687 |
}; |
|
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 | 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 | 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 | 696 |
} |
697 |
} |
|
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 | 700 |
{ |
701 |
int index; |
|
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 | 704 |
} |
705 |
} |
|
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 | 708 |
{ |
709 |
SlArray(_engine_name_strings, lengthof(_engine_name_strings), SLE_STRINGID); |
|
710 |
} |
|
711 |
||
712 |
const ChunkHandler _engine_chunk_handlers[] = { |
|
2848 | 713 |
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY }, |
714 |
{ 'ENGS', LoadSave_ENGS, LoadSave_ENGS, CH_RIFF }, |
|
715 |
{ 'ERNW', Save_ERNW, Load_ERNW, CH_ARRAY | CH_LAST}, |
|
0 | 716 |
}; |
717 |
||
2848 | 718 |
void InitializeEngines(void) |
1197 | 719 |
{ |
2848 | 720 |
/* Clean the engine renew pool and create 1 block in it */ |
721 |
CleanPool(&_engine_renew_pool); |
|
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 |
} |