|
|
@ -21,8 +21,8 @@ static struct BridgeData {
|
|
|
|
uint count;
|
|
|
|
uint count;
|
|
|
|
TileIndex start_tile;
|
|
|
|
TileIndex start_tile;
|
|
|
|
TileIndex end_tile;
|
|
|
|
TileIndex end_tile;
|
|
|
|
byte type;
|
|
|
|
uint8 type;
|
|
|
|
byte indexes[MAX_BRIDGES];
|
|
|
|
uint8 indexes[MAX_BRIDGES];
|
|
|
|
Money costs[MAX_BRIDGES];
|
|
|
|
Money costs[MAX_BRIDGES];
|
|
|
|
} _bridgedata;
|
|
|
|
} _bridgedata;
|
|
|
|
|
|
|
|
|
|
|
@ -42,23 +42,26 @@ static void BuildBridge(Window *w, int i)
|
|
|
|
static void BuildBridgeWndProc(Window *w, WindowEvent *e)
|
|
|
|
static void BuildBridgeWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
switch (e->event) {
|
|
|
|
switch (e->event) {
|
|
|
|
case WE_PAINT:
|
|
|
|
case WE_PAINT: {
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
|
|
|
|
for (uint i = 0; i < 4 && i + w->vscroll.pos < _bridgedata.count; i++) {
|
|
|
|
uint y = 15;
|
|
|
|
|
|
|
|
for (uint i = 0; (i < w->vscroll.cap) && ((i + w->vscroll.pos) < _bridgedata.count); i++) {
|
|
|
|
const Bridge *b = &_bridge[_bridgedata.indexes[i + w->vscroll.pos]];
|
|
|
|
const Bridge *b = &_bridge[_bridgedata.indexes[i + w->vscroll.pos]];
|
|
|
|
|
|
|
|
|
|
|
|
SetDParam(2, _bridgedata.costs[i + w->vscroll.pos]);
|
|
|
|
SetDParam(2, _bridgedata.costs[i + w->vscroll.pos]);
|
|
|
|
SetDParam(1, b->speed * 10 / 16);
|
|
|
|
SetDParam(1, b->speed * 10 / 16);
|
|
|
|
SetDParam(0, b->material);
|
|
|
|
SetDParam(0, b->material);
|
|
|
|
DrawSprite(b->sprite, b->pal, 3, 15 + i * 22);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DrawString(44, 15 + i * 22 , STR_500D, TC_FROMSTRING);
|
|
|
|
DrawSprite(b->sprite, b->pal, 3, y);
|
|
|
|
|
|
|
|
DrawString(44, y, STR_500D, TC_FROMSTRING);
|
|
|
|
|
|
|
|
y += w->resize.step_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case WE_KEYPRESS: {
|
|
|
|
case WE_KEYPRESS: {
|
|
|
|
uint i = e->we.keypress.keycode - '1';
|
|
|
|
const uint8 i = e->we.keypress.keycode - '1';
|
|
|
|
if (i < 9 && i < _bridgedata.count) {
|
|
|
|
if (i < 9 && i < _bridgedata.count) {
|
|
|
|
e->we.keypress.cont = false;
|
|
|
|
e->we.keypress.cont = false;
|
|
|
|
BuildBridge(w, i);
|
|
|
|
BuildBridge(w, i);
|
|
|
@ -69,10 +72,20 @@ static void BuildBridgeWndProc(Window *w, WindowEvent *e)
|
|
|
|
|
|
|
|
|
|
|
|
case WE_CLICK:
|
|
|
|
case WE_CLICK:
|
|
|
|
if (e->we.click.widget == 2) {
|
|
|
|
if (e->we.click.widget == 2) {
|
|
|
|
uint ind = ((int)e->we.click.pt.y - 14) / 22;
|
|
|
|
uint ind = ((int)e->we.click.pt.y - 14) / w->resize.step_height;
|
|
|
|
if (ind < 4 && (ind += w->vscroll.pos) < _bridgedata.count)
|
|
|
|
if (ind < w->vscroll.cap) {
|
|
|
|
|
|
|
|
ind += w->vscroll.pos;
|
|
|
|
|
|
|
|
if (ind < _bridgedata.count) {
|
|
|
|
BuildBridge(w, ind);
|
|
|
|
BuildBridge(w, ind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case WE_RESIZE:
|
|
|
|
|
|
|
|
w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
|
|
|
|
|
|
|
|
w->widget[2].data = (w->vscroll.cap << 8) + 1;
|
|
|
|
|
|
|
|
SetVScrollCount(w, _bridgedata.count);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -80,15 +93,16 @@ static void BuildBridgeWndProc(Window *w, WindowEvent *e)
|
|
|
|
static const Widget _build_bridge_widgets[] = {
|
|
|
|
static const Widget _build_bridge_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 199, 0, 13, STR_100D_SELECT_RAIL_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 199, 0, 13, STR_100D_SELECT_RAIL_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_MATRIX, RESIZE_NONE, 7, 0, 187, 14, 101, 0x401, STR_101F_BRIDGE_SELECTION_CLICK},
|
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 7, 0, 187, 14, 101, 0x401, STR_101F_BRIDGE_SELECTION_CLICK},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_NONE, 7, 188, 199, 14, 101, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 7, 188, 199, 14, 89, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_TB, 7, 188, 199, 90, 101, 0x0, STR_RESIZE_BUTTON},
|
|
|
|
{ WIDGETS_END},
|
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _build_bridge_desc = {
|
|
|
|
static const WindowDesc _build_bridge_desc = {
|
|
|
|
WDP_AUTO, WDP_AUTO, 200, 102, 200, 102,
|
|
|
|
WDP_AUTO, WDP_AUTO, 200, 102, 200, 102,
|
|
|
|
WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR,
|
|
|
|
WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
|
|
|
|
_build_bridge_widgets,
|
|
|
|
_build_bridge_widgets,
|
|
|
|
BuildBridgeWndProc
|
|
|
|
BuildBridgeWndProc
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -97,15 +111,16 @@ static const WindowDesc _build_bridge_desc = {
|
|
|
|
static const Widget _build_road_bridge_widgets[] = {
|
|
|
|
static const Widget _build_road_bridge_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 7, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 199, 0, 13, STR_1803_SELECT_ROAD_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 7, 11, 199, 0, 13, STR_1803_SELECT_ROAD_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_MATRIX, RESIZE_NONE, 7, 0, 187, 14, 101, 0x401, STR_101F_BRIDGE_SELECTION_CLICK},
|
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 7, 0, 187, 14, 101, 0x401, STR_101F_BRIDGE_SELECTION_CLICK},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_NONE, 7, 188, 199, 14, 101, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 7, 188, 199, 14, 89, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_TB, 7, 188, 199, 90, 101, 0x0, STR_RESIZE_BUTTON},
|
|
|
|
{ WIDGETS_END},
|
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _build_road_bridge_desc = {
|
|
|
|
static const WindowDesc _build_road_bridge_desc = {
|
|
|
|
WDP_AUTO, WDP_AUTO, 200, 102, 200, 102,
|
|
|
|
WDP_AUTO, WDP_AUTO, 200, 102, 200, 102,
|
|
|
|
WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR,
|
|
|
|
WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
|
|
|
|
_build_road_bridge_widgets,
|
|
|
|
_build_road_bridge_widgets,
|
|
|
|
BuildBridgeWndProc
|
|
|
|
BuildBridgeWndProc
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -113,52 +128,49 @@ static const WindowDesc _build_road_bridge_desc = {
|
|
|
|
|
|
|
|
|
|
|
|
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, byte bridge_type)
|
|
|
|
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, byte bridge_type)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint j = 0;
|
|
|
|
|
|
|
|
CommandCost ret;
|
|
|
|
|
|
|
|
StringID errmsg;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeleteWindowById(WC_BUILD_BRIDGE, 0);
|
|
|
|
DeleteWindowById(WC_BUILD_BRIDGE, 0);
|
|
|
|
|
|
|
|
|
|
|
|
_bridgedata.type = bridge_type;
|
|
|
|
_bridgedata.type = bridge_type;
|
|
|
|
_bridgedata.start_tile = start;
|
|
|
|
_bridgedata.start_tile = start;
|
|
|
|
_bridgedata.end_tile = end;
|
|
|
|
_bridgedata.end_tile = end;
|
|
|
|
|
|
|
|
|
|
|
|
errmsg = INVALID_STRING_ID;
|
|
|
|
/* only query bridge building possibility once, result is the same for all bridges!
|
|
|
|
|
|
|
|
* returns CMD_ERROR on failure, and price on success */
|
|
|
|
// only query bridge building possibility once, result is the same for all bridges!
|
|
|
|
StringID errmsg = INVALID_STRING_ID;
|
|
|
|
// returns CMD_ERROR on failure, and price on success
|
|
|
|
CommandCost ret = DoCommand(end, start, (bridge_type << 8), DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE);
|
|
|
|
ret = DoCommand(end, start, (bridge_type << 8), DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8 j = 0;
|
|
|
|
if (CmdFailed(ret)) {
|
|
|
|
if (CmdFailed(ret)) {
|
|
|
|
errmsg = _error_message;
|
|
|
|
errmsg = _error_message;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// check which bridges can be built
|
|
|
|
/* check which bridges can be built
|
|
|
|
// get absolute bridge length
|
|
|
|
* get absolute bridge length
|
|
|
|
// length of the middle parts of the bridge
|
|
|
|
* length of the middle parts of the bridge */
|
|
|
|
int bridge_len = GetBridgeLength(start, end);
|
|
|
|
const uint bridge_len = GetBridgeLength(start, end);
|
|
|
|
// total length of bridge
|
|
|
|
/* total length of bridge */
|
|
|
|
int tot_bridgedata_len = bridge_len + 2;
|
|
|
|
const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
|
|
|
|
|
|
|
|
|
|
|
|
tot_bridgedata_len = CalcBridgeLenCostFactor(tot_bridgedata_len);
|
|
|
|
/* loop for all bridgetypes */
|
|
|
|
|
|
|
|
for (bridge_type = 0; bridge_type != MAX_BRIDGES; bridge_type++) {
|
|
|
|
for (bridge_type = 0; bridge_type != MAX_BRIDGES; bridge_type++) { // loop for all bridgetypes
|
|
|
|
|
|
|
|
if (CheckBridge_Stuff(bridge_type, bridge_len)) {
|
|
|
|
if (CheckBridge_Stuff(bridge_type, bridge_len)) {
|
|
|
|
|
|
|
|
/* bridge is accepted, add to list */
|
|
|
|
const Bridge *b = &_bridge[bridge_type];
|
|
|
|
const Bridge *b = &_bridge[bridge_type];
|
|
|
|
// bridge is accepted, add to list
|
|
|
|
/* Add to terraforming & bulldozing costs the cost of the
|
|
|
|
// add to terraforming & bulldozing costs the cost of the bridge itself (not computed with DC_QUERY_COST)
|
|
|
|
* bridge itself (not computed with DC_QUERY_COST) */
|
|
|
|
_bridgedata.costs[j] = ret.GetCost() + (((int64)tot_bridgedata_len * _price.build_bridge * b->price) >> 8);
|
|
|
|
_bridgedata.costs[j] = ret.GetCost() + (((int64)tot_bridgedata_len * _price.build_bridge * b->price) >> 8);
|
|
|
|
_bridgedata.indexes[j] = bridge_type;
|
|
|
|
_bridgedata.indexes[j] = bridge_type;
|
|
|
|
j++;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_bridgedata.count = j;
|
|
|
|
_bridgedata.count = j;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (j != 0) {
|
|
|
|
if (j != 0) {
|
|
|
|
Window *w = AllocateWindowDesc((_bridgedata.type & 0x80) ? &_build_road_bridge_desc : &_build_bridge_desc);
|
|
|
|
Window *w = AllocateWindowDesc((_bridgedata.type & 0x80) ? &_build_road_bridge_desc : &_build_bridge_desc);
|
|
|
|
w->vscroll.cap = 4;
|
|
|
|
w->vscroll.cap = 4;
|
|
|
|
w->vscroll.count = (byte)j;
|
|
|
|
w->vscroll.count = j;
|
|
|
|
|
|
|
|
w->resize.step_height = 22;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE);
|
|
|
|
ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|