author | truelight |
Fri, 13 Jul 2007 09:18:50 +0000 | |
branch | noai |
changeset 9641 | 855e32c08c9b |
parent 9624 | b71483f2330f |
child 7823 | cad4dec2b899 |
permissions | -rw-r--r-- |
9517 | 1 |
/* $Id$ */ |
2 |
||
3 |
#include "stdafx.h" |
|
4 |
#include "openttd.h" |
|
9566 | 5 |
#include "debug.h" |
9517 | 6 |
#include "cargotype.h" |
7 |
#include "newgrf.h" |
|
8 |
#include "newgrf_callbacks.h" |
|
9 |
#include "newgrf_spritegroup.h" |
|
10 |
#include "newgrf_cargo.h" |
|
11 |
||
12 |
||
13 |
static uint32 CargoGetRandomBits(const ResolverObject *object) |
|
14 |
{ |
|
15 |
return 0; |
|
16 |
} |
|
17 |
||
18 |
||
19 |
static uint32 CargoGetTriggers(const ResolverObject *object) |
|
20 |
{ |
|
21 |
return 0; |
|
22 |
} |
|
23 |
||
24 |
||
25 |
static void CargoSetTriggers(const ResolverObject *object, int triggers) |
|
26 |
{ |
|
27 |
return; |
|
28 |
} |
|
29 |
||
30 |
||
31 |
static uint32 CargoGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
|
32 |
{ |
|
9566 | 33 |
DEBUG(grf, 1, "Unhandled cargo property 0x%X", variable); |
34 |
||
9517 | 35 |
*available = false; |
36 |
return 0; |
|
37 |
} |
|
38 |
||
39 |
||
40 |
static const SpriteGroup *CargoResolveReal(const ResolverObject *object, const SpriteGroup *group) |
|
41 |
{ |
|
9624 | 42 |
/* Cargo action 2s should always have only 1 "loaded" state, but some |
43 |
* times things don't follow the spec... */ |
|
44 |
if (group->g.real.num_loaded > 0) return group->g.real.loaded[0]; |
|
45 |
if (group->g.real.num_loading > 0) return group->g.real.loading[0]; |
|
9517 | 46 |
|
9624 | 47 |
return NULL; |
9517 | 48 |
} |
49 |
||
50 |
||
51 |
static void NewCargoResolver(ResolverObject *res, const CargoSpec *cs) |
|
52 |
{ |
|
53 |
res->GetRandomBits = &CargoGetRandomBits; |
|
54 |
res->GetTriggers = &CargoGetTriggers; |
|
55 |
res->SetTriggers = &CargoSetTriggers; |
|
56 |
res->GetVariable = &CargoGetVariable; |
|
57 |
res->ResolveReal = &CargoResolveReal; |
|
58 |
||
59 |
res->u.cargo.cs = cs; |
|
60 |
||
61 |
res->callback = 0; |
|
62 |
res->callback_param1 = 0; |
|
63 |
res->callback_param2 = 0; |
|
64 |
res->last_value = 0; |
|
65 |
res->trigger = 0; |
|
66 |
res->reseed = 0; |
|
67 |
} |
|
68 |
||
69 |
||
70 |
SpriteID GetCustomCargoSprite(const CargoSpec *cs) |
|
71 |
{ |
|
72 |
const SpriteGroup *group; |
|
73 |
ResolverObject object; |
|
74 |
||
75 |
NewCargoResolver(&object, cs); |
|
76 |
||
77 |
group = Resolve(cs->group, &object); |
|
78 |
if (group == NULL || group->type != SGT_RESULT) return 0; |
|
79 |
||
80 |
return group->g.result.sprite; |
|
81 |
} |
|
82 |
||
83 |
||
84 |
uint16 GetCargoCallback(uint16 callback, uint32 param1, uint32 param2, const CargoSpec *cs) |
|
85 |
{ |
|
86 |
ResolverObject object; |
|
87 |
const SpriteGroup *group; |
|
88 |
||
89 |
NewCargoResolver(&object, cs); |
|
90 |
object.callback = callback; |
|
91 |
object.callback_param1 = param1; |
|
92 |
object.callback_param2 = param2; |
|
93 |
||
94 |
group = Resolve(cs->group, &object); |
|
95 |
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
|
96 |
||
97 |
return group->g.callback.result; |
|
98 |
} |
|
9599 | 99 |
|
100 |
||
101 |
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile) |
|
102 |
{ |
|
103 |
/* Pre-version 7 uses the 'climate dependent' ID, i.e. cargo is the cargo ID */ |
|
104 |
if (grffile->grf_version < 7) return HASBIT(_cargo_mask, cargo) ? cargo : (CargoID) CT_INVALID; |
|
105 |
||
106 |
/* If the GRF contains a translation table (and the cargo is in bounds) |
|
107 |
* then get the cargo ID for the label */ |
|
108 |
if (cargo < grffile->cargo_max) return GetCargoIDByLabel(grffile->cargo_list[cargo]); |
|
109 |
||
110 |
/* Else the cargo value is a 'climate independent' 'bitnum' */ |
|
111 |
return GetCargoIDByBitnum(cargo); |
|
112 |
} |
|
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
113 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
114 |
uint8 GetReverseCargoTranslation(CargoID cargo, const GRFFile *grffile) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
115 |
{ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
116 |
/* Pre-version 7 uses the 'climate dependent' ID, i.e. cargo is the cargo ID */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
117 |
if (grffile->grf_version < 7) return cargo; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
118 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
119 |
const CargoSpec *cs = GetCargo(cargo); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
120 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
121 |
/* If the GRF contains a translation table (and the cargo is in the table) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
122 |
* then get the cargo ID for the label */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
123 |
for (uint i = 0; i < grffile->cargo_max; i++) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
124 |
if (cs->label == grffile->cargo_list[i]) return i; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
125 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
126 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
127 |
/* No matching label was found, so we return the 'climate independent' 'bitnum' */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
128 |
return cs->bitnum;; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
129 |
} |