|
1 /* $Id$ */ |
|
2 |
|
3 #include "stdafx.h" |
|
4 #include "openttd.h" |
|
5 #include "variables.h" |
|
6 #include "landscape.h" |
|
7 #include "debug.h" |
|
8 #include "newgrf.h" |
|
9 #include "newgrf_callbacks.h" |
|
10 #include "newgrf_spritegroup.h" |
|
11 #include "newgrf_canal.h" |
|
12 |
|
13 |
|
14 /** Table of canal 'feature' sprite groups */ |
|
15 const SpriteGroup *_canal_sg[CF_END]; |
|
16 |
|
17 |
|
18 /* Random bits and triggers are not supported for canals, so the following |
|
19 * three functions are stubs. */ |
|
20 static uint32 CanalGetRandomBits(const ResolverObject *object) |
|
21 { |
|
22 return 0; |
|
23 } |
|
24 |
|
25 |
|
26 static uint32 CanalGetTriggers(const ResolverObject *object) |
|
27 { |
|
28 return 0; |
|
29 } |
|
30 |
|
31 |
|
32 static void CanalSetTriggers(const ResolverObject *object, int triggers) |
|
33 { |
|
34 return; |
|
35 } |
|
36 |
|
37 |
|
38 static uint32 CanalGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
|
39 { |
|
40 TileIndex tile = object->u.canal.tile; |
|
41 |
|
42 switch (variable) { |
|
43 case 0x80: |
|
44 return TileHeight(tile); |
|
45 |
|
46 case 0x81: |
|
47 return ((_opt.landscape == LT_ARCTIC && GetTileZ(tile) > GetSnowLine()) ? 4 : 0) | |
|
48 (_opt.landscape == LT_TROPIC ? GetTropicZone(tile) : 0); |
|
49 } |
|
50 |
|
51 DEBUG(grf, 1, "Unhandled canal property 0x%02X", variable); |
|
52 |
|
53 *available = false; |
|
54 return 0; |
|
55 } |
|
56 |
|
57 |
|
58 static const SpriteGroup *CanalResolveReal(const ResolverObject *object, const SpriteGroup *group) |
|
59 { |
|
60 if (group->g.real.num_loaded == 0) return NULL; |
|
61 |
|
62 return group->g.real.loaded[0]; |
|
63 } |
|
64 |
|
65 |
|
66 static void NewCanalResolver(ResolverObject *res, TileIndex tile) |
|
67 { |
|
68 res->GetRandomBits = &CanalGetRandomBits; |
|
69 res->GetTriggers = &CanalGetTriggers; |
|
70 res->SetTriggers = &CanalSetTriggers; |
|
71 res->GetVariable = &CanalGetVariable; |
|
72 res->ResolveReal = &CanalResolveReal; |
|
73 |
|
74 res->u.canal.tile = tile; |
|
75 |
|
76 res->callback = 0; |
|
77 res->callback_param1 = 0; |
|
78 res->callback_param2 = 0; |
|
79 res->last_value = 0; |
|
80 res->trigger = 0; |
|
81 res->reseed = 0; |
|
82 } |
|
83 |
|
84 |
|
85 SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile) |
|
86 { |
|
87 ResolverObject object; |
|
88 const SpriteGroup *group; |
|
89 |
|
90 NewCanalResolver(&object, tile); |
|
91 |
|
92 group = Resolve(_canal_sg[feature], &object); |
|
93 if (group == NULL || group->type != SGT_RESULT) return 0; |
|
94 |
|
95 return group->g.result.sprite; |
|
96 } |