author | rubidium |
Sat, 17 May 2008 12:48:06 +0000 | |
changeset 9273 | 35e0224ea8f1 |
parent 9142 | 858a058aa730 |
child 9283 | dbccc281c38a |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6117
6507b2a7e71d
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
5931
diff
changeset
|
3 |
/** @file bridge_gui.cpp Graphical user interface for bridge construction */ |
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2186
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1781
diff
changeset
|
6 |
#include "openttd.h" |
0 | 7 |
#include "gui.h" |
8107
bb7deea89175
(svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents:
8106
diff
changeset
|
8 |
#include "window_gui.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
9 |
#include "command_func.h" |
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8114
diff
changeset
|
10 |
#include "economy_func.h" |
2159
f6284cf5fab0
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2133
diff
changeset
|
11 |
#include "variables.h" |
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2186
diff
changeset
|
12 |
#include "bridge.h" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8107
diff
changeset
|
13 |
#include "strings_func.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8121
diff
changeset
|
14 |
#include "window_func.h" |
8157
1505def01945
(svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents:
8139
diff
changeset
|
15 |
#include "sound_func.h" |
8139
4e91c448c409
(svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents:
8131
diff
changeset
|
16 |
#include "map_func.h" |
8224
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8157
diff
changeset
|
17 |
#include "viewport_func.h" |
c5a64d87cc54
(svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents:
8157
diff
changeset
|
18 |
#include "gfx_func.h" |
8398
1e181e2e4e15
(svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents:
8264
diff
changeset
|
19 |
#include "tunnelbridge.h" |
0 | 20 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8224
diff
changeset
|
21 |
#include "table/strings.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8224
diff
changeset
|
22 |
|
0 | 23 |
static struct BridgeData { |
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
24 |
uint8 last_size; |
2133 | 25 |
uint count; |
0 | 26 |
TileIndex start_tile; |
27 |
TileIndex end_tile; |
|
8557
d5fb341fc220
(svn r12135) -Codechange: Road and rail bridge selection windows were identical apart the caption. So remove one window definition and set manually the caption accordingly.
belugas
parents:
8535
diff
changeset
|
28 |
uint32 type; ///< Data type for the bridge. Bit 16,15 = transport type, 14..8 = road/rail pieces, 7..0 = type of bridge |
8532
ebe68d6899b6
(svn r12107) -Codechange: Add and use the typedef BridgeType
belugas
parents:
8491
diff
changeset
|
29 |
BridgeType indexes[MAX_BRIDGES]; |
6990
136a08baf0ed
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
rubidium
parents:
6950
diff
changeset
|
30 |
Money costs[MAX_BRIDGES]; |
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
31 |
|
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
32 |
BridgeData() |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
33 |
: last_size(4) |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
34 |
, count(0) |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
35 |
{}; |
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2186
diff
changeset
|
36 |
} _bridgedata; |
0 | 37 |
|
1977
37bbebf94434
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
38 |
void CcBuildBridge(bool success, TileIndex tile, uint32 p1, uint32 p2) |
0 | 39 |
{ |
541 | 40 |
if (success) SndPlayTileFx(SND_27_BLACKSMITH_ANVIL, tile); |
0 | 41 |
} |
42 |
||
43 |
static void BuildBridge(Window *w, int i) |
|
44 |
{ |
|
9115
47ae980bace3
(svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents:
8558
diff
changeset
|
45 |
delete w; |
2639 | 46 |
DoCommandP(_bridgedata.end_tile, _bridgedata.start_tile, |
8557
d5fb341fc220
(svn r12135) -Codechange: Road and rail bridge selection windows were identical apart the caption. So remove one window definition and set manually the caption accordingly.
belugas
parents:
8535
diff
changeset
|
47 |
_bridgedata.type | _bridgedata.indexes[i], CcBuildBridge, |
7521
0da1e91510e4
(svn r11040) -Fix [FS#1179]: removing CMD_AUTO from some commands could remotely trigger an assertion.
rubidium
parents:
7341
diff
changeset
|
48 |
CMD_BUILD_BRIDGE | CMD_MSG(STR_5015_CAN_T_BUILD_BRIDGE_HERE)); |
0 | 49 |
} |
50 |
||
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
51 |
/* Names of the build bridge selection window */ |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
52 |
enum BuildBridgeSelectionWidgets { |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
53 |
BBSW_CLOSEBOX = 0, |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
54 |
BBSW_CAPTION, |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
55 |
BBSW_BRIDGE_LIST, |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
56 |
BBSW_SCROLLBAR, |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
57 |
BBSW_RESIZEBOX |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
58 |
}; |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
59 |
|
0 | 60 |
static void BuildBridgeWndProc(Window *w, WindowEvent *e) |
61 |
{ |
|
2952 | 62 |
switch (e->event) { |
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
63 |
case WE_CREATE: |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
64 |
w->resize.step_height = 22; |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
65 |
w->vscroll.count = _bridgedata.count; |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
66 |
|
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
67 |
if (_bridgedata.last_size <= 4) { |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
68 |
w->vscroll.cap = 4; |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
69 |
} else { |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
70 |
/* Resize the bridge selection window if we used a bigger one the last time */ |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
71 |
w->vscroll.cap = (w->vscroll.count > _bridgedata.last_size) ? _bridgedata.last_size : w->vscroll.count; |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
72 |
ResizeWindow(w, 0, (w->vscroll.cap - 4) * w->resize.step_height); |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
73 |
w->widget[BBSW_BRIDGE_LIST].data = (w->vscroll.cap << 8) + 1; |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
74 |
} |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
75 |
break; |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
76 |
|
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
77 |
case WE_PAINT: { |
9273
35e0224ea8f1
(svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents:
9142
diff
changeset
|
78 |
w->DrawWidgets(); |
0 | 79 |
|
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
80 |
uint y = 15; |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
81 |
for (uint i = 0; (i < w->vscroll.cap) && ((i + w->vscroll.pos) < _bridgedata.count); i++) { |
8535
ef36a2eb9345
(svn r12111) -Codechange: Rename Bridge to BridgeSpec, out of consistensy with other Specs in used.
belugas
parents:
8532
diff
changeset
|
82 |
const BridgeSpec *b = GetBridgeSpec(_bridgedata.indexes[i + w->vscroll.pos]); |
0 | 83 |
|
7002
1bf6a62b0fcb
(svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents:
6991
diff
changeset
|
84 |
SetDParam(2, _bridgedata.costs[i + w->vscroll.pos]); |
6204
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
85 |
SetDParam(1, b->speed * 10 / 16); |
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
86 |
SetDParam(0, b->material); |
0 | 87 |
|
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
88 |
DrawSprite(b->sprite, b->pal, 3, y); |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
89 |
DrawString(44, y, STR_500D, TC_FROMSTRING); |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
90 |
y += w->resize.step_height; |
6204
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
91 |
} |
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
92 |
break; |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
93 |
} |
6204
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
94 |
|
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
95 |
case WE_KEYPRESS: { |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
96 |
const uint8 i = e->we.keypress.keycode - '1'; |
6204
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
97 |
if (i < 9 && i < _bridgedata.count) { |
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
98 |
e->we.keypress.cont = false; |
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
99 |
BuildBridge(w, i); |
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
100 |
} |
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
101 |
|
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
102 |
break; |
0 | 103 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
104 |
|
6204
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
105 |
case WE_CLICK: |
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
106 |
if (e->we.click.widget == BBSW_BRIDGE_LIST) { |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
107 |
uint ind = ((int)e->we.click.pt.y - 14) / w->resize.step_height; |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
108 |
if (ind < w->vscroll.cap) { |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
109 |
ind += w->vscroll.pos; |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
110 |
if (ind < _bridgedata.count) { |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
111 |
BuildBridge(w, ind); |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
112 |
} |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
113 |
} |
6204
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
114 |
} |
8cfc3aebfa3a
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6117
diff
changeset
|
115 |
break; |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
116 |
|
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
117 |
case WE_RESIZE: |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
118 |
w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height; |
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
119 |
w->widget[BBSW_BRIDGE_LIST].data = (w->vscroll.cap << 8) + 1; |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
120 |
SetVScrollCount(w, _bridgedata.count); |
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
121 |
|
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
122 |
_bridgedata.last_size = w->vscroll.cap; |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
123 |
break; |
0 | 124 |
} |
125 |
} |
|
126 |
||
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
127 |
/* Widget definition for the rail bridge selection window */ |
0 | 128 |
static const Widget _build_bridge_widgets[] = { |
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
129 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // BBSW_CLOSEBOX |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
130 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 199, 0, 13, STR_100D_SELECT_RAIL_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS}, // BBSW_CAPTION |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
131 |
{ WWT_MATRIX, RESIZE_BOTTOM, 7, 0, 187, 14, 101, 0x401, STR_101F_BRIDGE_SELECTION_CLICK}, // BBSW_BRIDGE_LIST |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
132 |
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 7, 188, 199, 14, 89, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // BBSW_SCROLLBAR |
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
133 |
{ WWT_RESIZEBOX, RESIZE_TB, 7, 188, 199, 90, 101, 0x0, STR_RESIZE_BUTTON}, // BBSW_RESIZEBOX |
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
0
diff
changeset
|
134 |
{ WIDGETS_END}, |
0 | 135 |
}; |
136 |
||
8020
ba100ceda5b4
(svn r11580) -Feature: Memorise the resizing of the build bridge selection window during runtime
skidd13
parents:
7983
diff
changeset
|
137 |
/* Window definition for the rail bridge selection window */ |
0 | 138 |
static const WindowDesc _build_bridge_desc = { |
7341
02515d0d4ced
(svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents:
7266
diff
changeset
|
139 |
WDP_AUTO, WDP_AUTO, 200, 102, 200, 102, |
5070
7f5b13b7e728
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4634
diff
changeset
|
140 |
WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR, |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
141 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE, |
0 | 142 |
_build_bridge_widgets, |
143 |
BuildBridgeWndProc |
|
144 |
}; |
|
145 |
||
8557
d5fb341fc220
(svn r12135) -Codechange: Road and rail bridge selection windows were identical apart the caption. So remove one window definition and set manually the caption accordingly.
belugas
parents:
8535
diff
changeset
|
146 |
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte bridge_type) |
0 | 147 |
{ |
148 |
DeleteWindowById(WC_BUILD_BRIDGE, 0); |
|
149 |
||
8558
2f50ad3af2a9
(svn r12136) -Fix(r12135): Code style compliance and... code style as such
belugas
parents:
8557
diff
changeset
|
150 |
_bridgedata.type = (transport_type << 15) | (bridge_type << 8); //prepare the parameter for use only once |
2262
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2186
diff
changeset
|
151 |
_bridgedata.start_tile = start; |
252cfd94c54d
(svn r2782) -Codechange: Started cleaning the bridge code. Removed numerous global variables containing bridge information and joined them in a struct. Introduced GetBridgeType and GetBridgePiece and fixed some minor stuff (whitespace etc)
celestar
parents:
2186
diff
changeset
|
152 |
_bridgedata.end_tile = end; |
0 | 153 |
|
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
154 |
/* only query bridge building possibility once, result is the same for all bridges! |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
155 |
* returns CMD_ERROR on failure, and price on success */ |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
156 |
StringID errmsg = INVALID_STRING_ID; |
8557
d5fb341fc220
(svn r12135) -Codechange: Road and rail bridge selection windows were identical apart the caption. So remove one window definition and set manually the caption accordingly.
belugas
parents:
8535
diff
changeset
|
157 |
CommandCost ret = DoCommand(end, start, _bridgedata.type, DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE); |
0 | 158 |
|
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
159 |
uint8 j = 0; |
2737
fb1556b8f5e0
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2639
diff
changeset
|
160 |
if (CmdFailed(ret)) { |
0 | 161 |
errmsg = _error_message; |
2548
49c8a096033f
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2470
diff
changeset
|
162 |
} else { |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
163 |
/* check which bridges can be built |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
164 |
* get absolute bridge length |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
165 |
* length of the middle parts of the bridge */ |
8398
1e181e2e4e15
(svn r11968) -Codechange: remove redundant FindLengthOfTunnel(), use GetTunnelBridgeLength() and/or GetOtherTunnelEnd() instead
smatz
parents:
8264
diff
changeset
|
166 |
const uint bridge_len = GetTunnelBridgeLength(start, end); |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
167 |
/* total length of bridge */ |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
168 |
const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2); |
0 | 169 |
|
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
170 |
/* loop for all bridgetypes */ |
8532
ebe68d6899b6
(svn r12107) -Codechange: Add and use the typedef BridgeType
belugas
parents:
8491
diff
changeset
|
171 |
for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) { |
ebe68d6899b6
(svn r12107) -Codechange: Add and use the typedef BridgeType
belugas
parents:
8491
diff
changeset
|
172 |
if (CheckBridge_Stuff(brd_type, bridge_len)) { |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
173 |
/* bridge is accepted, add to list */ |
8535
ef36a2eb9345
(svn r12111) -Codechange: Rename Bridge to BridgeSpec, out of consistensy with other Specs in used.
belugas
parents:
8532
diff
changeset
|
174 |
const BridgeSpec *b = GetBridgeSpec(brd_type); |
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
175 |
/* Add to terraforming & bulldozing costs the cost of the |
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
176 |
* bridge itself (not computed with DC_QUERY_COST) */ |
6950
14ecb0acdfb4
(svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents:
6943
diff
changeset
|
177 |
_bridgedata.costs[j] = ret.GetCost() + (((int64)tot_bridgedata_len * _price.build_bridge * b->price) >> 8); |
8532
ebe68d6899b6
(svn r12107) -Codechange: Add and use the typedef BridgeType
belugas
parents:
8491
diff
changeset
|
178 |
_bridgedata.indexes[j] = brd_type; |
0 | 179 |
j++; |
180 |
} |
|
181 |
} |
|
7983
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
182 |
|
3b1fec9d5e31
(svn r11539) -Feature: Make the bridge selection window resizable
skidd13
parents:
7824
diff
changeset
|
183 |
_bridgedata.count = j; |
0 | 184 |
} |
185 |
||
186 |
if (j != 0) { |
|
9142
858a058aa730
(svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents:
9115
diff
changeset
|
187 |
Window *w = new Window(&_build_bridge_desc); |
8557
d5fb341fc220
(svn r12135) -Codechange: Road and rail bridge selection windows were identical apart the caption. So remove one window definition and set manually the caption accordingly.
belugas
parents:
8535
diff
changeset
|
188 |
/* Change the data, or the caption of the gui. Set it to road or rail, accordingly */ |
d5fb341fc220
(svn r12135) -Codechange: Road and rail bridge selection windows were identical apart the caption. So remove one window definition and set manually the caption accordingly.
belugas
parents:
8535
diff
changeset
|
189 |
w->widget[BBSW_CAPTION].data = (transport_type == TRANSPORT_ROAD) ? STR_1803_SELECT_ROAD_BRIDGE : STR_100D_SELECT_RAIL_BRIDGE; |
0 | 190 |
} else { |
3422
a6eba3443452
(svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents:
2952
diff
changeset
|
191 |
ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE); |
0 | 192 |
} |
193 |
} |