author | glx |
Thu, 27 Sep 2007 21:47:38 +0000 | |
changeset 8142 | aaac2a5f116b |
parent 8019 | 35497d94c8d2 |
child 6872 | 1c4a4a609f85 |
child 8604 | 8afdd9877afd |
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" |
7702
e9990aaa0909
(svn r10484) -Codechange: reduce code duplication.
rubidium
parents:
7079
diff
changeset
|
10 |
#include "newgrf_commons.h" |
7079
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
11 |
#include "newgrf_spritegroup.h" |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
12 |
#include "newgrf_canal.h" |
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
15 |
/** Table of canal 'feature' sprite groups */ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
16 |
const SpriteGroup *_canal_sg[CF_END]; |
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
19 |
/* 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
|
20 |
* three functions are stubs. */ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
21 |
static uint32 CanalGetRandomBits(const ResolverObject *object) |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
22 |
{ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
23 |
return 0; |
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
27 |
static uint32 CanalGetTriggers(const ResolverObject *object) |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
28 |
{ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
29 |
return 0; |
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
33 |
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
|
34 |
{ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
35 |
return; |
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
39 |
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
|
40 |
{ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
41 |
TileIndex tile = object->u.canal.tile; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
42 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
43 |
switch (variable) { |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
44 |
case 0x80: |
8019
35497d94c8d2
(svn r11042) -Fix [FS#1196]: so newgrf callbacks returned slightly wrong heights (height of nothern corner instead of height of lowest corner). Patch by frosch.
rubidium
parents:
7823
diff
changeset
|
45 |
return GetTileZ(tile) / TILE_HEIGHT; |
7079
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
46 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
47 |
case 0x81: |
7702
e9990aaa0909
(svn r10484) -Codechange: reduce code duplication.
rubidium
parents:
7079
diff
changeset
|
48 |
return GetTerrainType(tile); |
7079
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 |
|
7823
cad4dec2b899
(svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents:
7702
diff
changeset
|
76 |
res->callback = CBID_NO_CALLBACK; |
7079
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 |
} |