annotate src/newgrf_canal.cpp @ 11302:b3148b168649 draft

(svn r15651) -Codechange: Codestyle and comments.
author peter1138 <peter1138@openttd.org>
date Mon, 09 Mar 2009 13:38:00 +0000
parents dbb22d77aec1
children db0e49f419d9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
1 /* $Id$ */
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
2
9111
d48433370037 (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 <rubidium@openttd.org>
parents: 8756
diff changeset
3 /** @file newgrf_canal.cpp Implementation of NewGRF canals. */
d48433370037 (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 <rubidium@openttd.org>
parents: 8756
diff changeset
4
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
5 #include "stdafx.h"
10960
a4e5b5d2837c (svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents: 9750
diff changeset
6 #include "core/overflowsafe_type.hpp"
a4e5b5d2837c (svn r15299) -Cleanup: remove many redundant includes
smatz <smatz@openttd.org>
parents: 9750
diff changeset
7 #include "tile_type.h"
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
8 #include "debug.h"
7206
4eb40d6fa23f (svn r10484) -Codechange: reduce code duplication.
rubidium <rubidium@openttd.org>
parents: 6583
diff changeset
9 #include "newgrf_commons.h"
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
10 #include "newgrf_spritegroup.h"
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
11 #include "newgrf_canal.h"
8108
4faab45e2603 (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium <rubidium@openttd.org>
parents: 7523
diff changeset
12 #include "tile_map.h"
8368
b42c4785f6e8 (svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138 <peter1138@openttd.org>
parents: 8108
diff changeset
13 #include "water_map.h"
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
14
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
15
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
16 /** Table of canal 'feature' sprite groups */
8372
2628bf7d5b77 (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138 <peter1138@openttd.org>
parents: 8368
diff changeset
17 WaterFeature _water_feature[CF_END];
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
18
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
19
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
20 /* Random bits and triggers are not supported for canals, so the following
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
21 * three functions are stubs. */
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
22 static uint32 CanalGetRandomBits(const ResolverObject *object)
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
23 {
8471
1e4ea519bfaf (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 <peter1138@openttd.org>
parents: 8372
diff changeset
24 /* Return random bits only for water tiles, not station tiles */
1e4ea519bfaf (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 <peter1138@openttd.org>
parents: 8372
diff changeset
25 return IsTileType(object->u.canal.tile, MP_WATER) ? GetWaterTileRandomBits(object->u.canal.tile) : 0;
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
26 }
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
27
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
28
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
29 static uint32 CanalGetTriggers(const ResolverObject *object)
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
30 {
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
31 return 0;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
32 }
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
33
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
34
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
35 static void CanalSetTriggers(const ResolverObject *object, int triggers)
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
36 {
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
37 return;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
38 }
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
39
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
40
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
41 static uint32 CanalGetVariable(const ResolverObject *object, byte variable, byte parameter, bool *available)
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
42 {
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
43 TileIndex tile = object->u.canal.tile;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
44
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
45 switch (variable) {
11302
b3148b168649 (svn r15651) -Codechange: Codestyle and comments.
peter1138 <peter1138@openttd.org>
parents: 11163
diff changeset
46 /* Height of tile */
b3148b168649 (svn r15651) -Codechange: Codestyle and comments.
peter1138 <peter1138@openttd.org>
parents: 11163
diff changeset
47 case 0x80: return GetTileZ(tile) / TILE_HEIGHT;
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
48
11302
b3148b168649 (svn r15651) -Codechange: Codestyle and comments.
peter1138 <peter1138@openttd.org>
parents: 11163
diff changeset
49 /* Terrain type */
b3148b168649 (svn r15651) -Codechange: Codestyle and comments.
peter1138 <peter1138@openttd.org>
parents: 11163
diff changeset
50 case 0x81: return GetTerrainType(tile);
8368
b42c4785f6e8 (svn r11934) -Codechange: add persistent random data for river and canal tiles.
peter1138 <peter1138@openttd.org>
parents: 8108
diff changeset
51
11302
b3148b168649 (svn r15651) -Codechange: Codestyle and comments.
peter1138 <peter1138@openttd.org>
parents: 11163
diff changeset
52 /* Random data for river or canal tiles, otherwise zero */
b3148b168649 (svn r15651) -Codechange: Codestyle and comments.
peter1138 <peter1138@openttd.org>
parents: 11163
diff changeset
53 case 0x83: return GetWaterTileRandomBits(tile);
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
54 }
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
55
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
56 DEBUG(grf, 1, "Unhandled canal property 0x%02X", variable);
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
57
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
58 *available = false;
11163
dbb22d77aec1 (svn r15513) -Cleanup: Unavailable varaction variable value does not matter, but at least it can be consistent.
peter1138 <peter1138@openttd.org>
parents: 10960
diff changeset
59 return UINT_MAX;
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
60 }
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
61
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
62
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
63 static const SpriteGroup *CanalResolveReal(const ResolverObject *object, const SpriteGroup *group)
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
64 {
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
65 if (group->g.real.num_loaded == 0) return NULL;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
66
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
67 return group->g.real.loaded[0];
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
68 }
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
69
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
70
9750
0654bf387d06 (svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch <frosch@openttd.org>
parents: 9111
diff changeset
71 static void NewCanalResolver(ResolverObject *res, TileIndex tile, const GRFFile *grffile)
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
72 {
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
73 res->GetRandomBits = &CanalGetRandomBits;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
74 res->GetTriggers = &CanalGetTriggers;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
75 res->SetTriggers = &CanalSetTriggers;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
76 res->GetVariable = &CanalGetVariable;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
77 res->ResolveReal = &CanalResolveReal;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
78
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
79 res->u.canal.tile = tile;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
80
7327
0ab2820a1e52 (svn r10690) -Codechange: use the enum that describes all callback IDs in favor of "just" using an untyped integer.
rubidium <rubidium@openttd.org>
parents: 7206
diff changeset
81 res->callback = CBID_NO_CALLBACK;
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
82 res->callback_param1 = 0;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
83 res->callback_param2 = 0;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
84 res->last_value = 0;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
85 res->trigger = 0;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
86 res->reseed = 0;
8756
ae0ec91bb55e (svn r12452) -Feature: [NewGRF] Add random action 2 type 84. For vehicles only.
glx <glx@openttd.org>
parents: 8471
diff changeset
87 res->count = 0;
9750
0654bf387d06 (svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch <frosch@openttd.org>
parents: 9111
diff changeset
88 res->grffile = grffile;
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
89 }
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
90
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
91
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
92 SpriteID GetCanalSprite(CanalFeature feature, TileIndex tile)
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
93 {
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
94 ResolverObject object;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
95 const SpriteGroup *group;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
96
9750
0654bf387d06 (svn r13885) -Fix [FS#2168]: Var 0x7F is not feature-specific.
frosch <frosch@openttd.org>
parents: 9111
diff changeset
97 NewCanalResolver(&object, tile, _water_feature[feature].grffile);
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
98
8372
2628bf7d5b77 (svn r11938) -Codechange: support loading of canal/river properties (though still ignored)
peter1138 <peter1138@openttd.org>
parents: 8368
diff changeset
99 group = Resolve(_water_feature[feature].group, &object);
6583
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
100 if (group == NULL || group->type != SGT_RESULT) return 0;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
101
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
102 return group->g.result.sprite;
7e15dfbfb126 (svn r9797) -Feature: [NewGRF] Add action 1, 2 and 3 support for canals.
peter1138 <peter1138@openttd.org>
parents:
diff changeset
103 }