author | truebrain |
Fri, 13 Jun 2008 19:57:25 +0000 | |
branch | noai |
changeset 10957 | 7a140b4cd91d |
parent 10920 | e33442a2b239 |
child 11044 | 097ea3e7ec56 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6443
b8f06d8eb7be
(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:
6182
diff
changeset
|
3 |
/** @file bridge_gui.cpp Graphical user interface for bridge construction */ |
2262
bd59b2d8d75f
(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
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1781
diff
changeset
|
6 |
#include "openttd.h" |
0 | 7 |
#include "gui.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
8 |
#include "window_gui.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
9 |
#include "command_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
10 |
#include "economy_func.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2133
diff
changeset
|
11 |
#include "variables.h" |
2262
bd59b2d8d75f
(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" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
13 |
#include "strings_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
14 |
#include "window_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
15 |
#include "sound_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
16 |
#include "map_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
17 |
#include "viewport_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
18 |
#include "gfx_func.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
19 |
#include "tunnelbridge.h" |
10645 | 20 |
#include "sortlist_type.h" |
21 |
#include "widgets/dropdown_func.h" |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
22 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
23 |
#include "table/strings.h" |
0 | 24 |
|
10645 | 25 |
/** |
26 |
* Carriage for the data we need if we want to build a bridge |
|
27 |
*/ |
|
28 |
struct BuildBridgeData { |
|
29 |
BridgeType index; |
|
30 |
const BridgeSpec *spec; |
|
31 |
Money cost; |
|
32 |
}; |
|
0 | 33 |
|
10645 | 34 |
typedef GUIList<BuildBridgeData> GUIBridgeList; |
35 |
||
36 |
/** |
|
37 |
* Callback executed after a build Bridge CMD has been called |
|
38 |
* |
|
39 |
* @param scucess True if the build succeded |
|
40 |
* @param tile The tile where the command has been executed |
|
41 |
* @param p1 not used |
|
42 |
* @param p2 not used |
|
43 |
*/ |
|
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1891
diff
changeset
|
44 |
void CcBuildBridge(bool success, TileIndex tile, uint32 p1, uint32 p2) |
0 | 45 |
{ |
541 | 46 |
if (success) SndPlayTileFx(SND_27_BLACKSMITH_ANVIL, tile); |
0 | 47 |
} |
48 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
49 |
/* Names of the build bridge selection window */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
50 |
enum BuildBridgeSelectionWidgets { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
51 |
BBSW_CLOSEBOX = 0, |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
52 |
BBSW_CAPTION, |
10645 | 53 |
BBSW_DROPDOWN_ORDER, |
54 |
BBSW_DROPDOWN_CRITERIA, |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
55 |
BBSW_BRIDGE_LIST, |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
56 |
BBSW_SCROLLBAR, |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
57 |
BBSW_RESIZEBOX |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
58 |
}; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
59 |
|
10645 | 60 |
class BuildBridgeWindow : public Window { |
61 |
private: |
|
10776 | 62 |
/* Runtime saved values */ |
10645 | 63 |
static uint last_size; |
10776 | 64 |
static Listing last_sorting; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
65 |
|
10776 | 66 |
/* Constants for sorting the bridges */ |
67 |
static const StringID sorter_names[]; |
|
68 |
static GUIBridgeList::SortFunction *const sorter_funcs[]; |
|
69 |
||
70 |
/* Internal variables */ |
|
10645 | 71 |
TileIndex start_tile; |
72 |
TileIndex end_tile; |
|
73 |
uint32 type; |
|
74 |
GUIBridgeList *bridges; |
|
0 | 75 |
|
10776 | 76 |
/** Sort the bridges by their index */ |
77 |
static int CDECL BridgeIndexSorter(const BuildBridgeData *a, const BuildBridgeData *b) |
|
78 |
{ |
|
79 |
return a->index - b->index; |
|
80 |
} |
|
81 |
||
82 |
/** Sort the bridges by their price */ |
|
83 |
static int CDECL BridgePriceSorter(const BuildBridgeData *a, const BuildBridgeData *b) |
|
84 |
{ |
|
85 |
return a->cost - b->cost; |
|
86 |
} |
|
87 |
||
88 |
/** Sort the bridges by their maximum speed */ |
|
89 |
static int CDECL BridgeSpeedSorter(const BuildBridgeData *a, const BuildBridgeData *b) |
|
90 |
{ |
|
91 |
return a->spec->speed - b->spec->speed; |
|
92 |
} |
|
93 |
||
10645 | 94 |
void BuildBridge(uint8 i) |
95 |
{ |
|
10776 | 96 |
DoCommandP(this->end_tile, this->start_tile, this->type | this->bridges->Get(i)->index, |
10645 | 97 |
CcBuildBridge, CMD_BUILD_BRIDGE | CMD_MSG(STR_5015_CAN_T_BUILD_BRIDGE_HERE)); |
98 |
} |
|
0 | 99 |
|
10645 | 100 |
/** Sort the builable bridges */ |
101 |
void SortBridgeList() |
|
102 |
{ |
|
10776 | 103 |
this->bridges->Sort(); |
10645 | 104 |
|
105 |
/* Display the current sort variant */ |
|
10776 | 106 |
this->widget[BBSW_DROPDOWN_CRITERIA].data = this->sorter_names[this->bridges->SortType()]; |
10645 | 107 |
|
108 |
/* Set the modified widgets dirty */ |
|
109 |
this->InvalidateWidget(BBSW_DROPDOWN_CRITERIA); |
|
110 |
this->InvalidateWidget(BBSW_BRIDGE_LIST); |
|
111 |
} |
|
112 |
||
113 |
public: |
|
114 |
BuildBridgeWindow(const WindowDesc *desc, TileIndex start, TileIndex end, uint32 br_type, GUIBridgeList *bl) : Window(desc), |
|
115 |
start_tile(start), |
|
116 |
end_tile(end), |
|
117 |
type(br_type), |
|
118 |
bridges(bl) |
|
119 |
{ |
|
10776 | 120 |
this->bridges->SetListing(this->last_sorting); |
121 |
this->bridges->SetSortFuncs(this->sorter_funcs); |
|
10920 | 122 |
this->bridges->NeedResort(); |
10645 | 123 |
this->SortBridgeList(); |
124 |
||
125 |
/* Change the data, or the caption of the gui. Set it to road or rail, accordingly */ |
|
126 |
this->widget[BBSW_CAPTION].data = (GB(this->type, 15, 2) == TRANSPORT_ROAD) ? STR_1803_SELECT_ROAD_BRIDGE : STR_100D_SELECT_RAIL_BRIDGE; |
|
127 |
||
128 |
this->resize.step_height = 22; |
|
10776 | 129 |
this->vscroll.count = bl->Length(); |
10645 | 130 |
|
131 |
if (this->last_size <= 4) { |
|
132 |
this->vscroll.cap = 4; |
|
133 |
} else { |
|
134 |
/* Resize the bridge selection window if we used a bigger one the last time */ |
|
135 |
this->vscroll.cap = (this->vscroll.count > this->last_size) ? this->last_size : this->vscroll.count; |
|
136 |
ResizeWindow(this, 0, (this->vscroll.cap - 4) * this->resize.step_height); |
|
137 |
this->widget[BBSW_BRIDGE_LIST].data = (this->vscroll.cap << 8) + 1; |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
138 |
} |
6530
c43fa965e8ae
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6443
diff
changeset
|
139 |
|
10645 | 140 |
this->FindWindowPlacementAndResize(desc); |
141 |
} |
|
6530
c43fa965e8ae
(svn r8990) -Fix: more indenting and variable scoping
peter1138
parents:
6443
diff
changeset
|
142 |
|
10645 | 143 |
~BuildBridgeWindow() |
144 |
{ |
|
10776 | 145 |
this->last_sorting = this->bridges->GetListing(); |
146 |
||
10645 | 147 |
delete bridges; |
148 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
176
diff
changeset
|
149 |
|
10645 | 150 |
virtual void OnPaint() |
151 |
{ |
|
152 |
this->DrawWidgets(); |
|
153 |
||
154 |
this->DrawSortButtonState(BBSW_DROPDOWN_ORDER, (this->bridges->flags & VL_DESC) ? SBS_DOWN : SBS_UP); |
|
155 |
||
156 |
uint y = this->widget[BBSW_BRIDGE_LIST].top + 2; |
|
157 |
||
10776 | 158 |
for (int i = this->vscroll.pos; (i < (this->vscroll.cap + this->vscroll.pos)) && (i < (int)this->bridges->Length()); i++) { |
159 |
const BridgeSpec *b = this->bridges->Get(i)->spec; |
|
10645 | 160 |
|
10776 | 161 |
SetDParam(2, this->bridges->Get(i)->cost); |
10645 | 162 |
SetDParam(1, b->speed * 10 / 16); |
163 |
SetDParam(0, b->material); |
|
164 |
||
165 |
DrawSprite(b->sprite, b->pal, 3, y); |
|
166 |
DrawString(44, y, STR_500D, TC_FROMSTRING); |
|
167 |
y += this->resize.step_height; |
|
168 |
||
169 |
} |
|
170 |
} |
|
171 |
||
172 |
virtual EventState OnKeyPress(uint16 key, uint16 keycode) |
|
173 |
{ |
|
174 |
const uint8 i = keycode - '1'; |
|
10776 | 175 |
if (i < 9 && i < this->bridges->Length()) { |
10645 | 176 |
/* Build the requested bridge */ |
177 |
this->BuildBridge(i); |
|
178 |
delete this; |
|
179 |
return ES_HANDLED; |
|
180 |
} |
|
181 |
return ES_NOT_HANDLED; |
|
182 |
} |
|
183 |
||
184 |
virtual void OnClick(Point pt, int widget) |
|
185 |
{ |
|
186 |
switch (widget) { |
|
187 |
default: break; |
|
188 |
case BBSW_BRIDGE_LIST: { |
|
189 |
uint i = ((int)pt.y - this->widget[BBSW_BRIDGE_LIST].top) / this->resize.step_height; |
|
190 |
if (i < this->vscroll.cap) { |
|
191 |
i += this->vscroll.pos; |
|
10776 | 192 |
if (i < this->bridges->Length()) { |
10645 | 193 |
this->BuildBridge(i); |
194 |
delete this; |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
195 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
196 |
} |
10645 | 197 |
} break; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
198 |
|
10645 | 199 |
case BBSW_DROPDOWN_ORDER: |
10776 | 200 |
this->bridges->ToggleSortOrder(); |
201 |
this->SetDirty(); |
|
10645 | 202 |
break; |
203 |
||
204 |
case BBSW_DROPDOWN_CRITERIA: |
|
10776 | 205 |
ShowDropDownMenu(this, this->sorter_names, this->bridges->SortType(), BBSW_DROPDOWN_CRITERIA, 0, 0); |
10645 | 206 |
break; |
207 |
} |
|
0 | 208 |
} |
10645 | 209 |
|
210 |
virtual void OnDropdownSelect(int widget, int index) |
|
211 |
{ |
|
10776 | 212 |
if (widget == BBSW_DROPDOWN_CRITERIA && this->bridges->SortType() != index) { |
213 |
this->bridges->SetSortType(index); |
|
10645 | 214 |
|
215 |
this->SortBridgeList(); |
|
216 |
} |
|
217 |
} |
|
218 |
||
219 |
virtual void OnResize(Point new_size, Point delta) |
|
220 |
{ |
|
221 |
this->vscroll.cap += delta.y / (int)this->resize.step_height; |
|
222 |
this->widget[BBSW_BRIDGE_LIST].data = (this->vscroll.cap << 8) + 1; |
|
10776 | 223 |
SetVScrollCount(this, this->bridges->Length()); |
10645 | 224 |
|
225 |
this->last_size = this->vscroll.cap; |
|
226 |
} |
|
227 |
}; |
|
228 |
||
229 |
/* Set the default size of the Build Bridge Window */ |
|
230 |
uint BuildBridgeWindow::last_size = 4; |
|
10776 | 231 |
/* Set the default sorting for the bridges */ |
232 |
Listing BuildBridgeWindow::last_sorting = {false, 0}; |
|
233 |
||
234 |
/* Availible bridge sorting functions */ |
|
235 |
GUIBridgeList::SortFunction* const BuildBridgeWindow::sorter_funcs[] = { |
|
236 |
&BridgeIndexSorter, |
|
237 |
&BridgePriceSorter, |
|
238 |
&BridgeSpeedSorter |
|
239 |
}; |
|
240 |
||
241 |
/* Names of the sorting functions */ |
|
242 |
const StringID BuildBridgeWindow::sorter_names[] = { |
|
243 |
STR_SORT_BY_NUMBER, |
|
244 |
STR_ENGINE_SORT_COST, |
|
245 |
STR_SORT_BY_MAX_SPEED, |
|
246 |
INVALID_STRING_ID |
|
247 |
}; |
|
0 | 248 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
249 |
/* Widget definition for the rail bridge selection window */ |
0 | 250 |
static const Widget _build_bridge_widgets[] = { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
251 |
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // BBSW_CLOSEBOX |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
252 |
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 199, 0, 13, STR_100D_SELECT_RAIL_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS}, // BBSW_CAPTION |
10645 | 253 |
|
254 |
{ WWT_TEXTBTN, RESIZE_NONE, 7, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP}, // BBSW_DROPDOWN_ORDER |
|
255 |
{ WWT_DROPDOWN, RESIZE_NONE, 7, 81, 199, 14, 25, 0x0, STR_SORT_CRITERIA_TIP}, // BBSW_DROPDOWN_CRITERIA |
|
256 |
||
257 |
{ WWT_MATRIX, RESIZE_BOTTOM, 7, 0, 187, 26, 113, 0x401, STR_101F_BRIDGE_SELECTION_CLICK}, // BBSW_BRIDGE_LIST |
|
258 |
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 7, 188, 199, 26, 101, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // BBSW_SCROLLBAR |
|
259 |
{ WWT_RESIZEBOX, RESIZE_TB, 7, 188, 199, 102, 113, 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
|
260 |
{ WIDGETS_END}, |
0 | 261 |
}; |
262 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
263 |
/* Window definition for the rail bridge selection window */ |
0 | 264 |
static const WindowDesc _build_bridge_desc = { |
10645 | 265 |
WDP_AUTO, WDP_AUTO, 200, 114, 200, 114, |
5070
0bbf5264bfb7
(svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents:
4634
diff
changeset
|
266 |
WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR, |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
267 |
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE, |
0 | 268 |
_build_bridge_widgets, |
269 |
}; |
|
270 |
||
10645 | 271 |
/** |
272 |
* Prepare the data for the build a bridge window. |
|
273 |
* If we can't build a bridge under the given conditions |
|
274 |
* show an error message. |
|
275 |
* |
|
276 |
* @parma start The start tile of the bridge |
|
277 |
* @param end The end tile of the bridge |
|
278 |
* @param transport_type The transport type |
|
279 |
* @param bridge_type The bridge type |
|
280 |
*/ |
|
9732 | 281 |
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, byte bridge_type) |
0 | 282 |
{ |
283 |
DeleteWindowById(WC_BUILD_BRIDGE, 0); |
|
284 |
||
10645 | 285 |
/* Data type for the bridge. |
286 |
* Bit 16,15 = transport type, |
|
287 |
* 14..8 = road/rail pieces, |
|
288 |
* 7..0 = type of bridge */ |
|
289 |
uint32 type = (transport_type << 15) | (bridge_type << 8); |
|
0 | 290 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
291 |
/* only query bridge building possibility once, result is the same for all bridges! |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
292 |
* returns CMD_ERROR on failure, and price on success */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
293 |
StringID errmsg = INVALID_STRING_ID; |
10645 | 294 |
CommandCost ret = DoCommand(end, start, type, DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE); |
0 | 295 |
|
10645 | 296 |
GUIBridgeList *bl = NULL; |
2737
f16e0a808897
(svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents:
2639
diff
changeset
|
297 |
if (CmdFailed(ret)) { |
0 | 298 |
errmsg = _error_message; |
2548
97ada3bd2702
(svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents:
2470
diff
changeset
|
299 |
} else { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
300 |
/* check which bridges can be built |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
301 |
* get absolute bridge length |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
302 |
* length of the middle parts of the bridge */ |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
303 |
const uint bridge_len = GetTunnelBridgeLength(start, end); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
304 |
/* total length of bridge */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
305 |
const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2); |
0 | 306 |
|
10776 | 307 |
bl = new GUIBridgeList(); |
308 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
309 |
/* loop for all bridgetypes */ |
9732 | 310 |
for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) { |
311 |
if (CheckBridge_Stuff(brd_type, bridge_len)) { |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
312 |
/* bridge is accepted, add to list */ |
10776 | 313 |
BuildBridgeData *item = bl->Append(); |
314 |
item->index = brd_type; |
|
315 |
item->spec = GetBridgeSpec(brd_type); |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
316 |
/* Add to terraforming & bulldozing costs the cost of the |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
317 |
* bridge itself (not computed with DC_QUERY_COST) */ |
10776 | 318 |
item->cost = ret.GetCost() + (((int64)tot_bridgedata_len * _price.build_bridge * item->spec->price) >> 8); |
0 | 319 |
} |
320 |
} |
|
321 |
} |
|
322 |
||
10776 | 323 |
if (bl != NULL && bl->Length() != 0) { |
10645 | 324 |
new BuildBridgeWindow(&_build_bridge_desc, start, end, type, bl); |
0 | 325 |
} else { |
10776 | 326 |
if (bl != NULL) delete bl; |
3422
12cdb13ddb56
(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
|
327 |
ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE); |
0 | 328 |
} |
329 |
} |