src/bridge_gui.cpp
author rubidium
Sun, 03 Feb 2008 20:17:54 +0000
branchnoai
changeset 9724 b39bc69bb2f2
parent 9723 eee46cb39750
child 9732 f8eb3e208514
permissions -rw-r--r--
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     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"
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    20
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
    21
#include "table/strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
static struct BridgeData {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    24
	uint8 last_size;
2133
098c9da8292e (svn r2643) Get rid of some unnecessary casts
tron
parents: 1977
diff changeset
    25
	uint count;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
	TileIndex start_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	TileIndex end_tile;
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    28
	uint8 type;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    29
	uint8 indexes[MAX_BRIDGES];
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 6530
diff changeset
    30
	Money costs[MAX_BRIDGES];
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    31
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    32
	BridgeData()
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    33
		: last_size(4)
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    34
		, count(0)
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    35
		{};
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
    36
} _bridgedata;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
    38
void CcBuildBridge(bool success, TileIndex tile, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
{
541
e1cd34389f79 (svn r925) Use sound enums
tron
parents: 534
diff changeset
    40
	if (success) SndPlayTileFx(SND_27_BLACKSMITH_ANVIL, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
static void BuildBridge(Window *w, int i)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
	DeleteWindow(w);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2548
diff changeset
    46
	DoCommandP(_bridgedata.end_tile, _bridgedata.start_tile,
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2548
diff changeset
    47
		_bridgedata.indexes[i] | (_bridgedata.type << 8), CcBuildBridge,
9703
d2a6acdbd665 (svn r11146) [NoAI] -Sync: with trunk r11035:11045.
rubidium
parents: 9694
diff changeset
    48
		CMD_BUILD_BRIDGE | CMD_MSG(STR_5015_CAN_T_BUILD_BRIDGE_HERE));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    51
/* Names of the build bridge selection window */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    52
enum BuildBridgeSelectionWidgets {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    53
	BBSW_CLOSEBOX = 0,
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    54
	BBSW_CAPTION,
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
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
static void BuildBridgeWndProc(Window *w, WindowEvent *e)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
{
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2737
diff changeset
    62
	switch (e->event) {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    63
		case WE_CREATE:
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    64
			w->resize.step_height = 22;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    65
			w->vscroll.count = _bridgedata.count;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    66
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    67
			if (_bridgedata.last_size <= 4) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    68
				w->vscroll.cap = 4;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    69
			} else {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    70
				/* Resize the bridge selection window if we used a bigger one the last time */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    71
				w->vscroll.cap = (w->vscroll.count > _bridgedata.last_size) ? _bridgedata.last_size : w->vscroll.count;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    72
				ResizeWindow(w, 0, (w->vscroll.cap - 4) * w->resize.step_height);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    73
				w->widget[BBSW_BRIDGE_LIST].data = (w->vscroll.cap << 8) + 1;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    74
			}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    75
			break;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    76
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    77
		case WE_PAINT: {
6530
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
    78
			DrawWindowWidgets(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    80
			uint y = 15;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    81
			for (uint i = 0; (i < w->vscroll.cap) && ((i + w->vscroll.pos) < _bridgedata.count); i++) {
6530
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
    82
				const Bridge *b = &_bridge[_bridgedata.indexes[i + w->vscroll.pos]];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
6530
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
    84
				SetDParam(2, _bridgedata.costs[i + w->vscroll.pos]);
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
    85
				SetDParam(1, b->speed * 10 / 16);
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
    86
				SetDParam(0, b->material);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    88
				DrawSprite(b->sprite, b->pal, 3, y);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    89
				DrawString(44, y, STR_500D, TC_FROMSTRING);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    90
				y += w->resize.step_height;
6530
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
    91
			}
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
    92
			break;
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    93
		}
6530
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
    94
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
    95
		case WE_KEYPRESS: {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
    96
			const uint8 i = e->we.keypress.keycode - '1';
6530
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
    97
			if (i < 9 && i < _bridgedata.count) {
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
    98
				e->we.keypress.cont = false;
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
    99
				BuildBridge(w, i);
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
   100
			}
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
   101
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
   102
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   104
6530
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
   105
		case WE_CLICK:
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   106
			if (e->we.click.widget == BBSW_BRIDGE_LIST) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   107
				uint ind = ((int)e->we.click.pt.y - 14) / w->resize.step_height;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   108
				if (ind < w->vscroll.cap) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   109
					ind += w->vscroll.pos;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   110
					if (ind < _bridgedata.count) {
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   111
						BuildBridge(w, ind);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   112
					}
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   113
				}
6530
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
   114
			}
c43fa965e8ae (svn r8990) -Fix: more indenting and variable scoping
peter1138
parents: 6443
diff changeset
   115
			break;
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   116
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   117
		case WE_RESIZE:
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   118
			w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   119
			w->widget[BBSW_BRIDGE_LIST].data = (w->vscroll.cap << 8) + 1;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   120
			SetVScrollCount(w, _bridgedata.count);
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   121
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   122
			_bridgedata.last_size = w->vscroll.cap;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   123
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   127
/* Widget definition for the rail bridge selection window */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
static const Widget _build_bridge_widgets[] = {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   129
{   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
   130
{    WWT_CAPTION,   RESIZE_NONE,  7,  11, 199,   0,  13, STR_100D_SELECT_RAIL_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS},  // BBSW_CAPTION
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   131
{     WWT_MATRIX, RESIZE_BOTTOM,  7,   0, 187,  14, 101, 0x401,                       STR_101F_BRIDGE_SELECTION_CLICK},  // BBSW_BRIDGE_LIST
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   132
{  WWT_SCROLLBAR, RESIZE_BOTTOM,  7, 188, 199,  14,  89, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST}, // BBSW_SCROLLBAR
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   133
{  WWT_RESIZEBOX,     RESIZE_TB,  7, 188, 199,  90, 101, 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
   134
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   137
/* Window definition for the rail bridge selection window */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
static const WindowDesc _build_bridge_desc = {
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   139
	WDP_AUTO, WDP_AUTO, 200, 102, 200, 102,
5070
0bbf5264bfb7 (svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents: 4634
diff changeset
   140
	WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR,
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   141
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
	_build_bridge_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
	BuildBridgeWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   146
/* Widget definition for the road bridge selection window */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
static const Widget _build_road_bridge_widgets[] = {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   148
{   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
   149
{    WWT_CAPTION,   RESIZE_NONE,  7,  11, 199,   0,  13, STR_1803_SELECT_ROAD_BRIDGE, STR_018C_WINDOW_TITLE_DRAG_THIS},  // BBSW_CAPTION
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   150
{     WWT_MATRIX, RESIZE_BOTTOM,  7,   0, 187,  14, 101, 0x401,                       STR_101F_BRIDGE_SELECTION_CLICK},  // BBSW_BRIDGE_LIST
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   151
{  WWT_SCROLLBAR, RESIZE_BOTTOM,  7, 188, 199,  14,  89, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST}, // BBSW_SCROLLBAR
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   152
{  WWT_RESIZEBOX,     RESIZE_TB,  7, 188, 199,  90, 101, 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
   153
{   WIDGETS_END},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   156
/* Window definition for the road bridge selection window */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
static const WindowDesc _build_road_bridge_desc = {
9694
e72987579514 (svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents: 9686
diff changeset
   158
	WDP_AUTO, WDP_AUTO, 200, 102, 200, 102,
5070
0bbf5264bfb7 (svn r7128) -Codechange: Replace magic numbers by magic enums (windowdesc positioning WDP_AUTO = -1)
Darkvater
parents: 4634
diff changeset
   159
	WC_BUILD_BRIDGE, WC_BUILD_TOOLBAR,
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   160
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	_build_road_bridge_widgets,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	BuildBridgeWndProc
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1891
diff changeset
   166
void ShowBuildBridgeWindow(TileIndex start, TileIndex end, byte bridge_type)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
	DeleteWindowById(WC_BUILD_BRIDGE, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
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
   170
	_bridgedata.type = bridge_type;
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
   171
	_bridgedata.start_tile = start;
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
   172
	_bridgedata.end_tile = end;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   174
	/* 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
   175
	 * returns CMD_ERROR on failure, and price on success */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   176
	StringID errmsg = INVALID_STRING_ID;
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   177
	CommandCost ret = DoCommand(end, start, (bridge_type << 8), DC_AUTO | DC_QUERY_COST, CMD_BUILD_BRIDGE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   179
	uint8 j = 0;
2737
f16e0a808897 (svn r3282) - Codechange: Replace tests against CMD_ERROR with CmdFailed()
peter1138
parents: 2639
diff changeset
   180
	if (CmdFailed(ret)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
		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
   182
	} else {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   183
		/* check which bridges can be built
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   184
		 * get absolute bridge length
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   185
		 * length of the middle parts of the bridge */
9724
b39bc69bb2f2 (svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents: 9723
diff changeset
   186
		const uint bridge_len = GetTunnelBridgeLength(start, end);
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   187
		/* total length of bridge */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   188
		const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   190
		/* loop for all bridgetypes */
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   191
		for (bridge_type = 0; bridge_type != MAX_BRIDGES; bridge_type++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
			if (CheckBridge_Stuff(bridge_type, bridge_len)) {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   193
				/* bridge is accepted, add to list */
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
   194
				const Bridge *b = &_bridge[bridge_type];
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   195
				/* Add to terraforming & bulldozing costs the cost of the
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   196
				 * bridge itself (not computed with DC_QUERY_COST) */
9629
66dde6412125 (svn r10350) [NoAI] -Sync with trunk r10194:10349
glx
parents: 6530
diff changeset
   197
				_bridgedata.costs[j] = ret.GetCost() + (((int64)tot_bridgedata_len * _price.build_bridge * b->price) >> 8);
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
   198
				_bridgedata.indexes[j] = bridge_type;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
				j++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
		}
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   202
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   203
		_bridgedata.count = j;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
	if (j != 0) {
9723
eee46cb39750 (svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents: 9722
diff changeset
   207
		AllocateWindowDesc((_bridgedata.type & 0x80) ? &_build_road_bridge_desc : &_build_bridge_desc);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
	} else {
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
   209
		ShowErrorMessage(errmsg, STR_5015_CAN_T_BUILD_BRIDGE_HERE, TileX(end) * TILE_SIZE, TileY(end) * TILE_SIZE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
}