author | Darkvater |
Sat, 14 May 2005 12:36:16 +0000 | |
changeset 1802 | 448f187042d3 |
parent 1786 | a54634efeb98 |
child 1820 | 9b6458526480 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1197
diff
changeset
|
3 |
#include "debug.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
485
diff
changeset
|
4 |
#include "table/strings.h" |
0 | 5 |
#include "engine.h" |
6 |
#include "table/engines.h" |
|
1009
a7ccb8e39cbc
(svn r1508) Remove duplicate declarations and include proper headers where necessary
tron
parents:
964
diff
changeset
|
7 |
#include "gfx.h" |
0 | 8 |
#include "player.h" |
9 |
#include "command.h" |
|
10 |
#include "vehicle.h" |
|
11 |
#include "news.h" |
|
12 |
#include "saveload.h" |
|
405
6830ae7a0d5d
(svn r602) -newgrf: Move DrawTileSeqStruct & co and struct SpriteGroup to sprite.h (pasky)
darkvater
parents:
369
diff
changeset
|
13 |
#include "sprite.h" |
0 | 14 |
|
15 |
#define UPDATE_PLAYER_RAILTYPE(e,p) if ((byte)(e->railtype + 1) > p->max_railtype) p->max_railtype = e->railtype + 1; |
|
16 |
||
17 |
enum { |
|
18 |
ENGINE_AVAILABLE = 1, |
|
19 |
ENGINE_INTRODUCING = 2, |
|
20 |
ENGINE_PREVIEWING = 4, |
|
21 |
}; |
|
22 |
||
1802
448f187042d3
(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
|
23 |
/** TRANSLATE FROM LOCAL CARGO TO GLOBAL CARGO ID'S. |
448f187042d3
(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
|
24 |
* This maps the per-landscape cargo ID's to globally unique cargo ID's usable ie. in |
448f187042d3
(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
|
25 |
* the custom GRF files. It is basically just a transcribed table from TTDPatch's newgrf.txt. |
448f187042d3
(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
|
26 |
*/ |
448f187042d3
(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
|
27 |
const CargoID _global_cargo_id[NUM_LANDSCAPE][NUM_CARGO] = { |
448f187042d3
(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
|
28 |
/* 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}, |
448f187042d3
(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
|
29 |
/* 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 }, |
448f187042d3
(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
|
30 |
/* 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 }, |
448f187042d3
(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
|
31 |
/* 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 }, |
448f187042d3
(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
|
32 |
/** |
448f187042d3
(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 |
* - GC_INVALID (255) means that cargo is not available for that climate |
448f187042d3
(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 |
* - GC_PAPER_TEMP (27) is paper in temperate climate in TTDPatch |
448f187042d3
(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 |
* Following can be renumbered: |
448f187042d3
(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 |
* - GC_DEFAULT (29) is the defa ult cargo for the purpose of spritesets |
448f187042d3
(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 |
* - GC_PURCHASE (30) is the purchase list image (the equivalent of 0xff) for the purpose of spritesets |
448f187042d3
(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 |
*/ |
0 | 39 |
}; |
40 |
||
1802
448f187042d3
(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 |
/** BEGIN --- TRANSLATE FROM GLOBAL CARGO TO LOCAL CARGO ID'S **/ |
448f187042d3
(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 |
/** Map global cargo ID's to local-cargo ID's */ |
448f187042d3
(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 |
const CargoID _local_cargo_id_ctype[NUM_GLOBAL_CID] = { |
448f187042d3
(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 |
CT_PASSENGERS,CT_COAL, CT_MAIL, CT_OIL, CT_LIVESTOCK,CT_GOODS, CT_GRAIN, CT_WOOD, /* 0- 7 */ |
448f187042d3
(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 |
CT_IRON_ORE, CT_STEEL, CT_VALUABLES, CT_PAPER, CT_FOOD, CT_FRUIT, CT_COPPER_ORE, CT_WATER, /* 8-15 */ |
448f187042d3
(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 |
CT_RUBBER, CT_SUGAR, CT_TOYS, CT_BATTERIES,CT_CANDY, CT_TOFFEE, CT_COLA, CT_COTTON_CANDY, /* 16-23 */ |
448f187042d3
(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 |
CT_BUBBLES, CT_PLASTIC,CT_FIZZY_DRINKS,CT_PAPER /* unsup. */,CT_HILLY_UNUSED, /* 24-28 */ |
448f187042d3
(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 |
CT_INVALID, CT_INVALID /* 29-30 */ |
0 | 49 |
}; |
50 |
||
1802
448f187042d3
(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 |
#define MC(cargo) (1 << cargo) |
448f187042d3
(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 |
/** Bitmasked value where the global cargo ID is available in landscape |
448f187042d3
(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 |
* 0: LT_NORMAL, 1: LT_HILLY, 2: LT_DESERT, 3: LT_CANDY */ |
448f187042d3
(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 |
const uint32 _landscape_global_cargo_mask[NUM_LANDSCAPE] = |
448f187042d3
(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 |
{ /* LT_NORMAL: temperate */ |
448f187042d3
(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 |
MC(GC_PASSENGERS)|MC(GC_COAL)|MC(GC_MAIL)|MC(GC_OIL)|MC(GC_LIVESTOCK)|MC(GC_GOODS)|MC(GC_GRAIN)|MC(GC_WOOD)| |
448f187042d3
(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 |
MC(GC_IRON_ORE)|MC(GC_STEEL)|MC(GC_VALUABLES)|MC(GC_FOOD)|MC(GC_UNDEFINED), |
448f187042d3
(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 |
/* LT_HILLY: arctic */ |
448f187042d3
(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
|
59 |
MC(GC_PASSENGERS)|MC(GC_COAL)|MC(GC_MAIL)|MC(GC_OIL)|MC(GC_LIVESTOCK)|MC(GC_GOODS)| |
448f187042d3
(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
|
60 |
MC(GC_GRAIN)|MC(GC_WOOD)|MC(GC_VALUABLES)|MC(GC_PAPER)|MC(GC_FOOD)|MC(GC_UNDEFINED), |
448f187042d3
(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 |
/* LT_DESERT: rainforest/desert */ |
448f187042d3
(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 |
MC(GC_PASSENGERS)|MC(GC_MAIL)|MC(GC_OIL)|MC(GC_GOODS)|MC(GC_GRAIN)|MC(GC_WOOD)| |
448f187042d3
(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 |
MC(GC_VALUABLES)|MC(GC_FOOD)|MC(GC_FRUIT)|MC(GC_COPPER_ORE)|MC(GC_WATER)|MC(GC_RUBBER), |
448f187042d3
(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 |
/* LT_CANDY: toyland */ |
448f187042d3
(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 |
MC(GC_PASSENGERS)|MC(GC_MAIL)|MC(GC_SUGAR)|MC(GC_TOYS)|MC(GC_BATTERIES)|MC(GC_CANDY)| |
448f187042d3
(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_TOFFEE)|MC(GC_COLA)|MC(GC_COTTON_CANDY)|MC(GC_BUBBLES)|MC(GC_PLASTIC)|MC(GC_FIZZY_DRINKS) |
0 | 67 |
}; |
1802
448f187042d3
(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 |
/** END --- TRANSLATE FROM GLOBAL CARGO TO LOCAL CARGO ID'S **/ |
448f187042d3
(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 |
|
448f187042d3
(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
|
70 |
/** Bitmasked values of what type of cargo is refittable for the given vehicle-type. |
448f187042d3
(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 |
* This coupled with the landscape information (_landscape_global_cargo_mask) gives |
448f187042d3
(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 |
* us exactly what is refittable and what is not */ |
448f187042d3
(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 |
const uint32 _default_refitmasks[NUM_VEHICLE_TYPES] = { |
448f187042d3
(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 |
/* Trains */ |
448f187042d3
(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_COAL)|MC(GC_MAIL)|MC(GC_LIVESTOCK)|MC(GC_GOODS)|MC(GC_GRAIN)|MC(GC_WOOD)|MC(GC_IRON_ORE)| |
448f187042d3
(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_STEEL)|MC(GC_VALUABLES)|MC(GC_PAPER)|MC(GC_FOOD)|MC(GC_FRUIT)|MC(GC_COPPER_ORE)|MC(GC_WATER)|MC(GC_SUGAR)| |
448f187042d3
(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
|
77 |
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), |
448f187042d3
(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 |
/* Road vehicles (not refittable by default) */ |
448f187042d3
(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 |
0, |
448f187042d3
(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 |
/* Ships */ |
448f187042d3
(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 |
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)| |
448f187042d3
(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 |
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)| |
448f187042d3
(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 |
MC(GC_CANDY)|MC(GC_TOFFEE)|MC(GC_COLA)|MC(GC_COTTON_CANDY)|MC(GC_BUBBLES)|MC(GC_PLASTIC)|MC(GC_FIZZY_DRINKS), |
448f187042d3
(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 |
/* Aircraft */ |
448f187042d3
(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_MAIL)|MC(GC_GOODS)|MC(GC_VALUABLES)|MC(GC_FOOD)|MC(GC_FRUIT)|MC(GC_SUGAR)|MC(GC_TOYS)| |
448f187042d3
(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_BATTERIES)|MC(GC_CANDY)|MC(GC_TOFFEE)|MC(GC_COLA)|MC(GC_COTTON_CANDY)|MC(GC_BUBBLES)|MC(GC_PLASTIC)|MC(GC_FIZZY_DRINKS), |
448f187042d3
(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 |
/* Special/Disaster */ |
448f187042d3
(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 |
0,0 |
448f187042d3
(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 |
}; |
448f187042d3
(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 |
#undef MC |
0 | 91 |
|
92 |
void ShowEnginePreviewWindow(int engine); |
|
93 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
94 |
void DeleteCustomEngineNames(void) |
0 | 95 |
{ |
96 |
uint i; |
|
97 |
StringID old; |
|
98 |
||
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
99 |
for (i = 0; i != TOTAL_NUM_ENGINES; i++) { |
0 | 100 |
old = _engine_name_strings[i]; |
101 |
_engine_name_strings[i] = i + STR_8000_KIRBY_PAUL_TANK_STEAM; |
|
102 |
DeleteName(old); |
|
103 |
} |
|
104 |
||
105 |
_vehicle_design_names &= ~1; |
|
106 |
} |
|
107 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
108 |
void LoadCustomEngineNames(void) |
0 | 109 |
{ |
110 |
// XXX: not done */ |
|
111 |
DEBUG(misc, 1) ("LoadCustomEngineNames: not done"); |
|
112 |
} |
|
113 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
114 |
static void SetupEngineNames(void) |
0 | 115 |
{ |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
116 |
StringID *name; |
0 | 117 |
|
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
118 |
for (name = _engine_name_strings; name != endof(_engine_name_strings); name++) |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
119 |
*name = STR_SV_EMPTY; |
0 | 120 |
|
121 |
DeleteCustomEngineNames(); |
|
122 |
LoadCustomEngineNames(); |
|
123 |
} |
|
124 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
125 |
static void AdjustAvailAircraft(void) |
0 | 126 |
{ |
127 |
uint16 date = _date; |
|
128 |
byte avail = 0; |
|
129 |
if (date >= 12784) avail |= 2; // big airport |
|
130 |
if (date < 14610 || _patches.always_small_airport) avail |= 1; // small airport |
|
131 |
if (date >= 15706) avail |= 4; // enable heliport |
|
132 |
||
133 |
if (avail != _avail_aircraft) { |
|
134 |
_avail_aircraft = avail; |
|
135 |
InvalidateWindow(WC_BUILD_STATION, 0); |
|
136 |
} |
|
137 |
} |
|
138 |
||
139 |
static void CalcEngineReliability(Engine *e) |
|
140 |
{ |
|
141 |
uint age = e->age; |
|
142 |
||
143 |
if (age < e->duration_phase_1) { |
|
144 |
uint start = e->reliability_start; |
|
145 |
e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start; |
|
146 |
} else if ((age -= e->duration_phase_1) < e->duration_phase_2) { |
|
147 |
e->reliability = e->reliability_max; |
|
148 |
} else if ((age -= e->duration_phase_2) < e->duration_phase_3) { |
|
149 |
uint max = e->reliability_max; |
|
150 |
e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max; |
|
151 |
} else { |
|
292
9b0a6d544593
(svn r298) Fix: Engines from other climates do not appear any more when never_expire_vehicles is enabled
dominik
parents:
257
diff
changeset
|
152 |
// time's up for this engine |
9b0a6d544593
(svn r298) Fix: Engines from other climates do not appear any more when never_expire_vehicles is enabled
dominik
parents:
257
diff
changeset
|
153 |
// make it either available to all players (if never_expire_vehicles is enabled and if it was available earlier) |
9b0a6d544593
(svn r298) Fix: Engines from other climates do not appear any more when never_expire_vehicles is enabled
dominik
parents:
257
diff
changeset
|
154 |
// or disable this engine completely |
9b0a6d544593
(svn r298) Fix: Engines from other climates do not appear any more when never_expire_vehicles is enabled
dominik
parents:
257
diff
changeset
|
155 |
e->player_avail = (_patches.never_expire_vehicles && e->player_avail)? -1 : 0; |
0 | 156 |
e->reliability = e->reliability_final; |
157 |
} |
|
158 |
} |
|
159 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
160 |
void AddTypeToEngines(void) |
842 | 161 |
{ |
162 |
Engine *e; |
|
163 |
uint32 counter = 0; |
|
915 | 164 |
|
842 | 165 |
for(e=_engines; e != endof(_engines); e++, counter++) { |
166 |
||
167 |
e->type = VEH_Train; |
|
168 |
if (counter >= ROAD_ENGINES_INDEX) { |
|
169 |
e->type = VEH_Road; |
|
170 |
if (counter >= SHIP_ENGINES_INDEX) { |
|
171 |
e->type = VEH_Ship; |
|
172 |
if (counter >= AIRCRAFT_ENGINES_INDEX) { |
|
173 |
e->type = VEH_Aircraft; |
|
174 |
if (counter >= TOTAL_NUM_ENGINES) { |
|
175 |
e->type = VEH_Special; |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
} |
|
180 |
} |
|
181 |
} |
|
182 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
183 |
void StartupEngines(void) |
0 | 184 |
{ |
185 |
Engine *e; |
|
186 |
const EngineInfo *ei; |
|
819
02e9296ccdca
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
187 |
uint32 r, counter = 0; |
0 | 188 |
|
189 |
SetupEngineNames(); |
|
190 |
||
842 | 191 |
for(e=_engines, ei=_engine_info; e != endof(_engines); e++, ei++, counter++) { |
0 | 192 |
|
193 |
e->age = 0; |
|
194 |
e->railtype = ei->railtype_climates >> 4; |
|
195 |
e->flags = 0; |
|
196 |
e->player_avail = 0; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
197 |
|
0 | 198 |
r = Random(); |
199 |
e->intro_date = (uint16)((r & 0x1FF) + ei->base_intro); |
|
200 |
if (e->intro_date <= _date) { |
|
201 |
e->age = (_date - e->intro_date) >> 5; |
|
202 |
e->player_avail = (byte)-1; |
|
203 |
e->flags |= ENGINE_AVAILABLE; |
|
204 |
} |
|
205 |
||
206 |
e->reliability_start = (uint16)(((r >> 16) & 0x3fff) + 0x7AE0); |
|
207 |
r = Random(); |
|
208 |
e->reliability_max = (uint16)((r & 0x3fff) + 0xbfff); |
|
209 |
e->reliability_final = (uint16)(((r>>16) & 0x3fff) + 0x3fff); |
|
210 |
||
211 |
r = Random(); |
|
212 |
e->duration_phase_1 = (uint16)((r & 0x1F) + 7); |
|
213 |
e->duration_phase_2 = (uint16)(((r >> 5) & 0xF) + ei->base_life * 12 - 96); |
|
214 |
e->duration_phase_3 = (uint16)(((r >> 9) & 0x7F) + 120); |
|
215 |
||
216 |
e->reliability_spd_dec = (ei->unk2&0x7F) << 2; |
|
217 |
||
218 |
/* my invented flag for something that is a wagon */ |
|
219 |
if (ei->unk2 & 0x80) { |
|
220 |
e->age = 0xFFFF; |
|
221 |
} else { |
|
222 |
CalcEngineReliability(e); |
|
223 |
} |
|
224 |
||
225 |
e->lifelength = ei->lifelength + _patches.extend_vehicle_life; |
|
226 |
||
227 |
// prevent certain engines from ever appearing. |
|
228 |
if (!HASBIT(ei->railtype_climates, _opt.landscape)) { |
|
229 |
e->flags |= ENGINE_AVAILABLE; |
|
230 |
e->player_avail = 0; |
|
231 |
} |
|
915 | 232 |
|
819
02e9296ccdca
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
233 |
/* This sets up type for the engine |
02e9296ccdca
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
234 |
It is needed if you want to ask the engine what type it is |
02e9296ccdca
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
235 |
It should hopefully be the same as when you ask a vehicle what it is |
02e9296ccdca
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
236 |
but using this, you can ask what type an engine number is |
02e9296ccdca
(svn r1290) Added type to typedef struct Engine and filled in the same data as in type in vehicle
bjarni
parents:
740
diff
changeset
|
237 |
even if it is not a vehicle (yet)*/ |
0 | 238 |
} |
239 |
||
240 |
AdjustAvailAircraft(); |
|
241 |
} |
|
242 |
||
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
243 |
uint32 _engine_refit_masks[TOTAL_NUM_ENGINES]; |
0 | 244 |
|
245 |
||
246 |
// TODO: We don't support cargo-specific wagon overrides. Pretty exotic... ;-) --pasky |
|
247 |
||
1477 | 248 |
typedef struct WagonOverride { |
0 | 249 |
byte *train_id; |
250 |
int trains; |
|
1477 | 251 |
SpriteGroup group; |
252 |
} WagonOverride; |
|
0 | 253 |
|
1477 | 254 |
typedef struct WagonOverrides { |
0 | 255 |
int overrides_count; |
1477 | 256 |
WagonOverride *overrides; |
257 |
} WagonOverrides; |
|
0 | 258 |
|
1477 | 259 |
static WagonOverrides _engine_wagon_overrides[TOTAL_NUM_ENGINES]; |
260 |
||
261 |
void SetWagonOverrideSprites(byte engine, SpriteGroup *group, byte *train_id, |
|
262 |
int trains) |
|
0 | 263 |
{ |
1477 | 264 |
WagonOverrides *wos; |
265 |
WagonOverride *wo; |
|
0 | 266 |
|
267 |
wos = &_engine_wagon_overrides[engine]; |
|
268 |
wos->overrides_count++; |
|
269 |
wos->overrides = realloc(wos->overrides, |
|
1477 | 270 |
wos->overrides_count * sizeof(*wos->overrides)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
271 |
|
0 | 272 |
wo = &wos->overrides[wos->overrides_count - 1]; |
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
273 |
/* FIXME: If we are replacing an override, release original SpriteGroup |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
274 |
* to prevent leaks. But first we need to refcount the SpriteGroup. |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
275 |
* --pasky */ |
369
ab2266938fa8
(svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents:
292
diff
changeset
|
276 |
wo->group = *group; |
0 | 277 |
wo->trains = trains; |
278 |
wo->train_id = malloc(trains); |
|
279 |
memcpy(wo->train_id, train_id, trains); |
|
280 |
} |
|
281 |
||
1477 | 282 |
static SpriteGroup *GetWagonOverrideSpriteSet(byte engine, byte overriding_engine) |
0 | 283 |
{ |
1477 | 284 |
WagonOverrides *wos = &_engine_wagon_overrides[engine]; |
0 | 285 |
int i; |
286 |
||
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
287 |
// XXX: This could turn out to be a timesink on profiles. We could |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
288 |
// always just dedicate 65535 bytes for an [engine][train] trampoline |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
289 |
// for O(1). Or O(logMlogN) and searching binary tree or smt. like |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
290 |
// that. --pasky |
0 | 291 |
|
292 |
for (i = 0; i < wos->overrides_count; i++) { |
|
1477 | 293 |
WagonOverride *wo = &wos->overrides[i]; |
0 | 294 |
int j; |
295 |
||
296 |
for (j = 0; j < wo->trains; j++) { |
|
297 |
if (wo->train_id[j] == overriding_engine) |
|
369
ab2266938fa8
(svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents:
292
diff
changeset
|
298 |
return &wo->group; |
0 | 299 |
} |
300 |
} |
|
301 |
return NULL; |
|
302 |
} |
|
303 |
||
304 |
||
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
305 |
byte _engine_original_sprites[TOTAL_NUM_ENGINES]; |
0 | 306 |
// 0 - 28 are cargos, 29 is default, 30 is the advert (purchase list) |
307 |
// (It isn't and shouldn't be like this in the GRF files since new cargo types |
|
308 |
// may appear in future - however it's more convenient to store it like this in |
|
309 |
// memory. --pasky) |
|
1802
448f187042d3
(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
|
310 |
static SpriteGroup _engine_custom_sprites[TOTAL_NUM_ENGINES][NUM_GLOBAL_CID]; |
0 | 311 |
|
1477 | 312 |
void SetCustomEngineSprites(byte engine, byte cargo, SpriteGroup *group) |
0 | 313 |
{ |
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
314 |
/* FIXME: If we are replacing an override, release original SpriteGroup |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
315 |
* to prevent leaks. But first we need to refcount the SpriteGroup. |
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
316 |
* --pasky */ |
369
ab2266938fa8
(svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents:
292
diff
changeset
|
317 |
_engine_custom_sprites[engine][cargo] = *group; |
0 | 318 |
} |
319 |
||
1477 | 320 |
typedef RealSpriteGroup *(*resolve_callback)(SpriteGroup *spritegroup, |
321 |
const Vehicle *veh, void *callback); /* XXX data pointer used as function pointer */ |
|
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
322 |
|
1477 | 323 |
static RealSpriteGroup* ResolveVehicleSpriteGroup(SpriteGroup *spritegroup, |
324 |
const Vehicle *veh, resolve_callback callback) |
|
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
325 |
{ |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
326 |
//debug("spgt %d", spritegroup->type); |
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
327 |
switch (spritegroup->type) { |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
328 |
case SGT_REAL: |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
329 |
return &spritegroup->g.real; |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
330 |
|
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
331 |
case SGT_DETERMINISTIC: { |
1477 | 332 |
DeterministicSpriteGroup *dsg = &spritegroup->g.determ; |
333 |
SpriteGroup *target; |
|
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
334 |
int value = -1; |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
335 |
|
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
336 |
//debug("[%p] Having fun resolving variable %x", veh, dsg->variable); |
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
337 |
|
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
338 |
if ((dsg->variable >> 6) == 0) { |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
339 |
/* General property */ |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
340 |
value = GetDeterministicSpriteValue(dsg->variable); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
341 |
} else { |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
342 |
/* Vehicle-specific property. */ |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
343 |
|
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
344 |
if (veh == NULL) { |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
345 |
/* We are in a purchase list of something, |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
346 |
* and we are checking for something undefined. |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
347 |
* That means we should get the first target |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
348 |
* (NOT the default one). */ |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
349 |
if (dsg->num_ranges > 0) { |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
350 |
target = &dsg->ranges[0].group; |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
351 |
} else { |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
352 |
target = dsg->default_group; |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
353 |
} |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
354 |
return callback(target, NULL, callback); |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
355 |
} |
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
356 |
|
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
357 |
if (dsg->var_scope == VSG_SCOPE_PARENT) { |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
358 |
/* First engine in the vehicle chain */ |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
359 |
if (veh->type == VEH_Train) |
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
360 |
veh = GetFirstVehicleInChain(veh); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
361 |
} |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
362 |
|
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
363 |
if (dsg->variable == 0x40) { |
433
00c1c7a58672
(svn r635) Fix choosing a spritegroup from deterministic variational spritegroups if there is no structure to search (i.e. in purchase lists) (pasky)
tron
parents:
426
diff
changeset
|
364 |
if (veh->type == VEH_Train) { |
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
365 |
Vehicle *u = GetFirstVehicleInChain(veh); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
366 |
byte chain_before = 0, chain_after = 0; |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
367 |
|
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
368 |
while (u != veh) { |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
369 |
u = u->next; |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
370 |
chain_before++; |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
371 |
} |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
372 |
while (u->next != NULL) { |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
373 |
u = u->next; |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
374 |
chain_after++; |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
375 |
}; |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
376 |
|
1559
616d0c6c5f3d
(svn r2063) Fix: the 0x40 deterministic spritegroup for vehicles was wrong, modified to match the wiki again. (The wiki was partially wrong, too! ;) (Patch by HackyKid.)
pasky
parents:
1539
diff
changeset
|
377 |
value = chain_before | chain_after << 8 |
616d0c6c5f3d
(svn r2063) Fix: the 0x40 deterministic spritegroup for vehicles was wrong, modified to match the wiki again. (The wiki was partially wrong, too! ;) (Patch by HackyKid.)
pasky
parents:
1539
diff
changeset
|
378 |
| (chain_before + chain_after) << 16; |
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
379 |
} else { |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
380 |
value = 1; /* 1 vehicle in the chain */ |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
381 |
} |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
382 |
|
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
383 |
} else { |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
384 |
// TTDPatch runs on little-endian arch; |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
385 |
// Variable is 0x80 + offset in TTD's vehicle structure |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
386 |
switch (dsg->variable - 0x80) { |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
387 |
#define veh_prop(id_, value_) case (id_): value = (value_); break |
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
388 |
veh_prop(0x00, veh->type); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
389 |
veh_prop(0x01, veh->subtype); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
390 |
veh_prop(0x04, veh->index); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
391 |
veh_prop(0x05, veh->index & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
392 |
/* XXX? Is THIS right? */ |
555
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
393 |
veh_prop(0x0A, PackOrder(&veh->current_order)); |
eec6c0294435
(svn r955) Replace uint16 for orders with struct Order
tron
parents:
543
diff
changeset
|
394 |
veh_prop(0x0B, PackOrder(&veh->current_order) & 0xff); |
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
395 |
veh_prop(0x0C, veh->num_orders); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
396 |
veh_prop(0x0D, veh->cur_order_index); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
397 |
veh_prop(0x10, veh->load_unload_time_rem); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
398 |
veh_prop(0x11, veh->load_unload_time_rem & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
399 |
veh_prop(0x12, veh->date_of_last_service); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
400 |
veh_prop(0x13, veh->date_of_last_service & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
401 |
veh_prop(0x14, veh->service_interval); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
402 |
veh_prop(0x15, veh->service_interval & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
403 |
veh_prop(0x16, veh->last_station_visited); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
404 |
veh_prop(0x17, veh->tick_counter); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
405 |
veh_prop(0x18, veh->max_speed); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
406 |
veh_prop(0x19, veh->max_speed & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
407 |
veh_prop(0x1F, veh->direction); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
408 |
veh_prop(0x28, veh->cur_image); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
409 |
veh_prop(0x29, veh->cur_image & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
410 |
veh_prop(0x32, veh->vehstatus); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
411 |
veh_prop(0x33, veh->vehstatus); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
412 |
veh_prop(0x34, veh->cur_speed); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
413 |
veh_prop(0x35, veh->cur_speed & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
414 |
veh_prop(0x36, veh->subspeed); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
415 |
veh_prop(0x37, veh->acceleration); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
416 |
veh_prop(0x39, veh->cargo_type); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
417 |
veh_prop(0x3A, veh->cargo_cap); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
418 |
veh_prop(0x3B, veh->cargo_cap & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
419 |
veh_prop(0x3C, veh->cargo_count); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
420 |
veh_prop(0x3D, veh->cargo_count & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
421 |
veh_prop(0x3E, veh->cargo_source); // Probably useless; so what |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
422 |
veh_prop(0x3F, veh->cargo_days); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
423 |
veh_prop(0x40, veh->age); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
424 |
veh_prop(0x41, veh->age & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
425 |
veh_prop(0x42, veh->max_age); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
426 |
veh_prop(0x43, veh->max_age & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
427 |
veh_prop(0x44, veh->build_year); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
428 |
veh_prop(0x45, veh->unitnumber); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
429 |
veh_prop(0x46, veh->engine_type); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
430 |
veh_prop(0x47, veh->engine_type & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
431 |
veh_prop(0x48, veh->spritenum); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
432 |
veh_prop(0x49, veh->day_counter); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
433 |
veh_prop(0x4A, veh->breakdowns_since_last_service); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
434 |
veh_prop(0x4B, veh->breakdown_ctr); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
435 |
veh_prop(0x4C, veh->breakdown_delay); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
436 |
veh_prop(0x4D, veh->breakdown_chance); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
437 |
veh_prop(0x4E, veh->reliability); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
438 |
veh_prop(0x4F, veh->reliability & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
439 |
veh_prop(0x50, veh->reliability_spd_dec); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
440 |
veh_prop(0x51, veh->reliability_spd_dec & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
441 |
veh_prop(0x52, veh->profit_this_year); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
442 |
veh_prop(0x53, veh->profit_this_year & 0xFFFFFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
443 |
veh_prop(0x54, veh->profit_this_year & 0xFFFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
444 |
veh_prop(0x55, veh->profit_this_year & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
445 |
veh_prop(0x56, veh->profit_last_year); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
446 |
veh_prop(0x57, veh->profit_last_year & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
447 |
veh_prop(0x58, veh->profit_last_year); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
448 |
veh_prop(0x59, veh->profit_last_year & 0xFF); |
938
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
919
diff
changeset
|
449 |
/* veh_prop(0x5A, veh->next_in_chain_old); |
4f84a0530758
(svn r1426) -Codechange: cleaned up the reference code in the saveload routines
truelight
parents:
919
diff
changeset
|
450 |
veh_prop(0x5B, veh->next_in_chain_old & 0xFF);*/ |
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
451 |
veh_prop(0x5C, veh->value); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
452 |
veh_prop(0x5D, veh->value & 0xFFFFFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
453 |
veh_prop(0x5E, veh->value & 0xFFFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
454 |
veh_prop(0x5F, veh->value & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
455 |
veh_prop(0x60, veh->string_id); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
456 |
veh_prop(0x61, veh->string_id & 0xFF); |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
457 |
/* 00h..07h=sub image? 40h=in tunnel; actually some kind of status |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
458 |
* aircraft: >=13h when in flight |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
459 |
* train, ship: 80h=in depot |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
460 |
* rv: 0feh=in depot */ |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
461 |
/* TODO veh_prop(0x62, veh->???); */ |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
462 |
|
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
463 |
/* TODO: The rest is per-vehicle, I hope no GRF file looks so far. |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
464 |
* But they won't let us have an easy ride so surely *some* GRF |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
465 |
* file does. So someone needs to do this too. --pasky */ |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
466 |
|
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
467 |
#undef veh_prop |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
468 |
} |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
469 |
} |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
470 |
} |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
471 |
|
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
472 |
target = value != -1 ? EvalDeterministicSpriteGroup(dsg, value) : dsg->default_group; |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
473 |
//debug("Resolved variable %x: %d, %p", dsg->variable, value, callback); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
474 |
return callback(target, veh, callback); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
475 |
} |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
476 |
|
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
477 |
case SGT_RANDOMIZED: { |
1477 | 478 |
RandomizedSpriteGroup *rsg = &spritegroup->g.random; |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
479 |
|
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
480 |
if (veh == NULL) { |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
481 |
/* Purchase list of something. Show the first one. */ |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
482 |
assert(rsg->num_groups > 0); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
483 |
//debug("going for %p: %d", rsg->groups[0], rsg->groups[0].type); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
484 |
return callback(&rsg->groups[0], NULL, callback); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
485 |
} |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
486 |
|
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
487 |
if (rsg->var_scope == VSG_SCOPE_PARENT) { |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
488 |
/* First engine in the vehicle chain */ |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
489 |
if (veh->type == VEH_Train) |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
490 |
veh = GetFirstVehicleInChain(veh); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
491 |
} |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
492 |
|
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
493 |
return callback(EvalRandomizedSpriteGroup(rsg, veh->random_bits), veh, callback); |
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
494 |
} |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
495 |
|
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
496 |
default: |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
497 |
error("I don't know how to handle such a spritegroup %d!", spritegroup->type); |
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
498 |
return NULL; |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
499 |
} |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
500 |
} |
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
501 |
|
1477 | 502 |
static SpriteGroup *GetVehicleSpriteGroup(byte engine, const Vehicle *v) |
0 | 503 |
{ |
1477 | 504 |
SpriteGroup *group; |
1802
448f187042d3
(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
|
505 |
byte cargo = GC_PURCHASE; |
0 | 506 |
|
414
e18cc252e2ea
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
507 |
if (v != NULL) { |
e18cc252e2ea
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
508 |
cargo = _global_cargo_id[_opt.landscape][v->cargo_type]; |
1802
448f187042d3
(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
|
509 |
assert(cargo != GC_INVALID); |
414
e18cc252e2ea
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
510 |
} |
e18cc252e2ea
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
511 |
|
e18cc252e2ea
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
512 |
group = &_engine_custom_sprites[engine][cargo]; |
e18cc252e2ea
(svn r611) -newgrf: Change GetCustomEngineSprite() calling convention (invisible to users of GetCustomVehicle*() wrappers). Needed for deterministic spritegroups support (pasky).
darkvater
parents:
410
diff
changeset
|
513 |
|
1560
50acca78ff8d
(svn r2064) - Codechange: GetVehicleSpriteGroup() cleanup - drop overriding_engine, which was around probably only for historical reasons. (Paralellily developed by HackyKid.)
pasky
parents:
1559
diff
changeset
|
514 |
if (v != NULL && v->type == VEH_Train) { |
50acca78ff8d
(svn r2064) - Codechange: GetVehicleSpriteGroup() cleanup - drop overriding_engine, which was around probably only for historical reasons. (Paralellily developed by HackyKid.)
pasky
parents:
1559
diff
changeset
|
515 |
SpriteGroup *overset = GetWagonOverrideSpriteSet(engine, v->u.rail.first_engine); |
0 | 516 |
|
1477 | 517 |
if (overset != NULL) group = overset; |
0 | 518 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
519 |
|
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
520 |
return group; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
521 |
} |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
522 |
|
1475 | 523 |
int GetCustomEngineSprite(byte engine, const Vehicle *v, byte direction) |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
524 |
{ |
1477 | 525 |
SpriteGroup *group; |
526 |
RealSpriteGroup *rsg; |
|
1802
448f187042d3
(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
|
527 |
byte cargo = GC_PURCHASE; |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
528 |
byte loaded = 0; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
529 |
bool in_motion = 0; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
530 |
int totalsets, spriteset; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
531 |
int r; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
532 |
|
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
533 |
if (v != NULL) { |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
534 |
int capacity = v->cargo_cap; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
535 |
|
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
536 |
cargo = _global_cargo_id[_opt.landscape][v->cargo_type]; |
1802
448f187042d3
(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
|
537 |
assert(cargo != GC_INVALID); |
448f187042d3
(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
|
538 |
|
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
539 |
if (capacity == 0) capacity = 1; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
540 |
loaded = (v->cargo_count * 100) / capacity; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
541 |
in_motion = (v->cur_speed != 0); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
542 |
} |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
543 |
|
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
544 |
group = GetVehicleSpriteGroup(engine, v); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
545 |
rsg = ResolveVehicleSpriteGroup(group, v, (resolve_callback) ResolveVehicleSpriteGroup); |
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
546 |
|
426
bd6f3c2cad9f
(svn r625) Almost complete support for deterministic variational vehicle spritegroups. (pasky)
tron
parents:
414
diff
changeset
|
547 |
if (rsg->sprites_per_set == 0 && cargo != 29) { /* XXX magic number */ |
369
ab2266938fa8
(svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents:
292
diff
changeset
|
548 |
// This group is empty but perhaps there'll be a default one. |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
549 |
rsg = ResolveVehicleSpriteGroup(&_engine_custom_sprites[engine][29], v, |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
550 |
(resolve_callback) ResolveVehicleSpriteGroup); |
0 | 551 |
} |
552 |
||
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
553 |
if (!rsg->sprites_per_set) { |
369
ab2266938fa8
(svn r557) -newgrf: Rename all 'superset' tokens to 'group' and some other small renamings (pasky and octo).
darkvater
parents:
292
diff
changeset
|
554 |
// This group is empty. This function users should therefore |
0 | 555 |
// look up the sprite number in _engine_original_sprites. |
556 |
return 0; |
|
557 |
} |
|
558 |
||
559 |
direction %= 8; |
|
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
560 |
if (rsg->sprites_per_set == 4) |
0 | 561 |
direction %= 4; |
562 |
||
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
563 |
totalsets = in_motion ? rsg->loaded_count : rsg->loading_count; |
0 | 564 |
|
565 |
// My aim here is to make it possible to visually determine absolutely |
|
566 |
// empty and totally full vehicles. --pasky |
|
567 |
if (loaded == 100 || totalsets == 1) { // full |
|
568 |
spriteset = totalsets - 1; |
|
569 |
} else if (loaded == 0 || totalsets == 2) { // empty |
|
570 |
spriteset = 0; |
|
571 |
} else { // something inbetween |
|
572 |
spriteset = loaded * (totalsets - 2) / 100 + 1; |
|
573 |
// correct possible rounding errors |
|
574 |
if (!spriteset) |
|
575 |
spriteset = 1; |
|
576 |
else if (spriteset == totalsets - 1) |
|
577 |
spriteset--; |
|
578 |
} |
|
579 |
||
408
63a8c0505aab
(svn r605) -newgrf: Framework for supporting variational spritegroups . Deterministic only at the moment, but random ones support shouldn't be that difficult now It doesn't do anything, but makes these actions actually possible (pasky).
darkvater
parents:
405
diff
changeset
|
580 |
r = (in_motion ? rsg->loaded[spriteset] : rsg->loading[spriteset]) + direction; |
0 | 581 |
return r; |
582 |
} |
|
583 |
||
584 |
||
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
585 |
// Global variables are evil, yes, but we would end up with horribly overblown |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
586 |
// calling convention otherwise and this should be 100% reentrant. |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
587 |
static byte _vsg_random_triggers; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
588 |
static byte _vsg_bits_to_reseed; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
589 |
|
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
590 |
extern int _custom_sprites_base; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
591 |
|
1477 | 592 |
static RealSpriteGroup *TriggerVehicleSpriteGroup(SpriteGroup *spritegroup, |
593 |
Vehicle *veh, resolve_callback callback) |
|
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
594 |
{ |
1477 | 595 |
if (spritegroup->type == SGT_RANDOMIZED) { |
596 |
_vsg_bits_to_reseed |= RandomizedSpriteGroupTriggeredBits( |
|
597 |
&spritegroup->g.random, |
|
598 |
_vsg_random_triggers, |
|
599 |
&veh->waiting_triggers |
|
600 |
); |
|
601 |
} |
|
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
602 |
|
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
603 |
return ResolveVehicleSpriteGroup(spritegroup, veh, callback); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
604 |
} |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
605 |
|
1477 | 606 |
static void DoTriggerVehicle(Vehicle *veh, VehicleTrigger trigger, byte base_random_bits, bool first) |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
607 |
{ |
1477 | 608 |
RealSpriteGroup *rsg; |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
609 |
byte new_random_bits; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
610 |
|
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
611 |
_vsg_random_triggers = trigger; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
612 |
_vsg_bits_to_reseed = 0; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
613 |
rsg = TriggerVehicleSpriteGroup(GetVehicleSpriteGroup(veh->engine_type, veh), veh, |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
614 |
(resolve_callback) TriggerVehicleSpriteGroup); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
615 |
if (rsg->sprites_per_set == 0 && veh->cargo_type != 29) { /* XXX magic number */ |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
616 |
// This group turned out to be empty but perhaps there'll be a default one. |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
617 |
rsg = TriggerVehicleSpriteGroup(&_engine_custom_sprites[veh->engine_type][29], veh, |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
618 |
(resolve_callback) TriggerVehicleSpriteGroup); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
619 |
} |
542 | 620 |
new_random_bits = Random(); |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
621 |
veh->random_bits &= ~_vsg_bits_to_reseed; |
542 | 622 |
veh->random_bits |= (first ? new_random_bits : base_random_bits) & _vsg_bits_to_reseed; |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
623 |
|
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
624 |
switch (trigger) { |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
625 |
case VEHICLE_TRIGGER_NEW_CARGO: |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
626 |
/* All vehicles in chain get ANY_NEW_CARGO trigger now. |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
627 |
* So we call it for the first one and they will recurse. */ |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
628 |
/* Indexing part of vehicle random bits needs to be |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
629 |
* same for all triggered vehicles in the chain (to get |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
630 |
* all the random-cargo wagons carry the same cargo, |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
631 |
* i.e.), so we give them all the NEW_CARGO triggered |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
632 |
* vehicle's portion of random bits. */ |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
633 |
assert(first); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
634 |
DoTriggerVehicle(GetFirstVehicleInChain(veh), VEHICLE_TRIGGER_ANY_NEW_CARGO, new_random_bits, false); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
635 |
break; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
636 |
case VEHICLE_TRIGGER_DEPOT: |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
637 |
/* We now trigger the next vehicle in chain recursively. |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
638 |
* The random bits portions may be different for each |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
639 |
* vehicle in chain. */ |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
640 |
if (veh->next != NULL) |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
641 |
DoTriggerVehicle(veh->next, trigger, 0, true); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
642 |
break; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
643 |
case VEHICLE_TRIGGER_EMPTY: |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
644 |
/* We now trigger the next vehicle in chain |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
645 |
* recursively. The random bits portions must be same |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
646 |
* for each vehicle in chain, so we give them all |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
647 |
* first chained vehicle's portion of random bits. */ |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
648 |
if (veh->next != NULL) |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
649 |
DoTriggerVehicle(veh->next, trigger, first ? new_random_bits : base_random_bits, false); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
650 |
break; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
651 |
case VEHICLE_TRIGGER_ANY_NEW_CARGO: |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
652 |
/* Now pass the trigger recursively to the next vehicle |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
653 |
* in chain. */ |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
654 |
assert(!first); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
655 |
if (veh->next != NULL) |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
656 |
DoTriggerVehicle(veh->next, VEHICLE_TRIGGER_ANY_NEW_CARGO, base_random_bits, false); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
657 |
break; |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
658 |
} |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
659 |
} |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
660 |
|
1477 | 661 |
void TriggerVehicle(Vehicle *veh, VehicleTrigger trigger) |
445
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
662 |
{ |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
663 |
DoTriggerVehicle(veh, trigger, 0, true); |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
664 |
} |
0e3fa3da3899
(svn r654) Hopefully complete support for randomized variational spritegroups (i.e. the cars transporter in DBSetXL gets different cars each time) (pasky)
tron
parents:
433
diff
changeset
|
665 |
|
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
666 |
static char *_engine_custom_names[TOTAL_NUM_ENGINES]; |
0 | 667 |
|
1329 | 668 |
void SetCustomEngineName(int engine, const char *name) |
0 | 669 |
{ |
670 |
_engine_custom_names[engine] = strdup(name); |
|
671 |
} |
|
672 |
||
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
673 |
void UnInitNewgrEngines(void) |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
674 |
{ |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
675 |
char **i; |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
676 |
for (i = _engine_custom_names; i != endof(_engine_custom_names); i++) { |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
677 |
free(*i); |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
678 |
*i = NULL; |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
679 |
} |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
680 |
} |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1329
diff
changeset
|
681 |
|
0 | 682 |
StringID GetCustomEngineName(int engine) |
683 |
{ |
|
684 |
if (!_engine_custom_names[engine]) |
|
685 |
return _engine_name_strings[engine]; |
|
485
453c096beb1b
(svn r767) Introduce USERSTRING_LEN (128) and try to make sure we don't overflow it anywhere (as long as we keep USERSTRING_LEN above 7 or so).
pasky
parents:
445
diff
changeset
|
686 |
strncpy(_userstring, _engine_custom_names[engine], USERSTRING_LEN); |
453c096beb1b
(svn r767) Introduce USERSTRING_LEN (128) and try to make sure we don't overflow it anywhere (as long as we keep USERSTRING_LEN above 7 or so).
pasky
parents:
445
diff
changeset
|
687 |
_userstring[USERSTRING_LEN - 1] = '\0'; |
0 | 688 |
return STR_SPEC_USERSTRING; |
689 |
} |
|
690 |
||
691 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
692 |
void AcceptEnginePreview(Engine *e, PlayerID player) |
0 | 693 |
{ |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
694 |
Player *p = DEREF_PLAYER(player); |
0 | 695 |
|
696 |
SETBIT(e->player_avail, player); |
|
697 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
698 |
UPDATE_PLAYER_RAILTYPE(e, p); |
0 | 699 |
|
700 |
e->preview_player = 0xFF; |
|
701 |
InvalidateWindowClasses(WC_BUILD_VEHICLE); |
|
1096
ce698f7e4621
(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
|
702 |
InvalidateWindowClasses(WC_REPLACE_VEHICLE); |
0 | 703 |
} |
704 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
705 |
static PlayerID GetBestPlayer(PlayerID pp) |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
706 |
{ |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
707 |
const Player *p; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
708 |
int32 best_hist; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
709 |
PlayerID best_player; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
710 |
uint mask = 0; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
711 |
|
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
712 |
do { |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
713 |
best_hist = -1; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
714 |
best_player = -1; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
715 |
FOR_ALL_PLAYERS(p) { |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
716 |
if (p->is_active && p->block_preview == 0 && !HASBIT(mask, p->index) && |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
717 |
p->old_economy[0].performance_history > best_hist) { |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
718 |
best_hist = p->old_economy[0].performance_history; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
719 |
best_player = p->index; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
720 |
} |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
721 |
} |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
722 |
|
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
723 |
if (best_player == (PlayerID)-1) return -1; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
724 |
|
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
725 |
SETBIT(mask, best_player); |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
726 |
} while (--pp != 0); |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
727 |
|
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
728 |
return best_player; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
729 |
} |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
730 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
731 |
void EnginesDailyLoop(void) |
0 | 732 |
{ |
733 |
Engine *e; |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
734 |
int i; |
0 | 735 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
736 |
if (_cur_year >= 130) return; |
0 | 737 |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
738 |
for (e = _engines, i = 0; i != TOTAL_NUM_ENGINES; e++, i++) { |
0 | 739 |
if (e->flags & ENGINE_INTRODUCING) { |
740 |
if (e->flags & ENGINE_PREVIEWING) { |
|
740
c1d06749846b
(svn r1196) -Fix: Preview Vehicle had a small glitch. Fixed now.
truelight
parents:
555
diff
changeset
|
741 |
if (e->preview_player != 0xFF && !--e->preview_wait) { |
0 | 742 |
e->flags &= ~ENGINE_PREVIEWING; |
743 |
DeleteWindowById(WC_ENGINE_PREVIEW, i); |
|
744 |
e->preview_player++; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
745 |
} |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
746 |
} else if (e->preview_player != 0xFF) { |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
747 |
PlayerID best_player = GetBestPlayer(e->preview_player); |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
748 |
|
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
749 |
if (best_player == (PlayerID)-1) { |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
750 |
e->preview_player = 0xFF; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
751 |
continue; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
752 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
753 |
|
0 | 754 |
if (!IS_HUMAN_PLAYER(best_player)) { |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
755 |
/* XXX - TTDBUG: TTD has a bug here ???? */ |
0 | 756 |
AcceptEnginePreview(e, best_player); |
757 |
} else { |
|
758 |
e->flags |= ENGINE_PREVIEWING; |
|
759 |
e->preview_wait = 20; |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
760 |
if (IS_INTERACTIVE_PLAYER(best_player)) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
761 |
ShowEnginePreviewWindow(i); |
0 | 762 |
} |
763 |
} |
|
764 |
} |
|
765 |
} |
|
766 |
} |
|
767 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
768 |
/** Accept an engine prototype. XXX - it is possible that the top-player |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
769 |
* changes while you are waiting to accept the offer? Then it becomes invalid |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
770 |
* @param x,y unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
771 |
* @param p1 engine-prototype offered |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
772 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
773 |
*/ |
0 | 774 |
int32 CmdWantEnginePreview(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
775 |
{ |
|
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
776 |
Engine *e; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
777 |
if (!IsEngineIndex(p1)) return CMD_ERROR; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
778 |
|
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
779 |
e = DEREF_ENGINE(p1); |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
780 |
if (GetBestPlayer(e->preview_player) != _current_player) return CMD_ERROR; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
781 |
|
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
782 |
if (flags & DC_EXEC) |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
783 |
AcceptEnginePreview(e, _current_player); |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
784 |
|
0 | 785 |
return 0; |
786 |
} |
|
787 |
||
257
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
788 |
// Determine if an engine type is a wagon (and not a loco) |
964
4bd472539a4e
(svn r1456) Simplify isWagon(), make it static and give it a canonical name (IsWagon)
tron
parents:
938
diff
changeset
|
789 |
static bool IsWagon(byte index) |
257
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
790 |
{ |
964
4bd472539a4e
(svn r1456) Simplify isWagon(), make it static and give it a canonical name (IsWagon)
tron
parents:
938
diff
changeset
|
791 |
return index < NUM_TRAIN_ENGINES && RailVehInfo(index)->flags & RVI_WAGON; |
257
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
792 |
} |
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
793 |
|
410 | 794 |
static void NewVehicleAvailable(Engine *e) |
0 | 795 |
{ |
796 |
Vehicle *v; |
|
797 |
Player *p; |
|
798 |
int index = e - _engines; |
|
799 |
||
800 |
// In case the player didn't build the vehicle during the intro period, |
|
801 |
// prevent that player from getting future intro periods for a while. |
|
802 |
if (e->flags&ENGINE_INTRODUCING) { |
|
803 |
FOR_ALL_PLAYERS(p) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
804 |
uint block_preview = p->block_preview; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
805 |
|
0 | 806 |
if (!HASBIT(e->player_avail,p->index)) |
807 |
continue; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
808 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
809 |
/* We assume the user did NOT build it.. prove me wrong ;) */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
810 |
p->block_preview = 20; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
811 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
812 |
FOR_ALL_VEHICLES(v) { |
0 | 813 |
if (v->type == VEH_Train || v->type == VEH_Road || v->type == VEH_Ship || |
814 |
(v->type == VEH_Aircraft && v->subtype <= 2)) { |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
815 |
if (v->owner == p->index && v->engine_type == index) { |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
816 |
/* The user did prove me wrong, so restore old value */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
817 |
p->block_preview = block_preview; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
818 |
break; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
915
diff
changeset
|
819 |
} |
0 | 820 |
} |
821 |
} |
|
822 |
} |
|
823 |
} |
|
824 |
||
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
825 |
e->flags = (e->flags & ~ENGINE_INTRODUCING) | ENGINE_AVAILABLE; |
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
826 |
InvalidateWindowClasses(WC_BUILD_VEHICLE); |
1096
ce698f7e4621
(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
|
827 |
InvalidateWindowClasses(WC_REPLACE_VEHICLE); |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
828 |
|
0 | 829 |
// Now available for all players |
830 |
e->player_avail = (byte)-1; |
|
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
831 |
|
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
832 |
// Do not introduce new rail wagons |
964
4bd472539a4e
(svn r1456) Simplify isWagon(), make it static and give it a canonical name (IsWagon)
tron
parents:
938
diff
changeset
|
833 |
if (IsWagon(index)) |
257
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
834 |
return; |
114
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
835 |
|
6a2af0c2d0db
(svn r115) Fix: monorail/maglev became available around 1927
dominik
parents:
0
diff
changeset
|
836 |
// make maglev / monorail available |
0 | 837 |
FOR_ALL_PLAYERS(p) { |
838 |
if (p->is_active) |
|
839 |
UPDATE_PLAYER_RAILTYPE(e,p); |
|
840 |
} |
|
841 |
||
842 |
if ((byte)index < NUM_TRAIN_ENGINES) { |
|
843 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_TRAINAVAIL), 0, 0); |
|
844 |
} else if ((byte)index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) { |
|
845 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_ROADAVAIL), 0, 0); |
|
846 |
} else if ((byte)index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) { |
|
847 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_SHIPAVAIL), 0, 0); |
|
848 |
} else { |
|
849 |
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_AIRCRAFTAVAIL), 0, 0); |
|
850 |
} |
|
851 |
} |
|
852 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
853 |
void EnginesMonthlyLoop(void) |
0 | 854 |
{ |
855 |
Engine *e; |
|
856 |
||
857 |
if (_cur_year < 130) { |
|
858 |
for(e=_engines; e != endof(_engines); e++) { |
|
859 |
// Age the vehicle |
|
860 |
if (e->flags&ENGINE_AVAILABLE && e->age != 0xFFFF) { |
|
861 |
e->age++; |
|
862 |
CalcEngineReliability(e); |
|
863 |
} |
|
864 |
||
865 |
if (!(e->flags & ENGINE_AVAILABLE) && (uint16)(_date - min(_date, 365)) >= e->intro_date) { |
|
866 |
// Introduce it to all players |
|
867 |
NewVehicleAvailable(e); |
|
868 |
} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_INTRODUCING)) && _date >= e->intro_date) { |
|
869 |
// Introduction date has passed.. show introducing dialog to one player. |
|
870 |
e->flags |= ENGINE_INTRODUCING; |
|
257
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
871 |
|
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
872 |
// Do not introduce new rail wagons |
964
4bd472539a4e
(svn r1456) Simplify isWagon(), make it static and give it a canonical name (IsWagon)
tron
parents:
938
diff
changeset
|
873 |
if (!IsWagon(e - _engines)) |
257
8d83db6716ea
(svn r262) Fix: [ 1028234 ] Monorail and MagLev infrastructure not available in 1920s any more
dominik
parents:
220
diff
changeset
|
874 |
e->preview_player = 1; // Give to the player with the highest rating. |
0 | 875 |
} |
876 |
} |
|
877 |
} |
|
878 |
AdjustAvailAircraft(); |
|
879 |
} |
|
880 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
881 |
/** Rename an engine. |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
882 |
* @param x,y unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
883 |
* @param p1 engine ID to rename |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
884 |
* @param p2 unused |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
885 |
*/ |
0 | 886 |
int32 CmdRenameEngine(int x, int y, uint32 flags, uint32 p1, uint32 p2) |
887 |
{ |
|
888 |
StringID str; |
|
889 |
||
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
890 |
if (!IsEngineIndex(p1)) return CMD_ERROR; |
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
891 |
|
1328
e069d2db0e4c
(svn r1832) Next byte -> char iteration: custom names
tron
parents:
1299
diff
changeset
|
892 |
str = AllocateNameUnique((const char*)_decode_parameters, 0); |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
893 |
if (str == 0) return CMD_ERROR; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
114
diff
changeset
|
894 |
|
0 | 895 |
if (flags & DC_EXEC) { |
896 |
StringID old_str = _engine_name_strings[p1]; |
|
897 |
_engine_name_strings[p1] = str; |
|
898 |
DeleteName(old_str); |
|
899 |
_vehicle_design_names |= 3; |
|
900 |
MarkWholeScreenDirty(); |
|
901 |
} else { |
|
902 |
DeleteName(str); |
|
903 |
} |
|
904 |
||
905 |
return 0; |
|
906 |
} |
|
907 |
||
908 |
int GetPlayerMaxRailtype(int p) |
|
909 |
{ |
|
910 |
Engine *e; |
|
911 |
int rt = 0; |
|
912 |
int i; |
|
913 |
||
914 |
for(e=_engines,i=0; i!=lengthof(_engines); e++,i++) { |
|
915 |
if (!HASBIT(e->player_avail, p)) |
|
916 |
continue; |
|
917 |
||
918 |
if ((i >= 27 && i < 54) || (i >= 57 && i < 84) || (i >= 89 && i < 116)) |
|
919 |
continue; |
|
920 |
||
921 |
if (rt < e->railtype) |
|
922 |
rt = e->railtype; |
|
923 |
} |
|
924 |
||
925 |
return rt + 1; |
|
926 |
} |
|
927 |
||
928 |
||
929 |
static const byte _engine_desc[] = { |
|
930 |
SLE_VAR(Engine,intro_date, SLE_UINT16), |
|
931 |
SLE_VAR(Engine,age, SLE_UINT16), |
|
932 |
SLE_VAR(Engine,reliability, SLE_UINT16), |
|
933 |
SLE_VAR(Engine,reliability_spd_dec, SLE_UINT16), |
|
934 |
SLE_VAR(Engine,reliability_start, SLE_UINT16), |
|
935 |
SLE_VAR(Engine,reliability_max, SLE_UINT16), |
|
936 |
SLE_VAR(Engine,reliability_final, SLE_UINT16), |
|
937 |
SLE_VAR(Engine,duration_phase_1, SLE_UINT16), |
|
938 |
SLE_VAR(Engine,duration_phase_2, SLE_UINT16), |
|
939 |
SLE_VAR(Engine,duration_phase_3, SLE_UINT16), |
|
940 |
||
941 |
SLE_VAR(Engine,lifelength, SLE_UINT8), |
|
942 |
SLE_VAR(Engine,flags, SLE_UINT8), |
|
943 |
SLE_VAR(Engine,preview_player, SLE_UINT8), |
|
944 |
SLE_VAR(Engine,preview_wait, SLE_UINT8), |
|
945 |
SLE_VAR(Engine,railtype, SLE_UINT8), |
|
946 |
SLE_VAR(Engine,player_avail, SLE_UINT8), |
|
947 |
||
948 |
// reserve extra space in savegame here. (currently 16 bytes) |
|
949 |
SLE_CONDARR(NullStruct,null,SLE_FILE_U64 | SLE_VAR_NULL, 2, 2, 255), |
|
950 |
||
951 |
SLE_END() |
|
952 |
}; |
|
953 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
954 |
static void Save_ENGN(void) |
0 | 955 |
{ |
956 |
Engine *e; |
|
957 |
int i; |
|
958 |
for(i=0,e=_engines; i != lengthof(_engines); i++,e++) { |
|
959 |
SlSetArrayIndex(i); |
|
960 |
SlObject(e, _engine_desc); |
|
961 |
} |
|
962 |
} |
|
963 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
964 |
static void Load_ENGN(void) |
0 | 965 |
{ |
966 |
int index; |
|
967 |
while ((index = SlIterateArray()) != -1) { |
|
968 |
SlObject(&_engines[index], _engine_desc); |
|
969 |
} |
|
970 |
} |
|
971 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1009
diff
changeset
|
972 |
static void LoadSave_ENGS(void) |
0 | 973 |
{ |
974 |
SlArray(_engine_name_strings, lengthof(_engine_name_strings), SLE_STRINGID); |
|
975 |
} |
|
976 |
||
977 |
const ChunkHandler _engine_chunk_handlers[] = { |
|
978 |
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY}, |
|
979 |
{ 'ENGS', LoadSave_ENGS, LoadSave_ENGS, CH_RIFF | CH_LAST}, |
|
980 |
}; |
|
981 |
||
1197 | 982 |
|
1196
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
983 |
/* |
1197 | 984 |
* returns true if an engine is valid, of the specified type, and buildable by |
985 |
* the current player, false otherwise |
|
1196
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
986 |
* |
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
987 |
* engine = index of the engine to check |
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
988 |
* type = the type the engine should be of (VEH_xxx) |
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
989 |
*/ |
1197 | 990 |
bool IsEngineBuildable(uint engine, byte type) |
991 |
{ |
|
992 |
const Engine *e; |
|
1196
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
993 |
|
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
994 |
// check if it's an engine that is in the engine array |
1786
a54634efeb98
(svn r2290) - CodeChange: protect the next batch of commands. This brings us to a total of 61, which is 53% :)
Darkvater
parents:
1560
diff
changeset
|
995 |
if (!IsEngineIndex(engine)) return false; |
1196
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
996 |
|
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
997 |
e = DEREF_ENGINE(engine); |
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
998 |
|
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
999 |
// check if it's an engine of specified type |
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
1000 |
if (e->type != type) return false; |
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
1001 |
|
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
1002 |
// check if it's available |
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
1003 |
if (!HASBIT(e->player_avail, _current_player)) return false; |
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
1004 |
|
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
1005 |
return true; |
115f46e3807d
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
bjarni
parents:
1096
diff
changeset
|
1006 |
} |