author | truebrain |
Mon, 30 Jun 2008 21:31:23 +0000 | |
branch | noai |
changeset 11111 | 1b984dab8cec |
parent 10455 | 22c441f5adf9 |
permissions | -rw-r--r-- |
9517 | 1 |
/* $Id$ */ |
2 |
||
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9826
diff
changeset
|
3 |
/** @file newgrf_cargo.cpp Implementation of NewGRF cargoes. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9826
diff
changeset
|
4 |
|
9517 | 5 |
#include "stdafx.h" |
6 |
#include "openttd.h" |
|
9566 | 7 |
#include "debug.h" |
9517 | 8 |
#include "cargotype.h" |
9 |
#include "newgrf.h" |
|
10 |
#include "newgrf_callbacks.h" |
|
11 |
#include "newgrf_spritegroup.h" |
|
12 |
#include "newgrf_cargo.h" |
|
13 |
||
14 |
||
15 |
static uint32 CargoGetRandomBits(const ResolverObject *object) |
|
16 |
{ |
|
17 |
return 0; |
|
18 |
} |
|
19 |
||
20 |
||
21 |
static uint32 CargoGetTriggers(const ResolverObject *object) |
|
22 |
{ |
|
23 |
return 0; |
|
24 |
} |
|
25 |
||
26 |
||
27 |
static void CargoSetTriggers(const ResolverObject *object, int triggers) |
|
28 |
{ |
|
29 |
return; |
|
30 |
} |
|
31 |
||
32 |
||
33 |
static uint32 CargoGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
|
34 |
{ |
|
9566 | 35 |
DEBUG(grf, 1, "Unhandled cargo property 0x%X", variable); |
36 |
||
9517 | 37 |
*available = false; |
38 |
return 0; |
|
39 |
} |
|
40 |
||
41 |
||
42 |
static const SpriteGroup *CargoResolveReal(const ResolverObject *object, const SpriteGroup *group) |
|
43 |
{ |
|
9624 | 44 |
/* Cargo action 2s should always have only 1 "loaded" state, but some |
45 |
* times things don't follow the spec... */ |
|
46 |
if (group->g.real.num_loaded > 0) return group->g.real.loaded[0]; |
|
47 |
if (group->g.real.num_loading > 0) return group->g.real.loading[0]; |
|
9517 | 48 |
|
9624 | 49 |
return NULL; |
9517 | 50 |
} |
51 |
||
52 |
||
53 |
static void NewCargoResolver(ResolverObject *res, const CargoSpec *cs) |
|
54 |
{ |
|
55 |
res->GetRandomBits = &CargoGetRandomBits; |
|
56 |
res->GetTriggers = &CargoGetTriggers; |
|
57 |
res->SetTriggers = &CargoSetTriggers; |
|
58 |
res->GetVariable = &CargoGetVariable; |
|
59 |
res->ResolveReal = &CargoResolveReal; |
|
60 |
||
61 |
res->u.cargo.cs = cs; |
|
62 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
63 |
res->callback = CBID_NO_CALLBACK; |
9517 | 64 |
res->callback_param1 = 0; |
65 |
res->callback_param2 = 0; |
|
66 |
res->last_value = 0; |
|
67 |
res->trigger = 0; |
|
68 |
res->reseed = 0; |
|
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
69 |
res->count = 0; |
9517 | 70 |
} |
71 |
||
72 |
||
73 |
SpriteID GetCustomCargoSprite(const CargoSpec *cs) |
|
74 |
{ |
|
75 |
const SpriteGroup *group; |
|
76 |
ResolverObject object; |
|
77 |
||
78 |
NewCargoResolver(&object, cs); |
|
79 |
||
80 |
group = Resolve(cs->group, &object); |
|
81 |
if (group == NULL || group->type != SGT_RESULT) return 0; |
|
82 |
||
83 |
return group->g.result.sprite; |
|
84 |
} |
|
85 |
||
86 |
||
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
87 |
uint16 GetCargoCallback(CallbackID callback, uint32 param1, uint32 param2, const CargoSpec *cs) |
9517 | 88 |
{ |
89 |
ResolverObject object; |
|
90 |
const SpriteGroup *group; |
|
91 |
||
92 |
NewCargoResolver(&object, cs); |
|
93 |
object.callback = callback; |
|
94 |
object.callback_param1 = param1; |
|
95 |
object.callback_param2 = param2; |
|
96 |
||
97 |
group = Resolve(cs->group, &object); |
|
98 |
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
|
99 |
||
100 |
return group->g.callback.result; |
|
101 |
} |
|
9599 | 102 |
|
103 |
||
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
104 |
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit) |
9599 | 105 |
{ |
106 |
/* 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
|
107 |
if (grffile->grf_version < 7) { |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
108 |
if (!usebit) return cargo; |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
109 |
/* Else the cargo value is a 'climate independent' 'bitnum' */ |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
110 |
if (HasBit(_cargo_mask, cargo)) return GetCargoIDByBitnum(cargo); |
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
111 |
} else { |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
112 |
/* 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
|
113 |
* then get the cargo ID for the label */ |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
114 |
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
|
115 |
} |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9694
diff
changeset
|
116 |
return CT_INVALID; |
9599 | 117 |
} |
9641
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 |
uint8 GetReverseCargoTranslation(CargoID cargo, const GRFFile *grffile) |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
120 |
{ |
9732 | 121 |
/* Note: All grf versions use CargoBit here. Pre-version 7 do NOT use the 'climate dependent' ID. */ |
9641
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
122 |
const CargoSpec *cs = GetCargo(cargo); |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
123 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
124 |
/* 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
|
125 |
* then get the cargo ID for the label */ |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
126 |
for (uint i = 0; i < grffile->cargo_max; i++) { |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
127 |
if (cs->label == grffile->cargo_list[i]) return i; |
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 |
|
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
130 |
/* 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
|
131 |
return cs->bitnum;; |
855e32c08c9b
(svn r10533) [NoAI] -Sync with trunk r10460:r10532.
truelight
parents:
9624
diff
changeset
|
132 |
} |