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