author | truelight |
Fri, 10 Sep 2004 19:02:27 +0000 | |
changeset 193 | 0a7025304867 |
parent 176 | 84990c4b9212 |
child 200 | 03b8104d1479 |
permissions | -rw-r--r-- |
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 |
||
10 |
static struct BridgeData { |
|
11 |
int count; |
|
12 |
TileIndex start_tile; |
|
13 |
TileIndex end_tile; |
|
14 |
byte type; |
|
15 |
byte indexes[MAX_BRIDGES]; |
|
16 |
int32 costs[MAX_BRIDGES]; |
|
17 |
} _bridge; |
|
18 |
||
19 |
extern const uint16 _bridge_type_price_mod[MAX_BRIDGES]; |
|
20 |
||
21 |
extern const PalSpriteID _bridge_sprites[MAX_BRIDGES]; |
|
22 |
extern const uint16 _bridge_speeds[MAX_BRIDGES]; |
|
23 |
extern const StringID _bridge_material[MAX_BRIDGES]; |
|
24 |
||
25 |
static void CcBuildBridge(bool success, uint tile, uint32 p1, uint32 p2) |
|
26 |
{ |
|
27 |
if (success) { SndPlayTileFx(0x25, tile); } |
|
28 |
} |
|
29 |
||
30 |
static void BuildBridge(Window *w, int i) |
|
31 |
{ |
|
32 |
DeleteWindow(w); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
33 |
DoCommandP(_bridge.end_tile, _bridge.start_tile, _bridge.indexes[i] | (_bridge.type << 8), CcBuildBridge, |
0 | 34 |
CMD_BUILD_BRIDGE | CMD_AUTO | CMD_MSG(STR_5015_CAN_T_BUILD_BRIDGE_HERE)); |
35 |
} |
|
36 |
||
37 |
static void BuildBridgeWndProc(Window *w, WindowEvent *e) |
|
38 |
{ |
|
39 |
switch(e->event) { |
|
40 |
case WE_PAINT: { |
|
41 |
int i; |
|
42 |
||
43 |
DrawWindowWidgets(w); |
|
44 |
||
45 |
for(i=0; i < 4 && i + w->vscroll.pos < _bridge.count; i++) { |
|
46 |
int ind = _bridge.indexes[i + w->vscroll.pos]; |
|
47 |
||
48 |
SET_DPARAM32(2, _bridge.costs[i + w->vscroll.pos]); |
|
49 |
SET_DPARAM16(1, (_bridge_speeds[ind] >> 4) * 10); |
|
50 |
SET_DPARAM16(0, _bridge_material[ind]); |
|
51 |
DrawSprite(_bridge_sprites[ind], 3, 15 + i * 22); |
|
52 |
||
53 |
DrawString(44, 15 + i*22 , STR_500D, 0); |
|
54 |
} |
|
55 |
} break; |
|
56 |
||
57 |
case WE_KEYPRESS: { |
|
58 |
uint i = e->keypress.keycode - '1'; |
|
59 |
if (i < 9 && i < (uint)_bridge.count) { |
|
60 |
e->keypress.cont = false; |
|
61 |
BuildBridge(w, i); |
|
62 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
63 |
|
0 | 64 |
break; |
65 |
} |
|
66 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
67 |
case WE_CLICK: |
0 | 68 |
if (e->click.widget == 2) { |
69 |
uint ind = ((int)e->click.pt.y - 14) / 22; |
|
70 |
if (ind < 4 && (ind += w->vscroll.pos) < (uint)_bridge.count) |
|
71 |
BuildBridge(w, ind); |
|
72 |
} |
|
73 |
break; |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
static const Widget _build_bridge_widgets[] = { |
|
78 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
79 |
{ WWT_CAPTION, 7, 11, 199, 0, 13, STR_100D_SELECT_RAIL_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
80 |
{ WWT_MATRIX, 7, 0, 188, 14, 101, 0x401, STR_101F_BRIDGE_SELECTION_CLICK}, |
|
81 |
{ WWT_SCROLLBAR, 7, 189, 199, 14, 101, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
0
diff
changeset
|
82 |
{ WIDGETS_END}, |
0 | 83 |
}; |
84 |
||
85 |
static const WindowDesc _build_bridge_desc = { |
|
86 |
-1, -1, 200, 102, |
|
87 |
WC_BUILD_BRIDGE,WC_BUILD_TOOLBAR, |
|
88 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
89 |
_build_bridge_widgets, |
|
90 |
BuildBridgeWndProc |
|
91 |
}; |
|
92 |
||
93 |
||
94 |
static const Widget _build_road_bridge_widgets[] = { |
|
95 |
{ WWT_CLOSEBOX, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
|
96 |
{ WWT_CAPTION, 7, 11, 199, 0, 13, STR_1803_SELECT_ROAD_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
|
97 |
{ WWT_MATRIX, 7, 0, 188, 14, 101, 0x401, STR_101F_BRIDGE_SELECTION_CLICK}, |
|
98 |
{ WWT_SCROLLBAR, 7, 189, 199, 14, 101, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
|
176
84990c4b9212
(svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents:
0
diff
changeset
|
99 |
{ WIDGETS_END}, |
0 | 100 |
}; |
101 |
||
102 |
static const WindowDesc _build_road_bridge_desc = { |
|
103 |
-1, -1, 200, 102, |
|
104 |
WC_BUILD_BRIDGE,WC_BUILD_TOOLBAR, |
|
105 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
106 |
_build_road_bridge_widgets, |
|
107 |
BuildBridgeWndProc |
|
108 |
}; |
|
109 |
||
110 |
||
111 |
void ShowBuildBridgeWindow(uint start, uint end, byte bridge_type) |
|
112 |
{ |
|
113 |
int j = 0; |
|
114 |
int32 ret; |
|
115 |
uint16 errmsg; |
|
116 |
||
117 |
DeleteWindowById(WC_BUILD_BRIDGE, 0); |
|
118 |
||
119 |
_bridge.type = bridge_type; |
|
120 |
_bridge.start_tile = start; |
|
121 |
_bridge.end_tile = end; |
|
122 |
||
123 |
errmsg = 0xFFFF; |
|
124 |
||
125 |
// only query bridge building possibility once, result is the same for all bridges! |
|
126 |
// returns CMD_ERROR on failure, and priCe on success |
|
127 |
ret = DoCommandByTile(end, start, (bridge_type << 8), DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE); |
|
128 |
||
129 |
if (ret == CMD_ERROR) { |
|
130 |
errmsg = _error_message; |
|
131 |
} |
|
132 |
// check which bridges can be built |
|
133 |
else { |
|
134 |
int bridge_len; // length of the middle parts of the bridge |
|
135 |
int tot_bridge_len; // total length of bridge |
|
136 |
||
137 |
// get absolute bridge length |
|
138 |
bridge_len = GetBridgeLength(start, end); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
139 |
tot_bridge_len = bridge_len + 2; |
0 | 140 |
|
141 |
tot_bridge_len = CalcBridgeLenCostFactor(tot_bridge_len); |
|
142 |
||
143 |
for (bridge_type = 0; bridge_type != MAX_BRIDGES; bridge_type++) { // loop for all bridgetypes |
|
144 |
||
145 |
if (CheckBridge_Stuff(bridge_type, bridge_len)) { |
|
146 |
// bridge is accepted, add to list |
|
147 |
// add to terraforming & bulldozing costs the cost of the bridge itself (not computed with DC_QUERY_COST) |
|
148 |
_bridge.costs[j] = ret + (((tot_bridge_len * _price.build_bridge) * _bridge_type_price_mod[bridge_type]) >> 8); |
|
149 |
_bridge.indexes[j] = bridge_type; |
|
150 |
j++; |
|
151 |
} |
|
152 |
} |
|
153 |
} |
|
154 |
||
155 |
_bridge.count = j; |
|
156 |
||
157 |
if (j != 0) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
158 |
Window *w = AllocateWindowDesc((_bridge.type & 0x80) ? &_build_road_bridge_desc : &_build_bridge_desc); |
0 | 159 |
w->vscroll.cap = 4; |
160 |
w->vscroll.count = (byte)j; |
|
161 |
} else { |
|
162 |
ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, GET_TILE_X(end) * 16, GET_TILE_Y(end) * 16); |
|
163 |
} |
|
164 |
} |