6303
|
1 |
/* $Id$ */
|
|
2 |
|
|
3 |
#include "stdafx.h"
|
|
4 |
#include "openttd.h"
|
|
5 |
#include "debug.h"
|
|
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 |
{
|
|
33 |
DEBUG(grf, 1, "Unhandled cargo property 0x%X", variable);
|
|
34 |
|
|
35 |
*available = false;
|
|
36 |
return 0;
|
|
37 |
}
|
|
38 |
|
|
39 |
|
|
40 |
static const SpriteGroup *CargoResolveReal(const ResolverObject *object, const SpriteGroup *group)
|
|
41 |
{
|
|
42 |
/* Cargo action 2s should always have only 1 "loaded" state */
|
|
43 |
if (group->g.real.num_loaded == 0) return NULL;
|
|
44 |
|
|
45 |
return group->g.real.loaded[0];
|
|
46 |
}
|
|
47 |
|
|
48 |
|
|
49 |
static void NewCargoResolver(ResolverObject *res, const CargoSpec *cs)
|
|
50 |
{
|
|
51 |
res->GetRandomBits = &CargoGetRandomBits;
|
|
52 |
res->GetTriggers = &CargoGetTriggers;
|
|
53 |
res->SetTriggers = &CargoSetTriggers;
|
|
54 |
res->GetVariable = &CargoGetVariable;
|
|
55 |
res->ResolveReal = &CargoResolveReal;
|
|
56 |
|
|
57 |
res->u.cargo.cs = cs;
|
|
58 |
|
|
59 |
res->callback = 0;
|
|
60 |
res->callback_param1 = 0;
|
|
61 |
res->callback_param2 = 0;
|
|
62 |
res->last_value = 0;
|
|
63 |
res->trigger = 0;
|
|
64 |
res->reseed = 0;
|
|
65 |
}
|
|
66 |
|
|
67 |
|
|
68 |
SpriteID GetCustomCargoSprite(const CargoSpec *cs)
|
|
69 |
{
|
|
70 |
const SpriteGroup *group;
|
|
71 |
ResolverObject object;
|
|
72 |
|
|
73 |
NewCargoResolver(&object, cs);
|
|
74 |
|
|
75 |
group = Resolve(cs->group, &object);
|
|
76 |
if (group == NULL || group->type != SGT_RESULT) return 0;
|
|
77 |
|
|
78 |
return group->g.result.sprite;
|
|
79 |
}
|
|
80 |
|
|
81 |
|
|
82 |
uint16 GetCargoCallback(uint16 callback, uint32 param1, uint32 param2, const CargoSpec *cs)
|
|
83 |
{
|
|
84 |
ResolverObject object;
|
|
85 |
const SpriteGroup *group;
|
|
86 |
|
|
87 |
NewCargoResolver(&object, cs);
|
|
88 |
object.callback = callback;
|
|
89 |
object.callback_param1 = param1;
|
|
90 |
object.callback_param2 = param2;
|
|
91 |
|
|
92 |
group = Resolve(cs->group, &object);
|
|
93 |
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED;
|
|
94 |
|
|
95 |
return group->g.callback.result;
|
|
96 |
}
|
6307
|
97 |
|
|
98 |
|
|
99 |
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile)
|
|
100 |
{
|
|
101 |
/* Pre-version 7 uses the 'climate dependent' ID, i.e. cargo is the cargo ID */
|
|
102 |
if (grffile->grf_version < 7) return HASBIT(_cargo_mask, cargo) ? cargo : (CargoID) CT_INVALID;
|
|
103 |
|
|
104 |
/* If the GRF contains a translation table (and the cargo is in bounds)
|
|
105 |
* then get the cargo ID for the label */
|
|
106 |
if (cargo < grffile->cargo_max) return GetCargoIDByLabel(grffile->cargo_list[cargo]);
|
|
107 |
|
|
108 |
/* Else the cargo value is a 'climate independent' 'bitnum' */
|
|
109 |
return GetCargoIDByBitnum(cargo);
|
|
110 |
}
|