author | truelight |
Sat, 20 Oct 2007 10:42:28 +0000 | |
branch | noai |
changeset 9718 | f82a4facea8b |
parent 9694 | e72987579514 |
child 8424 | 4a488a90ccab |
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 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
61 |
res->callback = CBID_NO_CALLBACK; |
9517 | 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 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
84 |
uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs) |
9517 | 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 |
||
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
101 |
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit) |
9599 | 102 |
{ |
103 |
/* Pre-version 7 uses the 'climate dependent' ID, i.e. cargo is the cargo ID */ |
|
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
104 |
if (grffile->grf_version < 7) { |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
105 |
if (!usebit) return cargo; |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
106 |
/* Else the cargo value is a 'climate independent' 'bitnum' */ |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
107 |
if (HASBIT(_cargo_mask, cargo)) return GetCargoIDByBitnum(cargo); |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
108 |
} else { |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
109 |
/* If the GRF contains a translation table (and the cargo is in bounds) |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
110 |
* then get the cargo ID for the label */ |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
111 |
if (cargo < grffile->cargo_max) return GetCargoIDByLabel(grffile->cargo_list[cargo]); |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
112 |
} |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
113 |
return CT_INVALID; |
9599 | 114 |
} |
9641
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 |
uint8 GetReverseCargoTranslation(CargoID cargo, const GRFFile *grffile) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
117 |
{ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
118 |
/* 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
|
119 |
if (grffile->grf_version < 7) return 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 |
const CargoSpec *cs = GetCargo(cargo); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
122 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
123 |
/* 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
|
124 |
* then get the cargo ID for the label */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
125 |
for (uint i = 0; i < grffile->cargo_max; i++) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
126 |
if (cs->label == grffile->cargo_list[i]) return i; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
127 |
} |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
128 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
129 |
/* 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
|
130 |
return cs->bitnum;; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
131 |
} |