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