0
|
1 |
#include "stdafx.h"
|
|
2 |
#include "ttd.h"
|
|
3 |
|
|
4 |
#include "window.h"
|
|
5 |
#include "gui.h"
|
|
6 |
#include "viewport.h"
|
|
7 |
#include "gfx.h"
|
|
8 |
#include "command.h"
|
|
9 |
#include "vehicle.h"
|
|
10 |
|
|
11 |
static uint _cur_railtype;
|
|
12 |
static bool _remove_button_clicked;
|
|
13 |
static byte _build_depot_direction;
|
|
14 |
|
|
15 |
struct {
|
|
16 |
byte orientation;
|
|
17 |
byte numtracks;
|
|
18 |
byte platlength;
|
|
19 |
bool dragdrop;
|
|
20 |
} _railstation;
|
|
21 |
|
|
22 |
|
|
23 |
static void HandleStationPlacement(uint start, uint end);
|
|
24 |
static void ShowBuildTrainDepotPicker();
|
|
25 |
static void ShowStationBuilder();
|
|
26 |
|
|
27 |
typedef void OnButtonClick(Window *w);
|
|
28 |
|
|
29 |
static void CcPlaySound1E(bool success, uint tile, uint32 p1, uint32 p2)
|
|
30 |
{
|
|
31 |
if (success) SndPlayTileFx(0x1E, tile);
|
|
32 |
}
|
|
33 |
|
|
34 |
static void GenericPlaceRail(uint tile, int cmd)
|
|
35 |
{
|
|
36 |
DoCommandP(tile, _cur_railtype, cmd, CcPlaySound1E,
|
|
37 |
_remove_button_clicked ?
|
|
38 |
CMD_REMOVE_SINGLE_RAIL | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) | CMD_AUTO | CMD_NO_WATER :
|
|
39 |
CMD_BUILD_SINGLE_RAIL | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK) | CMD_AUTO | CMD_NO_WATER
|
|
40 |
);
|
|
41 |
}
|
|
42 |
|
|
43 |
static void PlaceRail_N(uint tile)
|
|
44 |
{
|
|
45 |
int cmd = _tile_fract_coords.x > _tile_fract_coords.y ? 4 : 5;
|
|
46 |
GenericPlaceRail(tile, cmd);
|
|
47 |
}
|
|
48 |
|
|
49 |
static void PlaceRail_NE(uint tile)
|
|
50 |
{
|
|
51 |
VpStartPlaceSizing(tile, VPM_FIX_Y);
|
|
52 |
}
|
|
53 |
|
|
54 |
static void PlaceRail_E(uint tile)
|
|
55 |
{
|
|
56 |
int cmd = _tile_fract_coords.x + _tile_fract_coords.y <= 15 ? 2 : 3;
|
|
57 |
GenericPlaceRail(tile, cmd);
|
|
58 |
}
|
|
59 |
|
|
60 |
static void PlaceRail_NW(uint tile)
|
|
61 |
{
|
|
62 |
VpStartPlaceSizing(tile, VPM_FIX_X);
|
|
63 |
}
|
|
64 |
|
|
65 |
static void PlaceRail_AutoRail(uint tile)
|
|
66 |
{
|
|
67 |
VpStartPlaceSizing(tile, VPM_RAILDIRS);
|
|
68 |
}
|
|
69 |
|
|
70 |
static int16 _place_depot_offs_xy[4] = { -1, 0x100, 1, -0x100};
|
|
71 |
|
|
72 |
static void PlaceExtraDepotRail(uint tile, uint16 extra)
|
|
73 |
{
|
|
74 |
byte b = _map5[tile];
|
|
75 |
|
|
76 |
if (b & 0xC0 || !(b & (extra >> 8)))
|
|
77 |
return;
|
|
78 |
|
|
79 |
DoCommandP(tile, _cur_railtype, extra & 0xFF, NULL, CMD_BUILD_SINGLE_RAIL | CMD_AUTO | CMD_NO_WATER);
|
|
80 |
}
|
|
81 |
|
|
82 |
static const uint16 _place_depot_extra[12] = {
|
|
83 |
0x604, 0x2102, 0x1202, 0x505,
|
|
84 |
0x2400, 0x2801, 0x1800, 0x1401,
|
|
85 |
0x2203, 0x904, 0x0A05, 0x1103,
|
|
86 |
};
|
|
87 |
|
|
88 |
|
|
89 |
static void CcDepot(bool success, uint tile, uint32 p1, uint32 p2)
|
|
90 |
{
|
|
91 |
if (success) {
|
|
92 |
int dir = p2;
|
|
93 |
|
|
94 |
SndPlayTileFx(0x1E, tile);
|
|
95 |
ResetObjectToPlace();
|
|
96 |
|
|
97 |
tile += _place_depot_offs_xy[dir];
|
|
98 |
|
|
99 |
if (IS_TILETYPE(tile, MP_RAILWAY)) {
|
|
100 |
PlaceExtraDepotRail(tile, _place_depot_extra[dir]);
|
|
101 |
PlaceExtraDepotRail(tile, _place_depot_extra[dir + 4]);
|
|
102 |
PlaceExtraDepotRail(tile, _place_depot_extra[dir + 8]);
|
|
103 |
}
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
static void PlaceRail_Depot(uint tile)
|
|
108 |
{
|
|
109 |
DoCommandP(tile, _cur_railtype, _build_depot_direction, CcDepot,
|
|
110 |
CMD_BUILD_TRAIN_DEPOT | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_100E_CAN_T_BUILD_TRAIN_DEPOT));
|
|
111 |
}
|
|
112 |
|
|
113 |
static void PlaceRail_Checkpoint(uint tile)
|
|
114 |
{
|
|
115 |
if (!_remove_button_clicked) {
|
|
116 |
DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_BUILD_TRAIN_CHECKPOINT | CMD_MSG(STR_CANT_BUILD_TRAIN_CHECKPOINT));
|
|
117 |
} else {
|
|
118 |
DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_REMOVE_TRAIN_CHECKPOINT | CMD_MSG(STR_CANT_REMOVE_TRAIN_CHECKPOINT));
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
static void CcStation(bool success, uint tile, uint32 p1, uint32 p2)
|
|
123 |
{
|
|
124 |
if (success) {
|
|
125 |
SndPlayTileFx(0x1E, tile);
|
|
126 |
ResetObjectToPlace();
|
|
127 |
}
|
|
128 |
}
|
|
129 |
|
|
130 |
static void PlaceRail_Station(uint tile)
|
|
131 |
{
|
|
132 |
if(_remove_button_clicked)
|
|
133 |
DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_REMOVE_FROM_RAILROAD_STATION | CMD_MSG(STR_CANT_REMOVE_PART_OF_STATION));
|
|
134 |
else if (_railstation.dragdrop) {
|
|
135 |
VpStartPlaceSizing(tile, VPM_X_AND_Y_LIMITED);
|
|
136 |
VpSetPlaceSizingLimit(_patches.station_spread);
|
|
137 |
} else {
|
|
138 |
DoCommandP(tile, _railstation.orientation | (_railstation.numtracks<<8) | (_railstation.platlength<<16),_cur_railtype, CcStation,
|
|
139 |
CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
|
|
140 |
}
|
|
141 |
}
|
|
142 |
|
|
143 |
static void PlaceRail_Signals(uint tile)
|
|
144 |
{
|
|
145 |
uint trackstat;
|
|
146 |
int i;
|
|
147 |
|
|
148 |
trackstat = (byte)GetTileTrackStatus(tile,0);
|
|
149 |
|
|
150 |
if ((trackstat & 0x30) == 0x30) {
|
|
151 |
trackstat = (_tile_fract_coords.x <= _tile_fract_coords.y) ? 0x20 : 0x10;
|
|
152 |
}
|
|
153 |
|
|
154 |
if ((trackstat & 0x0C) == 0x0C) {
|
|
155 |
trackstat = (_tile_fract_coords.x + _tile_fract_coords.y <= 15) ? 4 : 8;
|
|
156 |
}
|
|
157 |
|
|
158 |
// Lookup the bit index
|
|
159 |
i = 0;
|
|
160 |
if (trackstat != 0) { while (!(trackstat & 1)) { i++; trackstat >>= 1; }}
|
|
161 |
|
|
162 |
if (!_remove_button_clicked) {
|
|
163 |
DoCommandP(tile, i + (_ctrl_pressed ? 8 : 0), 0, CcPlaySound1E,
|
|
164 |
CMD_BUILD_SIGNALS | CMD_AUTO | CMD_MSG(STR_1010_CAN_T_BUILD_SIGNALS_HERE));
|
|
165 |
} else {
|
|
166 |
DoCommandP(tile, i, 0, CcPlaySound1E,
|
|
167 |
CMD_REMOVE_SIGNALS | CMD_AUTO | CMD_MSG(STR_1013_CAN_T_REMOVE_SIGNALS_FROM));
|
|
168 |
}
|
|
169 |
}
|
|
170 |
|
|
171 |
static void PlaceRail_Bridge(uint tile)
|
|
172 |
{
|
|
173 |
VpStartPlaceSizing(tile, VPM_X_OR_Y);
|
|
174 |
}
|
|
175 |
|
|
176 |
static void CcBuildTunnel(bool success, uint tile, uint32 p1, uint32 p2)
|
|
177 |
{
|
|
178 |
if (success) {
|
|
179 |
SndPlayTileFx(0x1E, tile);
|
|
180 |
ResetObjectToPlace();
|
|
181 |
} else {
|
|
182 |
SetRedErrorSquare(_build_tunnel_endtile);
|
|
183 |
}
|
|
184 |
}
|
|
185 |
|
|
186 |
static void PlaceRail_Tunnel(uint tile)
|
|
187 |
{
|
|
188 |
DoCommandP(tile, _cur_railtype, 0, CcBuildTunnel,
|
|
189 |
CMD_BUILD_TUNNEL | CMD_AUTO | CMD_MSG(STR_5016_CAN_T_BUILD_TUNNEL_HERE));
|
|
190 |
}
|
|
191 |
|
|
192 |
void PlaceProc_BuyLand(uint tile)
|
|
193 |
{
|
|
194 |
DoCommandP(tile, 0, 0, CcPlaySound1E, CMD_PURCHASE_LAND_AREA | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_5806_CAN_T_PURCHASE_THIS_LAND));
|
|
195 |
}
|
|
196 |
|
|
197 |
static void PlaceRail_ConvertRail(uint tile)
|
|
198 |
{
|
|
199 |
VpStartPlaceSizing(tile, VPM_X_AND_Y | (1<<4));
|
|
200 |
}
|
|
201 |
|
|
202 |
static void BuildRailClick_AutoRail(Window *w)
|
|
203 |
{
|
|
204 |
HandlePlacePushButton(w, 3, _cur_railtype + SPR_OPENTTD_BASE + 4, 1, PlaceRail_AutoRail);
|
|
205 |
}
|
|
206 |
|
|
207 |
static void BuildRailClick_N(Window *w)
|
|
208 |
{
|
|
209 |
HandlePlacePushButton(w, 4, _cur_railtype*4 + 0x4EF, 1, PlaceRail_N);
|
|
210 |
}
|
|
211 |
|
|
212 |
static void BuildRailClick_NE(Window *w)
|
|
213 |
{
|
|
214 |
HandlePlacePushButton(w, 5, _cur_railtype*4 + 0x4F0, 1, PlaceRail_NE);
|
|
215 |
}
|
|
216 |
|
|
217 |
static void BuildRailClick_E(Window *w)
|
|
218 |
{
|
|
219 |
HandlePlacePushButton(w, 6, _cur_railtype*4 + 0x4F1, 1, PlaceRail_E);
|
|
220 |
}
|
|
221 |
|
|
222 |
static void BuildRailClick_NW(Window *w)
|
|
223 |
{
|
|
224 |
HandlePlacePushButton(w, 7, _cur_railtype*4 + 0x4F2, 1, PlaceRail_NW);
|
|
225 |
}
|
|
226 |
|
|
227 |
static void BuildRailClick_Demolish(Window *w)
|
|
228 |
{
|
|
229 |
HandlePlacePushButton(w, 8, ANIMCURSOR_DEMOLISH, 1, PlaceProc_DemolishArea);
|
|
230 |
}
|
|
231 |
|
|
232 |
static void BuildRailClick_Lower(Window *w)
|
|
233 |
{
|
|
234 |
HandlePlacePushButton(w, 9, ANIMCURSOR_LOWERLAND, 2, PlaceProc_LowerLand);
|
|
235 |
}
|
|
236 |
|
|
237 |
static void BuildRailClick_Raise(Window *w)
|
|
238 |
{
|
|
239 |
HandlePlacePushButton(w, 10, ANIMCURSOR_RAISELAND, 2, PlaceProc_RaiseLand);
|
|
240 |
}
|
|
241 |
|
|
242 |
static const SpriteID _depot_cursors[] = {
|
|
243 |
0x510,
|
|
244 |
SPR_OPENTTD_BASE + 14,
|
|
245 |
SPR_OPENTTD_BASE + 15,
|
|
246 |
};
|
|
247 |
|
|
248 |
static void BuildRailClick_Depot(Window *w)
|
|
249 |
{
|
|
250 |
if (HandlePlacePushButton(w, 11, _depot_cursors[_cur_railtype], 1, PlaceRail_Depot)) ShowBuildTrainDepotPicker();
|
|
251 |
}
|
|
252 |
|
|
253 |
static void BuildRailClick_Station(Window *w)
|
|
254 |
{
|
|
255 |
if (HandlePlacePushButton(w, 12, 0x514, 1, PlaceRail_Station)) ShowStationBuilder();
|
|
256 |
}
|
|
257 |
|
|
258 |
static void BuildRailClick_Signals(Window *w)
|
|
259 |
{
|
|
260 |
HandlePlacePushButton(w, 13, ANIMCURSOR_BUILDSIGNALS, 1, PlaceRail_Signals);
|
|
261 |
}
|
|
262 |
|
|
263 |
static void BuildRailClick_Bridge(Window *w)
|
|
264 |
{
|
|
265 |
HandlePlacePushButton(w, 14, 0xA21, 1, PlaceRail_Bridge);
|
|
266 |
}
|
|
267 |
|
|
268 |
static void BuildRailClick_Tunnel(Window *w)
|
|
269 |
{
|
|
270 |
HandlePlacePushButton(w, 15, 0x982 + _cur_railtype, 3, PlaceRail_Tunnel);
|
|
271 |
}
|
|
272 |
|
|
273 |
static void BuildRailClick_Remove(Window *w)
|
|
274 |
{
|
|
275 |
if (w->disabled_state & (1<<16))
|
|
276 |
return;
|
|
277 |
SetWindowDirty(w);
|
|
278 |
SndPlayFx(0x13);
|
|
279 |
|
|
280 |
_thd.make_square_red = !!((w->click_state ^= (1 << 16)) & (1<<16));
|
|
281 |
_remove_button_clicked = (w->click_state & (1 << 16)) != 0;
|
|
282 |
|
|
283 |
// handle station builder
|
|
284 |
if( w->click_state & (1 << 12) )
|
|
285 |
{
|
|
286 |
if(_remove_button_clicked)
|
|
287 |
SetTileSelectSize(1, 1);
|
|
288 |
else
|
|
289 |
BringWindowToFrontById(WC_BUILD_STATION, 0);
|
|
290 |
}
|
|
291 |
}
|
|
292 |
|
|
293 |
static void BuildRailClick_Sign(Window *w)
|
|
294 |
{
|
|
295 |
HandlePlacePushButton(w, 17, 0x12B8, 1, PlaceProc_BuyLand);
|
|
296 |
}
|
|
297 |
|
|
298 |
static void BuildRailClick_Checkpoint(Window *w)
|
|
299 |
{
|
|
300 |
HandlePlacePushButton(w, 18, SPR_OPENTTD_BASE + 7, 1, PlaceRail_Checkpoint);
|
|
301 |
}
|
|
302 |
|
|
303 |
static void BuildRailClick_Convert(Window *w)
|
|
304 |
{
|
|
305 |
HandlePlacePushButton(w, 19, (SPR_OPENTTD_BASE + 26) + _cur_railtype * 2, 1, PlaceRail_ConvertRail);
|
|
306 |
}
|
|
307 |
|
|
308 |
|
|
309 |
static void DoRailroadTrack(int mode)
|
|
310 |
{
|
|
311 |
DoCommandP(TILE_FROM_XY(_thd.selstart.x, _thd.selstart.y), PACK_POINT(_thd.selend.x, _thd.selend.y), (mode << 4) | _cur_railtype, NULL,
|
|
312 |
_remove_button_clicked ?
|
|
313 |
CMD_REMOVE_RAILROAD_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) :
|
|
314 |
CMD_BUILD_RAILROAD_TRACK | CMD_AUTO | CMD_NO_WATER | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK)
|
|
315 |
);
|
|
316 |
}
|
|
317 |
|
|
318 |
typedef struct {
|
|
319 |
byte bit, a,b, mouse;
|
|
320 |
} BestFitStruct;
|
|
321 |
|
|
322 |
#define M(d,m) (d << 6) | (m)
|
|
323 |
static const BestFitStruct _bestfit[] = {
|
|
324 |
// both edges have rail
|
|
325 |
{2, M(0, 1+8), M(3, 2+8), 0}, // upper track
|
|
326 |
{3, M(2, 1+4), M(1, 2+4), 0}, // lower track
|
|
327 |
|
|
328 |
{4, M(2, 1+32), M(3, 2+32), 1<<2}, // left track
|
|
329 |
{5, M(0, 1+16), M(1, 2+16), 1<<3}, // right track
|
|
330 |
|
|
331 |
{0, M(0,1+8+16), M(2,1+4+32), 0}, // diag1 track
|
|
332 |
{1, M(3,2+8+32), M(1,2+4+16), 0}, // diag2 track
|
|
333 |
|
|
334 |
// one edge with rail
|
|
335 |
{0, M(0,1), 0, 0}, // diag1 track
|
|
336 |
{0, M(2,1), 0, 0}, // diag1 track
|
|
337 |
|
|
338 |
{1, M(1,2), 0, 0}, // diag2 track
|
|
339 |
{1, M(3,2), 0, 0}, // diag2 track
|
|
340 |
|
|
341 |
{2, M(0,8), 0, 1<<0}, // upper track
|
|
342 |
{2, M(3,8), 0, 1<<0}, // upper track
|
|
343 |
|
|
344 |
{3, M(1,4), 0, 1<<1}, // lower track
|
|
345 |
{3, M(2,4), 0, 1<<1}, // lower track
|
|
346 |
|
|
347 |
{4, M(2,32), 0, 1<<2}, // left track
|
|
348 |
{4, M(3,32), 0, 1<<2}, // left track
|
|
349 |
|
|
350 |
{5, M(0,16), 0, 1<<3}, // right track
|
|
351 |
{5, M(1,16), 0, 1<<3}, // right track
|
|
352 |
|
|
353 |
{0xff,0,0},
|
|
354 |
};
|
|
355 |
#undef M
|
|
356 |
|
|
357 |
static int GetBestArea(int x, int y)
|
|
358 |
{
|
|
359 |
int r = 0;
|
|
360 |
if (x + y > 0x10) r += 2;
|
|
361 |
else if (x + y == 0x10) return -1;
|
|
362 |
if (y - x > 0) r += 1;
|
|
363 |
else if (y - x == 0) return -1;
|
|
364 |
return r;
|
|
365 |
}
|
|
366 |
|
|
367 |
int GetBestFit1x1(int x, int y)
|
|
368 |
{
|
|
369 |
byte m[5];
|
|
370 |
const BestFitStruct *bfs;
|
|
371 |
byte mouse;
|
|
372 |
uint tile;
|
|
373 |
int best;
|
|
374 |
int i;
|
|
375 |
|
|
376 |
// determine the mouse regions
|
|
377 |
mouse = ((x & 0xF) + (y & 0xF) < 0x10 ? 1 << 0 : 1 << 1) +
|
|
378 |
((x & 0xF) > (y & 0xF) ? 1 << 2 : 1 << 3);
|
|
379 |
|
|
380 |
// get the rail in each direction
|
|
381 |
tile = TILE_FROM_XY(x,y);
|
|
382 |
for(i=0; i!=5; i++) {
|
|
383 |
static TileIndexDiff _tile_inc[5] = {
|
|
384 |
TILE_XY(-1, 0),
|
|
385 |
TILE_XY(0, 1) - TILE_XY(-1, 0),
|
|
386 |
TILE_XY(1, 0) - TILE_XY(0, 1),
|
|
387 |
TILE_XY(0, -1) - TILE_XY(1, 0),
|
|
388 |
TILE_XY(0, 0) - TILE_XY(0, -1),
|
|
389 |
};
|
|
390 |
tile += _tile_inc[i];
|
|
391 |
m[i] = 0;
|
|
392 |
if (IS_TILETYPE(tile, MP_RAILWAY) && _map5[tile] < 0x80)
|
|
393 |
m[i] = _map5[tile]&0x3F;
|
|
394 |
|
|
395 |
// handle tracks under bridge
|
|
396 |
if(IS_TILETYPE(tile, MP_TUNNELBRIDGE) && (_map5[tile]&0xF8)==0xE0)
|
|
397 |
m[i] = (byte) !(_map5[tile]&0x01) + 1;
|
|
398 |
|
|
399 |
if (_remove_button_clicked) m[i] ^= 0x3F;
|
|
400 |
}
|
|
401 |
|
|
402 |
// check "mouse gesture"?
|
|
403 |
{
|
|
404 |
int a1,a2;
|
|
405 |
if ((a1 = GetBestArea(x & 0xF, y & 0xF)) != -1 && (a2 = GetBestArea(_tile_fract_coords.x, _tile_fract_coords.y)) != -1 && a1 != a2) {
|
|
406 |
static const byte _get_dir_by_areas[4][4] = {
|
|
407 |
{0,2,4,1},
|
|
408 |
{2,0,0,5},
|
|
409 |
{4,0,0,3},
|
|
410 |
{1,5,3,0},
|
|
411 |
};
|
|
412 |
i = _get_dir_by_areas[a2][a1];
|
|
413 |
if (!HASBIT(m[4], i))
|
|
414 |
return i;
|
|
415 |
}
|
|
416 |
}
|
|
417 |
// check each bestfit struct
|
|
418 |
for(bfs = _bestfit, best=-1; bfs->bit != 0xFF; bfs++) {
|
|
419 |
if ((bfs->a & m[bfs->a >> 6]) && (!bfs->b || bfs->b & m[bfs->b >> 6]) && !HASBIT(m[4], bfs->bit)) {
|
|
420 |
if ( (byte)(~mouse & bfs->mouse) == 0)
|
|
421 |
return bfs->bit;
|
|
422 |
if (best != -1)
|
|
423 |
return best;
|
|
424 |
best = bfs->bit;
|
|
425 |
}
|
|
426 |
}
|
|
427 |
|
|
428 |
return best;
|
|
429 |
}
|
|
430 |
|
|
431 |
static void SwapSelection()
|
|
432 |
{
|
|
433 |
TileHighlightData *thd = &_thd;
|
|
434 |
Point pt = thd->selstart;
|
|
435 |
thd->selstart.x = thd->selend.x & ~0xF;
|
|
436 |
thd->selstart.y = thd->selend.y & ~0xF;
|
|
437 |
thd->selend = pt;
|
|
438 |
}
|
|
439 |
|
|
440 |
static bool Check2x1AutoRail(int mode)
|
|
441 |
{
|
|
442 |
TileHighlightData *thd = &_thd;
|
|
443 |
int fxpy = _tile_fract_coords.x + _tile_fract_coords.y;
|
|
444 |
int sxpy = (thd->selend.x & 0xF) + (thd->selend.y & 0xF);
|
|
445 |
int fxmy = _tile_fract_coords.x - _tile_fract_coords.y;
|
|
446 |
int sxmy = (thd->selend.x & 0xF) - (thd->selend.y & 0xF);
|
|
447 |
|
|
448 |
switch(mode) {
|
|
449 |
case 0:
|
|
450 |
if (fxpy >= 20 && sxpy <= 12) { SwapSelection(); DoRailroadTrack(0); return true; }
|
|
451 |
if (fxmy < -3 && sxmy > 3) { DoRailroadTrack(0); return true; }
|
|
452 |
break;
|
|
453 |
|
|
454 |
case 1:
|
|
455 |
if (fxmy > 3 && sxmy < -3) { SwapSelection(); DoRailroadTrack(0); return true; }
|
|
456 |
if (fxpy <= 12 && sxpy >= 20) { DoRailroadTrack(0); return true; }
|
|
457 |
break;
|
|
458 |
|
|
459 |
case 2:
|
|
460 |
if (fxmy > 3 && sxmy < -3) { DoRailroadTrack(3); return true; }
|
|
461 |
if (fxpy >= 20 && sxpy <= 12) { SwapSelection(); DoRailroadTrack(0); return true; }
|
|
462 |
break;
|
|
463 |
|
|
464 |
case 3:
|
|
465 |
if (fxmy < -3 && sxmy > 3) { SwapSelection(); DoRailroadTrack(3); return true; }
|
|
466 |
if (fxpy <= 12 && sxpy >= 20) { DoRailroadTrack(0); return true; }
|
|
467 |
break;
|
|
468 |
}
|
|
469 |
|
|
470 |
return false;
|
|
471 |
}
|
|
472 |
|
|
473 |
|
|
474 |
static void HandleAutodirPlacement()
|
|
475 |
{
|
|
476 |
TileHighlightData *thd = &_thd;
|
|
477 |
int bit;
|
|
478 |
|
|
479 |
if (thd->drawstyle == HT_RECT) {
|
|
480 |
int dx = thd->selstart.x - (thd->selend.x&~0xF);
|
|
481 |
int dy = thd->selstart.y - (thd->selend.y&~0xF);
|
|
482 |
|
|
483 |
if (dx == 0 && dy == 0 ) {
|
|
484 |
// 1x1 tile
|
|
485 |
bit = GetBestFit1x1(thd->selend.x, thd->selend.y);
|
|
486 |
if (bit == -1) return;
|
|
487 |
GenericPlaceRail(TILE_FROM_XY(thd->selend.x, thd->selend.y), bit);
|
|
488 |
} else if (dx == 0) {
|
|
489 |
if (dy == -16) {
|
|
490 |
if (Check2x1AutoRail(0)) return;
|
|
491 |
} else if (dy == 16) {
|
|
492 |
if (Check2x1AutoRail(1)) return;
|
|
493 |
}
|
|
494 |
// same x coordinate
|
|
495 |
DoRailroadTrack(VPM_FIX_X);
|
|
496 |
} else {
|
|
497 |
// same y coordinate
|
|
498 |
// check it's it -16 or 16, then we must check if it should be normal tiles or special tiles.
|
|
499 |
if (dx == -16) {
|
|
500 |
if (Check2x1AutoRail(2)) return;
|
|
501 |
} else if (dx == 16) {
|
|
502 |
if (Check2x1AutoRail(3)) return;
|
|
503 |
}
|
|
504 |
DoRailroadTrack(VPM_FIX_Y);
|
|
505 |
}
|
|
506 |
} else {
|
|
507 |
DoRailroadTrack(thd->drawstyle & 1 ? 0 : 3);
|
|
508 |
}
|
|
509 |
}
|
|
510 |
|
|
511 |
static OnButtonClick * const _build_railroad_button_proc[] = {
|
|
512 |
BuildRailClick_AutoRail,
|
|
513 |
BuildRailClick_N,
|
|
514 |
BuildRailClick_NE,
|
|
515 |
BuildRailClick_E,
|
|
516 |
BuildRailClick_NW,
|
|
517 |
BuildRailClick_Demolish,
|
|
518 |
BuildRailClick_Lower,
|
|
519 |
BuildRailClick_Raise,
|
|
520 |
BuildRailClick_Depot,
|
|
521 |
BuildRailClick_Station,
|
|
522 |
BuildRailClick_Signals,
|
|
523 |
BuildRailClick_Bridge,
|
|
524 |
BuildRailClick_Tunnel,
|
|
525 |
BuildRailClick_Remove,
|
|
526 |
BuildRailClick_Sign,
|
|
527 |
BuildRailClick_Checkpoint,
|
|
528 |
BuildRailClick_Convert,
|
|
529 |
};
|
|
530 |
|
|
531 |
static const uint16 _rail_keycodes[] = {
|
|
532 |
'5',
|
|
533 |
'1',
|
|
534 |
'2',
|
|
535 |
'3',
|
|
536 |
'4',
|
|
537 |
'6',
|
|
538 |
'7',
|
|
539 |
'8',
|
|
540 |
0, // depot
|
|
541 |
0, // station
|
|
542 |
'S',// signals
|
|
543 |
'B',// bridge
|
|
544 |
'T',// tunnel
|
|
545 |
'R',// remove
|
|
546 |
0, // sign
|
|
547 |
'C',// checkpoint
|
|
548 |
};
|
|
549 |
|
|
550 |
|
|
551 |
|
|
552 |
|
|
553 |
static void BuildRailToolbWndProc(Window *w, WindowEvent *e)
|
|
554 |
{
|
|
555 |
switch(e->event) {
|
|
556 |
case WE_PAINT:
|
|
557 |
w->disabled_state &= ~(1 << 16);
|
|
558 |
if (!(w->click_state & ((1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<12)|(1<<13)|(1<<18)))) {
|
|
559 |
w->disabled_state |= (1 << 16);
|
|
560 |
w->click_state &= ~(1<<16);
|
|
561 |
}
|
|
562 |
DrawWindowWidgets(w);
|
|
563 |
break;
|
|
564 |
|
|
565 |
case WE_CLICK:
|
|
566 |
if (e->click.widget >= 3) {
|
|
567 |
_remove_button_clicked = false;
|
|
568 |
_build_railroad_button_proc[e->click.widget - 3](w);
|
|
569 |
}
|
|
570 |
break;
|
|
571 |
|
|
572 |
case WE_KEYPRESS: {
|
|
573 |
int i;
|
|
574 |
for(i=0; i!=lengthof(_rail_keycodes); i++)
|
|
575 |
if (e->keypress.keycode == _rail_keycodes[i]) {
|
|
576 |
e->keypress.cont = false;
|
|
577 |
_remove_button_clicked = false;
|
|
578 |
_build_railroad_button_proc[i](w);
|
|
579 |
break;
|
|
580 |
}
|
|
581 |
break;
|
|
582 |
}
|
|
583 |
|
|
584 |
case WE_PLACE_OBJ:
|
|
585 |
_place_proc(e->place.tile);
|
|
586 |
return;
|
|
587 |
|
|
588 |
case WE_PLACE_DRAG: {
|
|
589 |
VpSelectTilesWithMethod(e->place.pt.x, e->place.pt.y, e->place.userdata & 0xF);
|
|
590 |
return;
|
|
591 |
}
|
|
592 |
|
|
593 |
case WE_PLACE_MOUSEUP:
|
|
594 |
if (e->click.pt.x != -1) {
|
|
595 |
uint start_tile = e->place.starttile;
|
|
596 |
uint end_tile = e->place.tile;
|
|
597 |
|
|
598 |
if (e->place.userdata == VPM_X_OR_Y) {
|
|
599 |
ResetObjectToPlace();
|
|
600 |
ShowBuildBridgeWindow(start_tile, end_tile, _cur_railtype);
|
|
601 |
} else if (e->place.userdata == VPM_RAILDIRS) {
|
|
602 |
bool old = _remove_button_clicked;
|
|
603 |
if (_ctrl_pressed) _remove_button_clicked = true;
|
|
604 |
HandleAutodirPlacement();
|
|
605 |
_remove_button_clicked = old;
|
|
606 |
} else if (e->place.userdata == VPM_X_AND_Y) {
|
|
607 |
DoCommandP(end_tile, start_tile, 0, CcPlaySound10, CMD_CLEAR_AREA | CMD_MSG(STR_00B5_CAN_T_CLEAR_THIS_AREA));
|
|
608 |
} else if (e->place.userdata == (VPM_X_AND_Y | (1<<4))) {
|
|
609 |
DoCommandP(end_tile, start_tile, _cur_railtype, CcPlaySound10, CMD_CONVERT_RAIL | CMD_MSG(STR_CANT_CONVERT_RAIL));
|
|
610 |
} else if (e->place.userdata == (VPM_X_AND_Y | (2<<4))) {
|
|
611 |
DoCommandP(end_tile, start_tile, _cur_railtype, CcPlaySound10, CMD_LEVEL_LAND | CMD_AUTO);
|
|
612 |
} else if (e->place.userdata == VPM_X_AND_Y_LIMITED) {
|
|
613 |
HandleStationPlacement(start_tile, end_tile);
|
|
614 |
} else {
|
|
615 |
DoRailroadTrack(e->place.userdata);
|
|
616 |
}
|
|
617 |
}
|
|
618 |
break;
|
|
619 |
|
|
620 |
case WE_ABORT_PLACE_OBJ:
|
|
621 |
w->click_state = 0;
|
|
622 |
SetWindowDirty(w);
|
|
623 |
|
|
624 |
w = FindWindowById(WC_BUILD_STATION, 0);
|
|
625 |
if (w != NULL) WP(w,def_d).close=true;
|
|
626 |
w = FindWindowById(WC_BUILD_DEPOT, 0);
|
|
627 |
if (w != NULL) WP(w,def_d).close=true;
|
|
628 |
break;
|
|
629 |
|
|
630 |
case WE_PLACE_PRESIZE: {
|
|
631 |
uint tile = e->place.tile;
|
|
632 |
DoCommandByTile(tile, 0, 0, DC_AUTO, CMD_BUILD_TUNNEL);
|
|
633 |
VpSetPresizeRange(tile, _build_tunnel_endtile==0?tile:_build_tunnel_endtile);
|
|
634 |
} break;
|
|
635 |
}
|
|
636 |
}
|
|
637 |
|
|
638 |
static const Widget _build_railroad_widgets[] = {
|
|
639 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
640 |
{ WWT_CAPTION, 7, 11, 417, 0, 13, STR_100A_RAILROAD_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
641 |
|
|
642 |
{ WWT_PANEL, 7, 110, 113, 14, 35, 0x0, 0x0},
|
|
643 |
{ WWT_PANEL, 7, 88, 109, 14, 35, SPR_OPENTTD_BASE + 0, STR_BUILD_AUTORAIL_TIP},
|
|
644 |
|
|
645 |
{ WWT_PANEL, 7, 0, 21, 14, 35, 0x4E3, STR_1018_BUILD_RAILROAD_TRACK},
|
|
646 |
{ WWT_PANEL, 7, 22, 43, 14, 35, 0x4E4, STR_1018_BUILD_RAILROAD_TRACK},
|
|
647 |
{ WWT_PANEL, 7, 44, 65, 14, 35, 0x4E5, STR_1018_BUILD_RAILROAD_TRACK},
|
|
648 |
{ WWT_PANEL, 7, 66, 87, 14, 35, 0x4E6, STR_1018_BUILD_RAILROAD_TRACK},
|
|
649 |
|
|
650 |
{ WWT_PANEL, 7, 114, 135, 14, 35, 0x2BF, STR_018D_DEMOLISH_BUILDINGS_ETC},
|
|
651 |
{ WWT_PANEL, 7, 136, 157, 14, 35, 0x2B7, STR_018E_LOWER_A_CORNER_OF_LAND},
|
|
652 |
{ WWT_PANEL, 7, 158, 179, 14, 35, 0x2B6, STR_018F_RAISE_A_CORNER_OF_LAND},
|
|
653 |
{ WWT_PANEL, 7, 180, 201, 14, 35, 0x50E, STR_1019_BUILD_TRAIN_DEPOT_FOR_BUILDING},
|
|
654 |
|
|
655 |
{ WWT_PANEL, 7, 224, 265, 14, 35, 0x512, STR_101A_BUILD_RAILROAD_STATION},
|
|
656 |
{ WWT_PANEL, 7, 266, 287, 14, 35, 0x50B, STR_101B_BUILD_RAILROAD_SIGNALS},
|
|
657 |
{ WWT_PANEL, 7, 288, 329, 14, 35, 0xA22, STR_101C_BUILD_RAILROAD_BRIDGE},
|
|
658 |
{ WWT_PANEL, 7, 330, 351, 14, 35, 0x97E, STR_101D_BUILD_RAILROAD_TUNNEL},
|
|
659 |
{ WWT_PANEL, 7, 352, 373, 14, 35, 0x2CA, STR_101E_TOGGLE_BUILD_REMOVE_FOR},
|
|
660 |
{ WWT_PANEL, 7, 374, 395, 14, 35, 0x12B7, STR_0329_PURCHASE_LAND_FOR_FUTURE},
|
|
661 |
|
|
662 |
{ WWT_PANEL, 7, 202, 223, 14, 35, SPR_OPENTTD_BASE + 3, STR_CONVERT_RAIL_TO_CHECKPOINT_TIP},
|
|
663 |
{ WWT_PANEL, 7, 396, 417, 14, 35, SPR_OPENTTD_BASE + 25, STR_CONVERT_RAIL_TIP},
|
|
664 |
|
|
665 |
{ WWT_LAST},
|
|
666 |
};
|
|
667 |
|
|
668 |
static const WindowDesc _build_railroad_desc = {
|
|
669 |
640-418, 22, 418, 36,
|
|
670 |
WC_BUILD_TOOLBAR,0,
|
|
671 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
672 |
_build_railroad_widgets,
|
|
673 |
BuildRailToolbWndProc
|
|
674 |
};
|
|
675 |
|
|
676 |
static const Widget _build_monorail_widgets[] = {
|
|
677 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
678 |
{ WWT_CAPTION, 7, 11, 417, 0, 13, STR_100B_MONORAIL_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
679 |
|
|
680 |
{ WWT_PANEL, 7, 110, 113, 14, 35, 0x0, 0x0},
|
|
681 |
{ WWT_PANEL, 7, 88, 109, 14, 35, SPR_OPENTTD_BASE + 1, STR_BUILD_AUTORAIL_TIP},
|
|
682 |
|
|
683 |
{ WWT_PANEL, 7, 0, 21, 14, 35, 0x4E7, STR_1018_BUILD_RAILROAD_TRACK},
|
|
684 |
{ WWT_PANEL, 7, 22, 43, 14, 35, 0x4E8, STR_1018_BUILD_RAILROAD_TRACK},
|
|
685 |
{ WWT_PANEL, 7, 44, 65, 14, 35, 0x4E9, STR_1018_BUILD_RAILROAD_TRACK},
|
|
686 |
{ WWT_PANEL, 7, 66, 87, 14, 35, 0x4EA, STR_1018_BUILD_RAILROAD_TRACK},
|
|
687 |
|
|
688 |
{ WWT_PANEL, 7, 114, 135, 14, 35, 0x2BF, STR_018D_DEMOLISH_BUILDINGS_ETC},
|
|
689 |
{ WWT_PANEL, 7, 136, 157, 14, 35, 0x2B7, STR_018E_LOWER_A_CORNER_OF_LAND},
|
|
690 |
{ WWT_PANEL, 7, 158, 179, 14, 35, 0x2B6, STR_018F_RAISE_A_CORNER_OF_LAND},
|
|
691 |
{ WWT_PANEL, 7, 180, 201, 14, 35, SPR_OPENTTD_BASE + 12, STR_1019_BUILD_TRAIN_DEPOT_FOR_BUILDING},
|
|
692 |
|
|
693 |
{ WWT_PANEL, 7, 224, 265, 14, 35, 0x512, STR_101A_BUILD_RAILROAD_STATION},
|
|
694 |
{ WWT_PANEL, 7, 266, 287, 14, 35, 0x50B, STR_101B_BUILD_RAILROAD_SIGNALS},
|
|
695 |
{ WWT_PANEL, 7, 288, 329, 14, 35, 0xA22, STR_101C_BUILD_RAILROAD_BRIDGE},
|
|
696 |
{ WWT_PANEL, 7, 330, 351, 14, 35, 0x97F, STR_101D_BUILD_RAILROAD_TUNNEL},
|
|
697 |
{ WWT_PANEL, 7, 352, 373, 14, 35, 0x2CA, STR_101E_TOGGLE_BUILD_REMOVE_FOR},
|
|
698 |
{ WWT_PANEL, 7, 374, 395, 14, 35, 0x12B7, STR_0329_PURCHASE_LAND_FOR_FUTURE},
|
|
699 |
|
|
700 |
{ WWT_PANEL, 7, 202, 223, 14, 35, SPR_OPENTTD_BASE + 3, STR_CONVERT_RAIL_TO_CHECKPOINT_TIP},
|
|
701 |
{ WWT_PANEL, 7, 396, 417, 14, 35, SPR_OPENTTD_BASE + 27, STR_CONVERT_RAIL_TIP},
|
|
702 |
{ WWT_LAST},
|
|
703 |
};
|
|
704 |
|
|
705 |
static const WindowDesc _build_monorail_desc = {
|
|
706 |
640-418, 22, 418, 36,
|
|
707 |
WC_BUILD_TOOLBAR,0,
|
|
708 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
709 |
_build_monorail_widgets,
|
|
710 |
BuildRailToolbWndProc
|
|
711 |
};
|
|
712 |
|
|
713 |
static const Widget _build_maglev_widgets[] = {
|
|
714 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
715 |
{ WWT_CAPTION, 7, 11, 417, 0, 13, STR_100C_MAGLEV_CONSTRUCTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
716 |
|
|
717 |
{ WWT_PANEL, 7, 110, 113, 14, 35, 0x0, 0x0},
|
|
718 |
{ WWT_PANEL, 7, 88, 109, 14, 35, SPR_OPENTTD_BASE + 2, STR_BUILD_AUTORAIL_TIP},
|
|
719 |
|
|
720 |
{ WWT_PANEL, 7, 0, 21, 14, 35, 0x4EB, STR_1018_BUILD_RAILROAD_TRACK},
|
|
721 |
{ WWT_PANEL, 7, 22, 43, 14, 35, 0x4EC, STR_1018_BUILD_RAILROAD_TRACK},
|
|
722 |
{ WWT_PANEL, 7, 44, 65, 14, 35, 0x4EE, STR_1018_BUILD_RAILROAD_TRACK},
|
|
723 |
{ WWT_PANEL, 7, 66, 87, 14, 35, 0x4ED, STR_1018_BUILD_RAILROAD_TRACK},
|
|
724 |
|
|
725 |
{ WWT_PANEL, 7, 114, 135, 14, 35, 0x2BF, STR_018D_DEMOLISH_BUILDINGS_ETC},
|
|
726 |
{ WWT_PANEL, 7, 136, 157, 14, 35, 0x2B7, STR_018E_LOWER_A_CORNER_OF_LAND},
|
|
727 |
{ WWT_PANEL, 7, 158, 179, 14, 35, 0x2B6, STR_018F_RAISE_A_CORNER_OF_LAND},
|
|
728 |
{ WWT_PANEL, 7, 180, 201, 14, 35, SPR_OPENTTD_BASE + 13, STR_1019_BUILD_TRAIN_DEPOT_FOR_BUILDING},
|
|
729 |
|
|
730 |
{ WWT_PANEL, 7, 224, 265, 14, 35, 0x512, STR_101A_BUILD_RAILROAD_STATION},
|
|
731 |
{ WWT_PANEL, 7, 266, 287, 14, 35, 0x50B, STR_101B_BUILD_RAILROAD_SIGNALS},
|
|
732 |
{ WWT_PANEL, 7, 288, 329, 14, 35, 0xA22, STR_101C_BUILD_RAILROAD_BRIDGE},
|
|
733 |
{ WWT_PANEL, 7, 330, 351, 14, 35, 0x980, STR_101D_BUILD_RAILROAD_TUNNEL},
|
|
734 |
{ WWT_PANEL, 7, 352, 373, 14, 35, 0x2CA, STR_101E_TOGGLE_BUILD_REMOVE_FOR},
|
|
735 |
{ WWT_PANEL, 7, 374, 395, 14, 35, 0x12B7, STR_0329_PURCHASE_LAND_FOR_FUTURE},
|
|
736 |
|
|
737 |
{ WWT_PANEL, 7, 202, 223, 14, 35, SPR_OPENTTD_BASE + 3, STR_CONVERT_RAIL_TO_CHECKPOINT_TIP},
|
|
738 |
{ WWT_PANEL, 7, 396, 417, 14, 35, SPR_OPENTTD_BASE + 29, STR_CONVERT_RAIL_TIP},
|
|
739 |
{ WWT_LAST},
|
|
740 |
};
|
|
741 |
|
|
742 |
static const WindowDesc _build_maglev_desc = {
|
|
743 |
640-418, 22, 418, 36,
|
|
744 |
WC_BUILD_TOOLBAR,0,
|
|
745 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
746 |
_build_maglev_widgets,
|
|
747 |
BuildRailToolbWndProc
|
|
748 |
};
|
|
749 |
|
|
750 |
|
|
751 |
static const WindowDesc * const _build_rr_desc[] = {
|
|
752 |
&_build_railroad_desc,
|
|
753 |
&_build_monorail_desc,
|
|
754 |
&_build_maglev_desc,
|
|
755 |
};
|
|
756 |
|
|
757 |
void ShowBuildRailToolbar(int index, int button)
|
|
758 |
{
|
|
759 |
Window *w;
|
|
760 |
|
|
761 |
// don't recreate the window if we're clicking on a button and the window exists.
|
|
762 |
if (button < 0 || !(w = FindWindowById(WC_BUILD_TOOLBAR, 0)) || w->wndproc != BuildRailToolbWndProc) {
|
|
763 |
DeleteWindowById(WC_BUILD_TOOLBAR, 0);
|
|
764 |
_cur_railtype = (byte)index;
|
|
765 |
w = AllocateWindowDesc(_build_rr_desc[index]);
|
|
766 |
}
|
|
767 |
|
|
768 |
if (w != NULL && button >= 0) _build_railroad_button_proc[button](w);
|
|
769 |
}
|
|
770 |
|
|
771 |
static void HandleStationPlacement(uint start, uint end)
|
|
772 |
{
|
|
773 |
uint sx = GET_TILE_X(start);
|
|
774 |
uint sy = GET_TILE_Y(start);
|
|
775 |
uint ex = GET_TILE_X(end);
|
|
776 |
uint ey = GET_TILE_Y(end);
|
|
777 |
uint w,h;
|
|
778 |
|
|
779 |
if (sx > ex) intswap(sx,ex);
|
|
780 |
if (sy > ey) intswap(sy,ey);
|
|
781 |
w = ex - sx + 1;
|
|
782 |
h = ey - sy + 1;
|
|
783 |
if (!_railstation.orientation) intswap(w,h);
|
|
784 |
|
|
785 |
DoCommandP(TILE_XY(sx,sy), _railstation.orientation | (w<<8) | (h<<16),_cur_railtype, CcStation,
|
|
786 |
CMD_BUILD_RAILROAD_STATION | CMD_NO_WATER | CMD_AUTO | CMD_MSG(STR_100F_CAN_T_BUILD_RAILROAD_STATION));
|
|
787 |
}
|
|
788 |
|
|
789 |
static void StationBuildWndProc(Window *w, WindowEvent *e) {
|
|
790 |
switch(e->event) {
|
|
791 |
case WE_PAINT: {
|
|
792 |
uint bits;
|
|
793 |
|
|
794 |
if (WP(w,def_d).close)
|
|
795 |
return;
|
|
796 |
|
|
797 |
bits = (1<<3) << ( _railstation.orientation);
|
|
798 |
if (_railstation.dragdrop) {
|
|
799 |
bits |= (1<<19);
|
|
800 |
} else {
|
|
801 |
bits |= (1<<(5-1)) << (_railstation.numtracks);
|
|
802 |
bits |= (1<<(12-1)) << (_railstation.platlength);
|
|
803 |
}
|
|
804 |
bits |= (1<<20) << (_station_show_coverage);
|
|
805 |
w->click_state = bits;
|
|
806 |
|
|
807 |
if (_railstation.dragdrop) {
|
|
808 |
SetTileSelectSize(1, 1);
|
|
809 |
} else {
|
|
810 |
int x = _railstation.numtracks;
|
|
811 |
int y = _railstation.platlength;
|
|
812 |
if (_railstation.orientation == 0) intswap(x,y);
|
|
813 |
if(!_remove_button_clicked)
|
|
814 |
SetTileSelectSize(x, y);
|
|
815 |
}
|
|
816 |
|
|
817 |
if (_station_show_coverage)
|
|
818 |
SetTileSelectBigSize(-4, -4, 8, 8);
|
|
819 |
|
|
820 |
DrawWindowWidgets(w);
|
|
821 |
|
|
822 |
StationPickerDrawSprite(39, 42, _cur_railtype, 2);
|
|
823 |
StationPickerDrawSprite(107, 42, _cur_railtype, 3);
|
|
824 |
|
|
825 |
DrawStringCentered(74, 15, STR_3002_ORIENTATION, 0);
|
|
826 |
DrawStringCentered(74, 76, STR_3003_NUMBER_OF_TRACKS, 0);
|
|
827 |
DrawStringCentered(74, 101, STR_3004_PLATFORM_LENGTH, 0);
|
|
828 |
DrawStringCentered(74, 141, STR_3066_COVERAGE_AREA_HIGHLIGHT, 0);
|
|
829 |
|
|
830 |
DrawStationCoverageAreaText(2, 166, (uint)-1);
|
|
831 |
} break;
|
|
832 |
|
|
833 |
case WE_CLICK: {
|
|
834 |
switch(e->click.widget) {
|
|
835 |
case 0:
|
|
836 |
ResetObjectToPlace();
|
|
837 |
break;
|
|
838 |
case 3:
|
|
839 |
case 4:
|
|
840 |
_railstation.orientation = e->click.widget - 3;
|
|
841 |
SndPlayFx(0x13);
|
|
842 |
SetWindowDirty(w);
|
|
843 |
break;
|
|
844 |
|
|
845 |
case 5:
|
|
846 |
case 6:
|
|
847 |
case 7:
|
|
848 |
case 8:
|
|
849 |
case 9:
|
|
850 |
case 10:
|
|
851 |
case 11:
|
|
852 |
_railstation.numtracks = (e->click.widget - 5) + 1;
|
|
853 |
_railstation.dragdrop = false;
|
|
854 |
SndPlayFx(0x13);
|
|
855 |
SetWindowDirty(w);
|
|
856 |
break;
|
|
857 |
|
|
858 |
case 12:
|
|
859 |
case 13:
|
|
860 |
case 14:
|
|
861 |
case 15:
|
|
862 |
case 16:
|
|
863 |
case 17:
|
|
864 |
case 18:
|
|
865 |
_railstation.platlength = (e->click.widget - 12) + 1;
|
|
866 |
_railstation.dragdrop = false;
|
|
867 |
SndPlayFx(0x13);
|
|
868 |
SetWindowDirty(w);
|
|
869 |
break;
|
|
870 |
|
|
871 |
case 19:
|
|
872 |
_railstation.dragdrop ^= true;
|
|
873 |
SndPlayFx(0x13);
|
|
874 |
SetWindowDirty(w);
|
|
875 |
break;
|
|
876 |
|
|
877 |
case 20:
|
|
878 |
case 21:
|
|
879 |
_station_show_coverage = e->click.widget - 20;
|
|
880 |
SndPlayFx(0x13);
|
|
881 |
SetWindowDirty(w);
|
|
882 |
break;
|
|
883 |
}
|
|
884 |
} break;
|
|
885 |
|
|
886 |
case WE_MOUSELOOP: {
|
|
887 |
if (WP(w,def_d).close) {
|
|
888 |
DeleteWindow(w);
|
|
889 |
return;
|
|
890 |
}
|
|
891 |
CheckRedrawStationCoverage(w);
|
|
892 |
} break;
|
|
893 |
}
|
|
894 |
}
|
|
895 |
|
|
896 |
static const Widget _station_builder_widgets[] = {
|
|
897 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
898 |
{ WWT_CAPTION, 7, 11, 147, 0, 13, STR_3000_RAIL_STATION_SELECTION, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
899 |
{ WWT_PANEL, 7, 0, 147, 14, 199, 0x0, 0},
|
|
900 |
{ WWT_PANEL, 14, 7, 72, 26, 73, 0x0, STR_304E_SELECT_RAILROAD_STATION},
|
|
901 |
{ WWT_PANEL, 14, 75, 140, 26, 73, 0x0, STR_304E_SELECT_RAILROAD_STATION},
|
|
902 |
|
|
903 |
{ WWT_CLOSEBOX, 14, 22, 36, 87, 98, STR_00CB_1, STR_304F_SELECT_NUMBER_OF_PLATFORMS},
|
|
904 |
{ WWT_CLOSEBOX, 14, 37, 51, 87, 98, STR_00CC_2, STR_304F_SELECT_NUMBER_OF_PLATFORMS},
|
|
905 |
{ WWT_CLOSEBOX, 14, 52, 66, 87, 98, STR_00CD_3, STR_304F_SELECT_NUMBER_OF_PLATFORMS},
|
|
906 |
{ WWT_CLOSEBOX, 14, 67, 81, 87, 98, STR_00CE_4, STR_304F_SELECT_NUMBER_OF_PLATFORMS},
|
|
907 |
{ WWT_CLOSEBOX, 14, 82, 96, 87, 98, STR_00CF_5, STR_304F_SELECT_NUMBER_OF_PLATFORMS},
|
|
908 |
{ WWT_CLOSEBOX, 14, 97, 111, 87, 98, STR_0335_6, STR_304F_SELECT_NUMBER_OF_PLATFORMS},
|
|
909 |
{ WWT_CLOSEBOX, 14, 112, 126, 87, 98, STR_0336_7, STR_304F_SELECT_NUMBER_OF_PLATFORMS},
|
|
910 |
|
|
911 |
{ WWT_CLOSEBOX, 14, 22, 36, 112, 123, STR_00CB_1, STR_3050_SELECT_LENGTH_OF_RAILROAD},
|
|
912 |
{ WWT_CLOSEBOX, 14, 37, 51, 112, 123, STR_00CC_2, STR_3050_SELECT_LENGTH_OF_RAILROAD},
|
|
913 |
{ WWT_CLOSEBOX, 14, 52, 66, 112, 123, STR_00CD_3, STR_3050_SELECT_LENGTH_OF_RAILROAD},
|
|
914 |
{ WWT_CLOSEBOX, 14, 67, 81, 112, 123, STR_00CE_4, STR_3050_SELECT_LENGTH_OF_RAILROAD},
|
|
915 |
{ WWT_CLOSEBOX, 14, 82, 96, 112, 123, STR_00CF_5, STR_3050_SELECT_LENGTH_OF_RAILROAD},
|
|
916 |
{ WWT_CLOSEBOX, 14, 97, 111, 112, 123, STR_0335_6, STR_3050_SELECT_LENGTH_OF_RAILROAD},
|
|
917 |
{ WWT_CLOSEBOX, 14, 112, 126, 112, 123, STR_0336_7, STR_3050_SELECT_LENGTH_OF_RAILROAD},
|
|
918 |
|
|
919 |
//{ WWT_CLOSEBOX, 14, 14, 73, 137, 148, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE},
|
|
920 |
//{ WWT_CLOSEBOX, 14, 74, 133, 137, 148, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA},
|
|
921 |
{ WWT_CLOSEBOX, 14, 37, 111, 126, 137, STR_DRAG_DROP, STR_STATION_DRAG_DROP},
|
|
922 |
{ WWT_CLOSEBOX, 14, 14, 73, 152, 163, STR_02DB_OFF, STR_3065_DON_T_HIGHLIGHT_COVERAGE},
|
|
923 |
{ WWT_CLOSEBOX, 14, 74, 133, 152, 163, STR_02DA_ON, STR_3064_HIGHLIGHT_COVERAGE_AREA},
|
|
924 |
{ WWT_LAST},
|
|
925 |
};
|
|
926 |
|
|
927 |
static const WindowDesc _station_builder_desc = {
|
|
928 |
-1, -1, 148, 200,
|
|
929 |
WC_BUILD_STATION,WC_BUILD_TOOLBAR,
|
|
930 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
931 |
_station_builder_widgets,
|
|
932 |
StationBuildWndProc
|
|
933 |
};
|
|
934 |
|
|
935 |
static void ShowStationBuilder()
|
|
936 |
{
|
|
937 |
AllocateWindowDesc(&_station_builder_desc);
|
|
938 |
}
|
|
939 |
|
|
940 |
static void BuildTrainDepotWndProc(Window *w, WindowEvent *e)
|
|
941 |
{
|
|
942 |
switch(e->event) {
|
|
943 |
case WE_PAINT: {
|
|
944 |
int r;
|
|
945 |
|
|
946 |
w->click_state = (1 << 3) << _build_depot_direction;
|
|
947 |
DrawWindowWidgets(w);
|
|
948 |
|
|
949 |
r = _cur_railtype;
|
|
950 |
DrawTrainDepotSprite(70, 17, 0, r);
|
|
951 |
DrawTrainDepotSprite(70, 69, 1, r);
|
|
952 |
DrawTrainDepotSprite(2, 69, 2, r);
|
|
953 |
DrawTrainDepotSprite(2, 17, 3, r);
|
|
954 |
break;
|
|
955 |
}
|
|
956 |
case WE_CLICK: {
|
|
957 |
switch(e->click.widget) {
|
|
958 |
case 0:
|
|
959 |
ResetObjectToPlace();
|
|
960 |
break;
|
|
961 |
case 3:
|
|
962 |
case 4:
|
|
963 |
case 5:
|
|
964 |
case 6:
|
|
965 |
_build_depot_direction = e->click.widget - 3;
|
|
966 |
SndPlayFx(0x13);
|
|
967 |
SetWindowDirty(w);
|
|
968 |
break;
|
|
969 |
}
|
|
970 |
} break;
|
|
971 |
|
|
972 |
case WE_MOUSELOOP:
|
|
973 |
if (WP(w,def_d).close)
|
|
974 |
DeleteWindow(w);
|
|
975 |
return;
|
|
976 |
}
|
|
977 |
}
|
|
978 |
|
|
979 |
static const Widget _build_depot_widgets[] = {
|
|
980 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
981 |
{ WWT_CAPTION, 7, 11, 139, 0, 13, STR_1014_TRAIN_DEPOT_ORIENTATION,STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
982 |
{ WWT_PANEL, 7, 0, 139, 14, 121, 0x0, 0},
|
|
983 |
{ WWT_PANEL, 14, 71, 136, 17, 66, 0x0, STR_1020_SELECT_RAILROAD_DEPOT_ORIENTATIO},
|
|
984 |
{ WWT_PANEL, 14, 71, 136, 69, 118, 0x0, STR_1020_SELECT_RAILROAD_DEPOT_ORIENTATIO},
|
|
985 |
{ WWT_PANEL, 14, 3, 68, 69, 118, 0x0, STR_1020_SELECT_RAILROAD_DEPOT_ORIENTATIO},
|
|
986 |
{ WWT_PANEL, 14, 3, 68, 17, 66, 0x0, STR_1020_SELECT_RAILROAD_DEPOT_ORIENTATIO},
|
|
987 |
{ WWT_LAST},
|
|
988 |
};
|
|
989 |
|
|
990 |
static const WindowDesc _build_depot_desc = {
|
|
991 |
-1,-1, 140, 122,
|
|
992 |
WC_BUILD_DEPOT,WC_BUILD_TOOLBAR,
|
|
993 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
994 |
_build_depot_widgets,
|
|
995 |
BuildTrainDepotWndProc
|
|
996 |
};
|
|
997 |
|
|
998 |
static void ShowBuildTrainDepotPicker()
|
|
999 |
{
|
|
1000 |
AllocateWindowDesc(&_build_depot_desc);
|
|
1001 |
}
|
|
1002 |
|
|
1003 |
void InitializeRailGui()
|
|
1004 |
{
|
|
1005 |
_build_depot_direction = 3;
|
|
1006 |
_railstation.numtracks = 1;
|
|
1007 |
_railstation.platlength = 1;
|
|
1008 |
_railstation.dragdrop = true;
|
|
1009 |
}
|