author | rubidium |
Sun, 25 May 2008 19:17:03 +0000 | |
changeset 9354 | 845e07db4549 |
parent 9111 | 48ce04029fe4 |
child 9750 | 7114408dd1fa |
permissions | -rw-r--r-- |
6583
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
1 |
/* $Id$ */ |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
2 |
|
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8756
diff
changeset
|
3 |
/** @file newgrf_canal.cpp Implementation of NewGRF canals. */ |
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8756
diff
changeset
|
4 |
|
6583
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
6 |
#include "openttd.h" |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
7 |
#include "variables.h" |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
8 |
#include "landscape.h" |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
9 |
#include "debug.h" |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
10 |
#include "newgrf.h" |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
11 |
#include "newgrf_callbacks.h" |
7206
fbba6cb67bc8
(svn r10484) -Codechange: reduce code duplication.
rubidium
parents:
6583
diff
changeset
|
12 |
#include "newgrf_commons.h" |
6583
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
13 |
#include "newgrf_spritegroup.h" |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
14 |
#include "newgrf_canal.h" |
8108
b42a0e5c67ef
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7523
diff
changeset
|
15 |
#include "tile_map.h" |
8368
dcee6c9440b5
(svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents:
8108
diff
changeset
|
16 |
#include "water_map.h" |
6583
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
17 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
18 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
19 |
/** Table of canal 'feature' sprite groups */ |
8372
49f8ca06527d
(svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents:
8368
diff
changeset
|
20 |
WaterFeature _water_feature[CF_END]; |
6583
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
21 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
22 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
23 |
/* Random bits and triggers are not supported for canals, so the following |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
24 |
* three functions are stubs. */ |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
25 |
static uint32 CanalGetRandomBits(const ResolverObject *object) |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
26 |
{ |
8471
ba4c15fe147b
(svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents:
8372
diff
changeset
|
27 |
/* Return random bits only for water tiles, not station tiles */ |
ba4c15fe147b
(svn r12042) -Fix [FS#1676]: Reimplement how rivers and canals are stored in the map, allowing the sea/river/canal status to also be
peter1138
parents:
8372
diff
changeset
|
28 |
return IsTileType(object->u.canal.tile, MP_WATER) ? GetWaterTileRandomBits(object->u.canal.tile) : 0; |
6583
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
29 |
} |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
30 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
31 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
32 |
static uint32 CanalGetTriggers(const ResolverObject *object) |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
33 |
{ |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
34 |
return 0; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
35 |
} |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
36 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
37 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
38 |
static void CanalSetTriggers(const ResolverObject *object, int triggers) |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
39 |
{ |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
40 |
return; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
41 |
} |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
42 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
43 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
44 |
static uint32 CanalGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available) |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
45 |
{ |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
46 |
TileIndex tile = object->u.canal.tile; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
47 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
48 |
switch (variable) { |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
49 |
case 0x80: |
7523
a7690a1d6f06
(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:
7327
diff
changeset
|
50 |
return GetTileZ(tile) / TILE_HEIGHT; |
6583
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
51 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
52 |
case 0x81: |
7206
fbba6cb67bc8
(svn r10484) -Codechange: reduce code duplication.
rubidium
parents:
6583
diff
changeset
|
53 |
return GetTerrainType(tile); |
8368
dcee6c9440b5
(svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents:
8108
diff
changeset
|
54 |
|
dcee6c9440b5
(svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents:
8108
diff
changeset
|
55 |
case 0x83: |
dcee6c9440b5
(svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138
parents:
8108
diff
changeset
|
56 |
return GetWaterTileRandomBits(tile); |
6583
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
57 |
} |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
58 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
59 |
DEBUG(grf, 1, "Unhandled canal property 0x%02X", variable); |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
60 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
61 |
*available = false; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
62 |
return 0; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
63 |
} |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
64 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
65 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
66 |
static const SpriteGroup *CanalResolveReal(const ResolverObject *object, const SpriteGroup *group) |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
67 |
{ |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
68 |
if (group->g.real.num_loaded == 0) return NULL; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
69 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
70 |
return group->g.real.loaded[0]; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
71 |
} |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
72 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
73 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
74 |
static void NewCanalResolver(ResolverObject *res, TileIndex tile) |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
75 |
{ |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
76 |
res->GetRandomBits = &CanalGetRandomBits; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
77 |
res->GetTriggers = &CanalGetTriggers; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
78 |
res->SetTriggers = &CanalSetTriggers; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
79 |
res->GetVariable = &CanalGetVariable; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
80 |
res->ResolveReal = &CanalResolveReal; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
81 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
82 |
res->u.canal.tile = tile; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
83 |
|
7327
d810677fb909
(svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium
parents:
7206
diff
changeset
|
84 |
res->callback = CBID_NO_CALLBACK; |
6583
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
85 |
res->callback_param1 = 0; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
86 |
res->callback_param2 = 0; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
87 |
res->last_value = 0; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
88 |
res->trigger = 0; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
89 |
res->reseed = 0; |
8756
b6f8dc6a246f
(svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx
parents:
8471
diff
changeset
|
90 |
res->count = 0; |
6583
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
91 |
} |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
92 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
93 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
94 |
SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile) |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
95 |
{ |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
96 |
ResolverObject object; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
97 |
const SpriteGroup *group; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
98 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
99 |
NewCanalResolver(&object, tile); |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
100 |
|
8372
49f8ca06527d
(svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138
parents:
8368
diff
changeset
|
101 |
group = Resolve(_water_feature[feature].group, &object); |
6583
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
102 |
if (group == NULL || group->type != SGT_RESULT) return 0; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
103 |
|
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
104 |
return group->g.result.sprite; |
71d62b85d3ad
(svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138
parents:
diff
changeset
|
105 |
} |