author | tron |
Mon, 14 Feb 2005 18:55:10 +0000 | |
changeset 1370 | c86b2c30fd01 |
parent 926 | a6d140a6a4de |
child 1781 | 5e2fef482637 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
337
diff
changeset
|
3 |
#include "table/strings.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
543
diff
changeset
|
4 |
#include "map.h" |
0 | 5 |
#include "window.h" |
6 |
#include "gui.h" |
|
7 |
#include "viewport.h" |
|
8 |
#include "gfx.h" |
|
9 |
#include "command.h" |
|
337
cbe0c766c947
(svn r513) Merge revisions 402, 416, 417, 478, 479, 511, 512 from map to trunk
tron
parents:
203
diff
changeset
|
10 |
#include "sound.h" |
0 | 11 |
|
12 |
static struct BridgeData { |
|
13 |
int count; |
|
14 |
TileIndex start_tile; |
|
15 |
TileIndex end_tile; |
|
16 |
byte type; |
|
17 |
byte indexes[MAX_BRIDGES]; |
|
18 |
int32 costs[MAX_BRIDGES]; |
|
19 |
} _bridge; |
|
20 |
||
21 |
extern const uint16 _bridge_type_price_mod[MAX_BRIDGES]; |
|
22 |
||
23 |
extern const PalSpriteID _bridge_sprites[MAX_BRIDGES]; |
|
24 |
extern const uint16 _bridge_speeds[MAX_BRIDGES]; |
|
25 |
extern const StringID _bridge_material[MAX_BRIDGES]; |
|
26 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
541
diff
changeset
|
27 |
void CcBuildBridge(bool success, uint tile, uint32 p1, uint32 p2) |
0 | 28 |
{ |
541 | 29 |
if (success) SndPlayTileFx(SND_27_BLACKSMITH_ANVIL, tile); |
0 | 30 |
} |
31 |
||
32 |
static void BuildBridge(Window *w, int i) |
|
33 |
{ |
|
34 |
DeleteWindow(w); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
35 |
DoCommandP(_bridge.end_tile, _bridge.start_tile, _bridge.indexes[i] | (_bridge.type << 8), CcBuildBridge, |
0 | 36 |
CMD_BUILD_BRIDGE | CMD_AUTO | CMD_MSG(STR_5015_CAN_T_BUILD_BRIDGE_HERE)); |
37 |
} |
|
38 |
||
39 |
static void BuildBridgeWndProc(Window *w, WindowEvent *e) |
|
40 |
{ |
|
41 |
switch(e->event) { |
|
42 |
case WE_PAINT: { |
|
43 |
int i; |
|
44 |
||
45 |
DrawWindowWidgets(w); |
|
46 |
||
47 |
for(i=0; i < 4 && i + w->vscroll.pos < _bridge.count; i++) { |
|
48 |
int ind = _bridge.indexes[i + w->vscroll.pos]; |
|
49 |
||
534
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
50 |
SetDParam(2, _bridge.costs[i + w->vscroll.pos]); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
51 |
SetDParam(1, (_bridge_speeds[ind] >> 4) * 10); |
306bc86eb23e
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
52 |
SetDParam(0, _bridge_material[ind]); |
0 | 53 |
DrawSprite(_bridge_sprites[ind], 3, 15 + i * 22); |
54 |
||
55 |
DrawString(44, 15 + i*22 , STR_500D, 0); |
|
56 |
} |
|
57 |
} break; |
|
58 |
||
59 |
case WE_KEYPRESS: { |
|
60 |
uint i = e->keypress.keycode - '1'; |
|
61 |
if (i < 9 && i < (uint)_bridge.count) { |
|
62 |
e->keypress.cont = false; |
|
63 |
BuildBridge(w, i); |
|
64 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
65 |
|
0 | 66 |
break; |
67 |
} |
|
68 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
69 |
case WE_CLICK: |
0 | 70 |
if (e->click.widget == 2) { |
71 |
uint ind = ((int)e->click.pt.y - 14) / 22; |
|
72 |
if (ind < 4 && (ind += w->vscroll.pos) < (uint)_bridge.count) |
|
73 |
BuildBridge(w, ind); |
|
74 |
} |
|
75 |
break; |
|
76 |
} |
|
77 |
} |
|
78 |
||
79 |
static const Widget _build_bridge_widgets[] = { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
679
diff
changeset
|
80 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
679
diff
changeset
|
81 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 199, 0, 13, STR_100D_SELECT_RAIL_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
894
8b59c639837d
(svn r1380) -Fix: missed widget fixes; thanks Jango and TestMan57
darkvater
parents:
867
diff
changeset
|
82 |
{ WWT_MATRIX, RESIZE_NONE, 7, 0, 187, 14, 101, 0x401, STR_101F_BRIDGE_SELECTION_CLICK}, |
8b59c639837d
(svn r1380) -Fix: missed widget fixes; thanks Jango and TestMan57
darkvater
parents:
867
diff
changeset
|
83 |
{ WWT_SCROLLBAR, RESIZE_NONE, 7, 188, 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
|
84 |
{ WIDGETS_END}, |
0 | 85 |
}; |
86 |
||
87 |
static const WindowDesc _build_bridge_desc = { |
|
88 |
-1, -1, 200, 102, |
|
89 |
WC_BUILD_BRIDGE,WC_BUILD_TOOLBAR, |
|
90 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
91 |
_build_bridge_widgets, |
|
92 |
BuildBridgeWndProc |
|
93 |
}; |
|
94 |
||
95 |
||
96 |
static const Widget _build_road_bridge_widgets[] = { |
|
867
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
679
diff
changeset
|
97 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, |
dffd33233237
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
679
diff
changeset
|
98 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 199, 0, 13, STR_1803_SELECT_ROAD_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
908 | 99 |
{ WWT_MATRIX, RESIZE_NONE, 7, 0, 187, 14, 101, 0x401, STR_101F_BRIDGE_SELECTION_CLICK}, |
100 |
{ WWT_SCROLLBAR, RESIZE_NONE, 7, 188, 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
|
101 |
{ WIDGETS_END}, |
0 | 102 |
}; |
103 |
||
104 |
static const WindowDesc _build_road_bridge_desc = { |
|
105 |
-1, -1, 200, 102, |
|
106 |
WC_BUILD_BRIDGE,WC_BUILD_TOOLBAR, |
|
107 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET, |
|
108 |
_build_road_bridge_widgets, |
|
109 |
BuildBridgeWndProc |
|
110 |
}; |
|
111 |
||
112 |
||
113 |
void ShowBuildBridgeWindow(uint start, uint end, byte bridge_type) |
|
114 |
{ |
|
115 |
int j = 0; |
|
116 |
int32 ret; |
|
117 |
uint16 errmsg; |
|
118 |
||
119 |
DeleteWindowById(WC_BUILD_BRIDGE, 0); |
|
120 |
||
121 |
_bridge.type = bridge_type; |
|
122 |
_bridge.start_tile = start; |
|
123 |
_bridge.end_tile = end; |
|
124 |
||
125 |
errmsg = 0xFFFF; |
|
126 |
||
127 |
// only query bridge building possibility once, result is the same for all bridges! |
|
128 |
// returns CMD_ERROR on failure, and priCe on success |
|
129 |
ret = DoCommandByTile(end, start, (bridge_type << 8), DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE); |
|
130 |
||
131 |
if (ret == CMD_ERROR) { |
|
132 |
errmsg = _error_message; |
|
133 |
} |
|
134 |
// check which bridges can be built |
|
135 |
else { |
|
136 |
int bridge_len; // length of the middle parts of the bridge |
|
137 |
int tot_bridge_len; // total length of bridge |
|
138 |
||
139 |
// get absolute bridge length |
|
140 |
bridge_len = GetBridgeLength(start, end); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
141 |
tot_bridge_len = bridge_len + 2; |
0 | 142 |
|
143 |
tot_bridge_len = CalcBridgeLenCostFactor(tot_bridge_len); |
|
144 |
||
145 |
for (bridge_type = 0; bridge_type != MAX_BRIDGES; bridge_type++) { // loop for all bridgetypes |
|
146 |
||
147 |
if (CheckBridge_Stuff(bridge_type, bridge_len)) { |
|
148 |
// bridge is accepted, add to list |
|
149 |
// 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
|
150 |
_bridge.costs[j] = ret + (((int64)tot_bridge_len * _price.build_bridge * _bridge_type_price_mod[bridge_type]) >> 8); |
0 | 151 |
_bridge.indexes[j] = bridge_type; |
152 |
j++; |
|
153 |
} |
|
154 |
} |
|
155 |
} |
|
156 |
||
157 |
_bridge.count = j; |
|
158 |
||
159 |
if (j != 0) { |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
160 |
Window *w = AllocateWindowDesc((_bridge.type & 0x80) ? &_build_road_bridge_desc : &_build_bridge_desc); |
0 | 161 |
w->vscroll.cap = 4; |
162 |
w->vscroll.count = (byte)j; |
|
163 |
} else { |
|
926
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
908
diff
changeset
|
164 |
ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, |
a6d140a6a4de
(svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents:
908
diff
changeset
|
165 |
TileX(end) * 16, TileY(end) * 16); |
0 | 166 |
} |
167 |
} |