summaryrefslogtreecommitdiff
path: root/src/trafficlight.h
blob: 4563a690c03f97a7020f6c633246117ea5f9d17d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* $Id: trafficlight.h $ */

/*
 * This file is part of OpenTTD.
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 */

/** @file trafficlight.h variables used for handling trafficlights. */


/**
 * Used for synchronising traffic light signals.
 * Number below is how far we look into the _tl_check_offsets array when
 * placing trafficlights, based on _settings_game.construction.max_tlc_distance.
 */
static const uint8 _tlc_distance[5] = {
0,  ///< no synchronizing.
8,  ///< adjecant tiles only.
24, ///< 2 tiles away.
48, ///< 3 tiles away.
80  ///< 4 tiles away.
};

/** TileDiffs for the adjacent tiles and those a little further away. */
static const TileIndexDiffC _tl_check_offsets[80] = {
	/* Tiles next to this tile (8 tiles). */
	{-1, -1},
	{ 0, -1},
	{ 1, -1},
	{ 1,  0},
	{ 1,  1},
	{ 0,  1},
	{-1,  1},
	{-1,  0},
	/* Tiles two tiles away from this tile (16 tiles). */
	{-2, -2},
	{-1, -2},
	{ 0, -2},
	{ 1, -2},
	{ 2, -2},
	{ 2, -1},
	{ 2,  0},
	{ 2,  1},
	{ 2,  2},
	{ 1,  2},
	{ 0,  2},
	{-1,  2},
	{-2,  2},
	{-2,  1},
	{-2,  0},
	{-2, -1},
	/* Tiles three tiles away from this tile (24 tiles). */
	{-3, -3},
	{-3, -2},
	{-3, -1},
	{-3,  0},
	{-3,  1},
	{-3,  2},
	{-3,  3},
	{-2,  3},
	{-1,  3},
	{ 0,  3},
	{ 1,  3},
	{ 2,  3},
	{ 3,  3},
	{ 3,  2},
	{ 3,  1},
	{ 3,  0},
	{ 3, -1},
	{ 3, -2},
	{ 3, -3},
	{ 2, -3},
	{ 1, -3},
	{ 0, -3},
	{-1, -3},
	{-2, -3},
	/* Tiles four tiles away from this tile (32 tiles). */
	{-4, -4},
	{-3, -4},
	{-2, -4},
	{-1, -4},
	{ 0, -4},
	{ 1, -4},
	{ 2, -4},
	{ 3, -4},
	{ 4, -4},
	{ 4, -3},
	{ 4, -2},
	{ 4, -1},
	{ 4,  0},
	{ 4,  1},
	{ 4,  2},
	{ 4,  3},
	{ 4,  4},
	{ 3,  4},
	{ 2,  4},
	{ 1,  4},
	{ 0,  4},
	{-1,  4},
	{-2,  4},
	{-3,  4},
	{-4,  4},
	{-4,  3},
	{-4,  2},
	{-4,  1},
	{-4,  0},
	{-4, -1},
	{-4, -2},
	{-4, -3}
};

/**
 * Drawing offsets for the traffic light posts [roadside (left, right)][direction (SW, SE, NW, NE)].
 */
static const Point _tl_offsets[2][4] = {
	{{15, 1}, {14, 15}, {1, 0}, {0, 14}},  // Left side driving.
	{{15, 14}, {1, 15}, {14, 0}, {0, 1}}   // Right side driving.
};

/**
 * Sprites needed for the various states of a TL crossing [state][direction].
 */
static const SpriteID _tls_to_sprites[7][4] = {
	{SPR_TL_SW_NONE,       SPR_TL_SE_NONE,       SPR_TL_NW_NONE,       SPR_TL_NE_NONE},
	{SPR_TL_SW_GREEN,      SPR_TL_SE_RED,        SPR_TL_NW_RED,        SPR_TL_NE_GREEN},
	{SPR_TL_SW_YELLOW,     SPR_TL_SE_RED,        SPR_TL_NW_RED,        SPR_TL_NE_YELLOW},
	{SPR_TL_SW_RED,        SPR_TL_SE_RED_YELLOW, SPR_TL_NW_RED_YELLOW, SPR_TL_NE_RED},
	{SPR_TL_SW_RED,        SPR_TL_SE_GREEN,      SPR_TL_NW_GREEN,      SPR_TL_NE_RED},
	{SPR_TL_SW_RED,        SPR_TL_SE_YELLOW,     SPR_TL_NW_YELLOW,     SPR_TL_NE_RED},
	{SPR_TL_SW_RED_YELLOW, SPR_TL_SE_RED,        SPR_TL_NW_RED,        SPR_TL_NE_RED_YELLOW}
};