author | rubidium |
Thu, 27 Dec 2007 13:35:39 +0000 | |
changeset 8640 | 1e93b81e96d2 |
parent 8604 | 8afdd9877afd |
child 8864 | 0082e49e8351 |
child 9724 | b39bc69bb2f2 |
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" |
8604
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
8019
diff
changeset
|
13 |
#include "tile_map.h" |
7079
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
16 |
/** Table of canal 'feature' sprite groups */ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
17 |
const SpriteGroup *_canal_sg[CF_END]; |
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
20 |
/* 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
|
21 |
* three functions are stubs. */ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
22 |
static uint32 CanalGetRandomBits(const ResolverObject *object) |
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 |
return 0; |
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
28 |
static uint32 CanalGetTriggers(const ResolverObject *object) |
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 |
return 0; |
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
34 |
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
|
35 |
{ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
36 |
return; |
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
40 |
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
|
41 |
{ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
42 |
TileIndex tile = object->u.canal.tile; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
43 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
44 |
switch (variable) { |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
45 |
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
|
46 |
return GetTileZ(tile) / TILE_HEIGHT; |
7079
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
47 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
48 |
case 0x81: |
7702
e9990aaa0909
(svn r10484) -Codechange: reduce code duplication.
rubidium
parents:
7079
diff
changeset
|
49 |
return GetTerrainType(tile); |
7079
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
52 |
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
|
53 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
54 |
*available = false; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
55 |
return 0; |
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
59 |
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
|
60 |
{ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
61 |
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
|
62 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
63 |
return group->g.real.loaded[0]; |
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
67 |
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
|
68 |
{ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
69 |
res->GetRandomBits = &CanalGetRandomBits; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
70 |
res->GetTriggers = &CanalGetTriggers; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
71 |
res->SetTriggers = &CanalSetTriggers; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
72 |
res->GetVariable = &CanalGetVariable; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
73 |
res->ResolveReal = &CanalResolveReal; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
74 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
75 |
res->u.canal.tile = tile; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
76 |
|
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
|
77 |
res->callback = CBID_NO_CALLBACK; |
7079
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
78 |
res->callback_param1 = 0; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
79 |
res->callback_param2 = 0; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
80 |
res->last_value = 0; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
81 |
res->trigger = 0; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
82 |
res->reseed = 0; |
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 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
86 |
SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile) |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
87 |
{ |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
88 |
ResolverObject object; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
89 |
const SpriteGroup *group; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
90 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
91 |
NewCanalResolver(&object, tile); |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
92 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
93 |
group = Resolve(_canal_sg[feature], &object); |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
94 |
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
|
95 |
|
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
96 |
return group->g.result.sprite; |
35743c461482
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
97 |
} |