author | KUDr |
Fri, 20 Apr 2007 19:43:06 +0000 | |
changeset 6513 | 454347ca3dfb |
parent 6460 | 705fbddbf3dc |
child 6657 | 75f1dccae0dd |
permissions | -rw-r--r-- |
6365
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
1 |
/* $Id$ */ |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
2 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
3 |
#include "stdafx.h" |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
4 |
#include "openttd.h" |
6383
ec677b36d183
(svn r9473) -Codechange: add 'unhandled variable' debug message to newcargo resolver
peter1138
parents:
6365
diff
changeset
|
5 |
#include "debug.h" |
6365
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
6 |
#include "cargotype.h" |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
7 |
#include "newgrf.h" |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
8 |
#include "newgrf_callbacks.h" |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
9 |
#include "newgrf_spritegroup.h" |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
10 |
#include "newgrf_cargo.h" |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
11 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
12 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
13 |
static uint32 CargoGetRandomBits(const ResolverObject *object) |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
14 |
{ |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
15 |
return 0; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
16 |
} |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
17 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
18 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
19 |
static uint32 CargoGetTriggers(const ResolverObject *object) |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
20 |
{ |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
21 |
return 0; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
22 |
} |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
23 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
24 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
25 |
static void CargoSetTriggers(const ResolverObject *object, int triggers) |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
26 |
{ |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
27 |
return; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
28 |
} |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
29 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
30 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
31 |
static uint32 CargoGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
32 |
{ |
6383
ec677b36d183
(svn r9473) -Codechange: add 'unhandled variable' debug message to newcargo resolver
peter1138
parents:
6365
diff
changeset
|
33 |
DEBUG(grf, 1, "Unhandled cargo property 0x%X", variable); |
ec677b36d183
(svn r9473) -Codechange: add 'unhandled variable' debug message to newcargo resolver
peter1138
parents:
6365
diff
changeset
|
34 |
|
6365
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
35 |
*available = false; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
36 |
return 0; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
37 |
} |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
38 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
39 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
40 |
static const SpriteGroup *CargoResolveReal(const ResolverObject *object, const SpriteGroup *group) |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
41 |
{ |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
42 |
/* Cargo action 2s should always have only 1 "loaded" state */ |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
43 |
if (group->g.real.num_loaded == 0) return NULL; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
44 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
45 |
return group->g.real.loaded[0]; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
46 |
} |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
47 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
48 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
49 |
static void NewCargoResolver(ResolverObject *res, const CargoSpec *cs) |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
50 |
{ |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
51 |
res->GetRandomBits = &CargoGetRandomBits; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
52 |
res->GetTriggers = &CargoGetTriggers; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
53 |
res->SetTriggers = &CargoSetTriggers; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
54 |
res->GetVariable = &CargoGetVariable; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
55 |
res->ResolveReal = &CargoResolveReal; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
56 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
57 |
res->u.cargo.cs = cs; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
58 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
59 |
res->callback = 0; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
60 |
res->callback_param1 = 0; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
61 |
res->callback_param2 = 0; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
62 |
res->last_value = 0; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
63 |
res->trigger = 0; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
64 |
res->reseed = 0; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
65 |
} |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
66 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
67 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
68 |
SpriteID GetCustomCargoSprite(const CargoSpec *cs) |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
69 |
{ |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
70 |
const SpriteGroup *group; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
71 |
ResolverObject object; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
72 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
73 |
NewCargoResolver(&object, cs); |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
74 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
75 |
group = Resolve(cs->group, &object); |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
76 |
if (group == NULL || group->type != SGT_RESULT) return 0; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
77 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
78 |
return group->g.result.sprite; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
79 |
} |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
80 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
81 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
82 |
uint16 GetCargoCallback(uint16 callback, uint32 param1, uint32 param2, const CargoSpec *cs) |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
83 |
{ |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
84 |
ResolverObject object; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
85 |
const SpriteGroup *group; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
86 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
87 |
NewCargoResolver(&object, cs); |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
88 |
object.callback = callback; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
89 |
object.callback_param1 = param1; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
90 |
object.callback_param2 = param2; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
91 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
92 |
group = Resolve(cs->group, &object); |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
93 |
if (group == NULL || group->type != SGT_CALLBACK) return CALLBACK_FAILED; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
94 |
|
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
95 |
return group->g.callback.result; |
b52bd4ca10b6
(svn r9418) -Codechange: Implement actions 1/2/3 for cargos, callback handler and custom icon sprites
peter1138
parents:
diff
changeset
|
96 |
} |
6460
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
97 |
|
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
98 |
|
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
99 |
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile) |
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
100 |
{ |
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
101 |
/* Pre-version 7 uses the 'climate dependent' ID, i.e. cargo is the cargo ID */ |
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
102 |
if (grffile->grf_version < 7) return HASBIT(_cargo_mask, cargo) ? cargo : (CargoID) CT_INVALID; |
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
103 |
|
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
104 |
/* If the GRF contains a translation table (and the cargo is in bounds) |
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
105 |
* then get the cargo ID for the label */ |
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
106 |
if (cargo < grffile->cargo_max) return GetCargoIDByLabel(grffile->cargo_list[cargo]); |
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
107 |
|
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
108 |
/* Else the cargo value is a 'climate independent' 'bitnum' */ |
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
109 |
return GetCargoIDByBitnum(cargo); |
705fbddbf3dc
(svn r9620) -Codechange: apply cargo translation table to newstation variables 0x60..0x65
peter1138
parents:
6383
diff
changeset
|
110 |
} |