viewport.c
author belugas
Sat, 23 Sep 2006 02:39:24 +0000
changeset 4634 07699ac2bf37
parent 4609 954fe701062f
child 4799 20311e38bedf
permissions -rw-r--r--
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1864
diff changeset
     4
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1172
diff changeset
     5
#include "debug.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     6
#include "functions.h"
2662
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
     7
#include "gui.h"
1349
15979a2e9001 (svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents: 1309
diff changeset
     8
#include "spritecache.h"
1309
4403a69da4f8 (svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents: 1299
diff changeset
     9
#include "strings.h"
1363
775a7ee52369 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1349
diff changeset
    10
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 500
diff changeset
    11
#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: 657
diff changeset
    12
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "station.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
#include "town.h"
988
4304525d1b8b (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 981
diff changeset
    19
#include "signs.h"
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
    20
#include "waypoint.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2125
diff changeset
    21
#include "variables.h"
2676
59b65b4fb480 (svn r3218) -Feature: Multiheaded train engines will now stay in the same train
bjarni
parents: 2662
diff changeset
    22
#include "train.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
    24
#define VIEWPORT_DRAW_MEM (65536 * 2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
static bool _added_tile_sprite;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
static bool _offset_ground_sprites;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
4186
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    29
/* The in-game coordiante system looks like this *
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    30
 *                                               *
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    31
 *                    ^ Z                        *
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    32
 *                    |                          *
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    33
 *                    |                          *
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    34
 *                    |                          *
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    35
 *                    |                          *
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    36
 *                 /     \                       *
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    37
 *              /           \                    *
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    38
 *           /                 \                 *
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    39
 *        /                       \              *
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    40
 *   X <                             > Y         *
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    41
 */
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    42
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
typedef struct StringSpriteToDraw {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
	uint16 string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
	uint16 color;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
	struct StringSpriteToDraw *next;
849
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    47
	int32 x;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    48
	int32 y;
835
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
    49
	uint32 params[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	uint16 width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
} StringSpriteToDraw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
typedef struct TileSpriteToDraw {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	uint32 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
	struct TileSpriteToDraw *next;
849
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    56
	int32 x;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    57
	int32 y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	byte z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
} TileSpriteToDraw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
typedef struct ChildScreenSpriteToDraw {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
	uint32 image;
849
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    63
	int32 x;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    64
	int32 y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
	struct ChildScreenSpriteToDraw *next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
} ChildScreenSpriteToDraw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
typedef struct ParentSpriteToDraw {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
	uint32 image;
849
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    70
	int32 left;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    71
	int32 top;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    72
	int32 right;
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    73
	int32 bottom;
4186
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    74
	int32 xmin;
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    75
	int32 ymin;
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    76
	int32 xmax;
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    77
	int32 ymax;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
	ChildScreenSpriteToDraw *child;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
	byte unk16;
4186
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    80
	byte zmin;
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
    81
	byte zmax;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
} ParentSpriteToDraw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
2109
545d8173eebe (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
    84
// Quick hack to know how much memory to reserve when allocating from the spritelist
545d8173eebe (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
    85
// to prevent a buffer overflow.
545d8173eebe (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
    86
#define LARGEST_SPRITELIST_STRUCT ParentSpriteToDraw
545d8173eebe (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
    87
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
typedef struct ViewportDrawer {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	DrawPixelInfo dpi;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
    90
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
    91
	byte *spritelist_mem;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
    92
	const byte *eof_spritelist_mem;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
    93
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
	StringSpriteToDraw **last_string, *first_string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
	TileSpriteToDraw **last_tile, *first_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
	ChildScreenSpriteToDraw **last_child;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
	ParentSpriteToDraw **parent_list;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   100
	ParentSpriteToDraw * const *eof_parent_list;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
	byte combine_sprites;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	int offs_x, offs_y; // used when drawing ground sprites relative
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
} ViewportDrawer;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
static ViewportDrawer *_cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   109
TileHighlightData _thd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
static TileInfo *_cur_ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
4340
89b0ebfb7615 (svn r6041) -Fix r6040: forgot to declare a function in viewport.c
truelight
parents: 4339
diff changeset
   112
extern void SmallMapCenterOnCurrentPos(Window *w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   114
static Point MapXYZToViewport(const ViewPort *vp, uint x, uint y, uint z)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
	Point p = RemapCoords(x, y, z);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   117
	p.x -= vp->virtual_width / 2;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   118
	p.y -= vp->virtual_height / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
	return p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   122
void AssignWindowViewport(Window *w, int x, int y,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
	int width, int height, uint32 follow_flags, byte zoom)
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
	ViewPort *vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
	uint32 bit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   129
	for (vp = _viewports, bit = 1; ; vp++, bit <<= 1) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   130
		assert(vp != endof(_viewports));
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   131
		if (vp->width == 0) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
	_active_viewports |= bit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
	vp->left = x + w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
	vp->top = y + w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
	vp->width = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
	vp->height = height;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   139
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
	vp->zoom = zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
	vp->virtual_width = width << zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
	vp->virtual_height = height << zoom;
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
	if (follow_flags & 0x80000000) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   146
		const Vehicle *veh;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   147
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   148
		WP(w, vp_d).follow_vehicle = (VehicleID)(follow_flags & 0xFFFF);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   149
		veh = GetVehicle(WP(w, vp_d).follow_vehicle);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
		pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
	} else {
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
   152
		uint x = TileX(follow_flags) * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
   153
		uint y = TileY(follow_flags) * TILE_SIZE;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   154
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   155
		WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   156
		pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   159
	WP(w, vp_d).scrollpos_x = pt.x;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   160
	WP(w, vp_d).scrollpos_y = pt.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
	w->viewport = vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	vp->virtual_left = 0;//pt.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	vp->virtual_top = 0;//pt.y;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
static Point _vp_move_offs;
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
static void DoSetViewportPosition(Window *w, int left, int top, int width, int height)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
	for (; w < _last_window; w++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
		if (left + width > w->left &&
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   172
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
				top + height > w->top &&
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   174
				w->top + w->height > top) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   175
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
			if (left < w->left) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
				DoSetViewportPosition(w, left, top, w->left - left, height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
				DoSetViewportPosition(w, left + (w->left - left), top, width - (w->left - left), height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
			if (left + width > w->left + w->width) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
				DoSetViewportPosition(w, left, top, (w->left + w->width - left), height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
				DoSetViewportPosition(w, left + (w->left + w->width - left), top, width - (w->left + w->width - left) , height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
			if (top < w->top) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
				DoSetViewportPosition(w, left, top, width, (w->top - top));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
				DoSetViewportPosition(w, left, top + (w->top - top), width, height - (w->top - top));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
			if (top + height > w->top + w->height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
				DoSetViewportPosition(w, left, top, width, (w->top + w->height - top));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
				DoSetViewportPosition(w, left, top + (w->top + w->height - top), width , height - (w->top + w->height - top));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
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
		int xo = _vp_move_offs.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
		int yo = _vp_move_offs.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
		if (abs(xo) >= width || abs(yo) >= height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
			/* fully_outside */
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   210
			RedrawScreenRect(left, top, left + width, top + height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
		GfxScroll(left, top, width, height, xo, yo);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
		if (xo > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
			RedrawScreenRect(left, top, xo + left, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
			left += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
			width -= xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
		} else if (xo < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
			RedrawScreenRect(left+width+xo, top, left+width, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
			width += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
		if (yo > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
			RedrawScreenRect(left, top, width+left, top + yo);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
		} else if (yo < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
			RedrawScreenRect(left, top + height + yo, width+left, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
   233
static void SetViewportPosition(Window *w, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	ViewPort *vp = w->viewport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
	int old_left = vp->virtual_left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
	int old_top = vp->virtual_top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
	int left, top, width, height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
	vp->virtual_left = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	vp->virtual_top = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
	old_left >>= vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	old_top >>= vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
	x >>= vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	y >>= vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
	old_left -= x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
	old_top -= y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   252
	if (old_top == 0 && old_left == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	_vp_move_offs.x = old_left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
	_vp_move_offs.y = old_top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
	left = vp->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
	top = vp->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
	width = vp->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
	height = vp->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
	if (left < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
		width += left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
		left = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   267
	i = left + width - _screen.width;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   268
	if (i >= 0) width -= i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
	if (width > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
		if (top < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
			height += top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
			top = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   275
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   276
		i = top + height - _screen.height;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   277
		if (i >= 0) height -= i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   279
		if (height > 0) DoSetViewportPosition(w + 1, left, top, width, height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   284
ViewPort *IsPtInWindowViewport(const Window *w, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
	ViewPort *vp = w->viewport;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   287
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
	if (vp != NULL &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	    IS_INT_INSIDE(x, vp->left, vp->left + vp->width) &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
			IS_INT_INSIDE(y, vp->top, vp->top + vp->height))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
		return vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   296
static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y)
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   297
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
	int a,b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	if ( (uint)(x -= vp->left) >= (uint)vp->width ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
				(uint)(y -= vp->top) >= (uint)vp->height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
				Point pt = {-1, -1};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
				return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	x = ((x << vp->zoom) + vp->virtual_left) >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
	y = ((y << vp->zoom) + vp->virtual_top) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
#if !defined(NEW_ROTATION)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
	a = y-x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
	b = y+x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
#else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
	a = x+y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
	b = x-y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4189
diff changeset
   318
	if ((uint)a < MapMaxX() * TILE_SIZE && (uint)b < MapMaxY() * TILE_SIZE) {
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4189
diff changeset
   319
		uint z;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   320
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4189
diff changeset
   321
		z = GetSlopeZ(a,     b    ) / 2;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4189
diff changeset
   322
		z = GetSlopeZ(a + z, b + z) / 2;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4189
diff changeset
   323
		z = GetSlopeZ(a + z, b + z) / 2;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4189
diff changeset
   324
		z = GetSlopeZ(a + z, b + z) / 2;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4189
diff changeset
   325
		z = GetSlopeZ(a + z, b + z) / 2;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4189
diff changeset
   326
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4189
diff changeset
   327
		pt.x = a + z;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4189
diff changeset
   328
		pt.y = b + z;
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4189
diff changeset
   329
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
		pt.x = pt.y = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
981
f74abee65b7b (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   336
/* When used for zooming, check area below current coordinates (x,y)
f74abee65b7b (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   337
 * and return the tile of the zoomed out/in position (zoom_x, zoom_y)
f74abee65b7b (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   338
 * when you just want the tile, make x = zoom_x and y = zoom_y */
f74abee65b7b (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   339
static Point GetTileFromScreenXY(int x, int y, int zoom_x, int zoom_y)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   340
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
	ViewPort *vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
	Point pt;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   344
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   345
	if ( (w = FindWindowFromPt(x, y)) != NULL &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
			 (vp = IsPtInWindowViewport(w, x, y)) != NULL)
981
f74abee65b7b (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   347
				return TranslateXYToTileCoord(vp, zoom_x, zoom_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	pt.y = pt.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
   353
Point GetTileBelowCursor(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
{
981
f74abee65b7b (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   355
	return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, _cursor.pos.x, _cursor.pos.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   358
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   359
Point GetTileZoomCenterWindow(bool in, Window * w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
	int x, y;
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   362
	ViewPort * vp;
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   363
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   364
	vp = w->viewport;
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   365
2026
567e3bc9af72 (svn r2535) Tabs
tron
parents: 2023
diff changeset
   366
	if (in) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   367
		x = ((_cursor.pos.x - vp->left) >> 1) + (vp->width >> 2);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   368
		y = ((_cursor.pos.y - vp->top) >> 1) + (vp->height >> 2);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   369
	} else {
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   370
		x = vp->width - (_cursor.pos.x - vp->left);
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
   371
		y = vp->height - (_cursor.pos.y - vp->top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
	}
981
f74abee65b7b (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   373
	/* Get the tile below the cursor and center on the zoomed-out center */
f74abee65b7b (svn r1477) -Fix: finally zooming in/out always works. The problem was that the zoomed in/out coordinates were used for checking if the area was a zoomable viewport in the not zoomed in/out position. The chances were high that there was a window.
darkvater
parents: 979
diff changeset
   374
	return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, x + vp->left, y + vp->top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
849
c3407041774f (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
   377
void DrawGroundSpriteAt(uint32 image, int32 x, int32 y, byte z)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
	TileSpriteToDraw *ts;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   381
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   382
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   384
	if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
2013
c83b52340eee (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1990
diff changeset
   385
		DEBUG(misc, 0) ("Out of sprite mem");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
	}
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   388
	ts = (TileSpriteToDraw*)vd->spritelist_mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	vd->spritelist_mem += sizeof(TileSpriteToDraw);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   391
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
	ts->image = image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
	ts->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
	ts->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
	ts->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
	ts->z = z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
	*vd->last_tile = ts;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   398
	vd->last_tile = &ts->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
void DrawGroundSprite(uint32 image)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
	if (_offset_ground_sprites) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
		// offset ground sprite because of foundation?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
		AddChildSpriteScreen(image, _cur_vd->offs_x, _cur_vd->offs_y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
	} else {
1083
8e64dc3ed29f (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   407
		_added_tile_sprite = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
		DrawGroundSpriteAt(image, _cur_ti->x, _cur_ti->y, _cur_ti->z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
void OffsetGroundSprite(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
	_cur_vd->offs_x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
	_cur_vd->offs_y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
	_offset_ground_sprites = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
static void AddCombinedSprite(uint32 image, int x, int y, byte z)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   422
	const ViewportDrawer *vd = _cur_vd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
	Point pt = RemapCoords(x, y, z);
2319
fba7d61df04a (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   424
	const Sprite* spr = GetSprite(image & SPRITE_MASK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
2319
fba7d61df04a (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   426
	if (pt.x + spr->x_offs >= vd->dpi.left + vd->dpi.width ||
fba7d61df04a (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   427
			pt.x + spr->x_offs + spr->width <= vd->dpi.left ||
fba7d61df04a (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   428
			pt.y + spr->y_offs >= vd->dpi.top + vd->dpi.height ||
fba7d61df04a (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   429
			pt.y + spr->y_offs + spr->height <= vd->dpi.top)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   432
	AddChildSpriteScreen(image, pt.x - vd->parent_list[-1]->left, pt.y - vd->parent_list[-1]->top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
void AddSortableSpriteToDraw(uint32 image, int x, int y, int w, int h, byte dz, byte z)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
	ParentSpriteToDraw *ps;
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
   440
	const Sprite *spr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   443
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
	if (vd->combine_sprites == 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
		AddCombinedSprite(image, x, y, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
	vd->last_child = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   452
	if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
2013
c83b52340eee (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1990
diff changeset
   453
		DEBUG(misc, 0) ("Out of sprite mem");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
	}
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   456
	ps = (ParentSpriteToDraw*)vd->spritelist_mem;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   457
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   458
	if (vd->parent_list >= vd->eof_parent_list) {
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   459
		// This can happen rarely, mostly when you zoom out completely
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   460
		//  and have a lot of stuff that moves (and is added to the
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   461
		//  sort-list, this function). To solve it, increase
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   462
		//  parent_list somewhere below to a higher number.
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   463
		// This can not really hurt you, it just gives some black
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   464
		//  spots on the screen ;)
2013
c83b52340eee (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1990
diff changeset
   465
		DEBUG(misc, 0) ("Out of sprite mem (parent_list)");
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   466
		return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   467
	}
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   468
4189
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   469
	pt = RemapCoords(x, y, z);
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   470
	spr = GetSprite(image & SPRITE_MASK);
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   471
	if ((ps->left   = (pt.x += spr->x_offs)) >= vd->dpi.left + vd->dpi.width ||
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   472
			(ps->right  = (pt.x +  spr->width )) <= vd->dpi.left ||
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   473
			(ps->top    = (pt.y += spr->y_offs)) >= vd->dpi.top + vd->dpi.height ||
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   474
			(ps->bottom = (pt.y +  spr->height)) <= vd->dpi.top) {
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   475
		return;
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   476
	}
fcc29d7b6722 (svn r5631) Don't allocate memory for information about a sprite which isn't drawn
tron
parents: 4188
diff changeset
   477
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   478
	vd->spritelist_mem += sizeof(ParentSpriteToDraw);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
	ps->image = image;
4186
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
   481
	ps->xmin = x;
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
   482
	ps->xmax = x + w - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
4186
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
   484
	ps->ymin = y;
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
   485
	ps->ymax = y + h - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
4186
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
   487
	ps->zmin = z;
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
   488
	ps->zmax = z + dz - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
	ps->unk16 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
	ps->child = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
	vd->last_child = &ps->child;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
	*vd->parent_list++ = ps;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   496
	if (vd->combine_sprites == 1) vd->combine_sprites = 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
   499
void StartSpriteCombine(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   500
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
	_cur_vd->combine_sprites = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
   504
void EndSpriteCombine(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
	_cur_vd->combine_sprites = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
void AddChildSpriteScreen(uint32 image, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
	ChildScreenSpriteToDraw *cs;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   513
2187
a0e206ce9fbf (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   514
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   516
	if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
2013
c83b52340eee (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1990
diff changeset
   517
		DEBUG(misc, 0) ("Out of sprite mem");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
	}
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   520
	cs = (ChildScreenSpriteToDraw*)vd->spritelist_mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   522
	if (vd->last_child == NULL) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   523
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   524
	vd->spritelist_mem += sizeof(ChildScreenSpriteToDraw);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
	*vd->last_child = cs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	vd->last_child = &cs->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   529
	cs->image = image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
	cs->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
	cs->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
	cs->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
/* Returns a StringSpriteToDraw */
835
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
   536
void *AddStringToDraw(int x, int y, StringID string, uint32 params_1, uint32 params_2, uint32 params_3)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
	StringSpriteToDraw *ss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   541
	if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
2013
c83b52340eee (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1990
diff changeset
   542
		DEBUG(misc, 0) ("Out of sprite mem");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
	}
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   545
	ss = (StringSpriteToDraw*)vd->spritelist_mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
	vd->spritelist_mem += sizeof(StringSpriteToDraw);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   549
	ss->string = string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
	ss->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
	ss->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
	ss->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
	ss->params[0] = params_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
	ss->params[1] = params_2;
835
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
   555
	ss->params[2] = params_3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
	ss->width = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
	*vd->last_string = ss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   559
	vd->last_string = &ss->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   561
	return ss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3809
diff changeset
   564
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
static void DrawSelectionSprite(uint32 image, const TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
{
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   567
	if (_added_tile_sprite && !(_thd.drawstyle & HT_LINE)) { // draw on real ground
1083
8e64dc3ed29f (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   568
		DrawGroundSpriteAt(image, ti->x, ti->y, ti->z + 7);
8e64dc3ed29f (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   569
	} else { // draw on top of foundation
8e64dc3ed29f (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   570
		AddSortableSpriteToDraw(image, ti->x, ti->y, 0x10, 0x10, 1, ti->z + 7);
8e64dc3ed29f (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   571
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
static bool IsPartOfAutoLine(int px, int py)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
{
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   576
	px -= _thd.selstart.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   577
	py -= _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2817
diff changeset
   579
	switch (_thd.drawstyle) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   580
	case HT_LINE | HT_DIR_X:  return py == 0; // x direction
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   581
	case HT_LINE | HT_DIR_Y:  return px == 0; // y direction
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   582
	case HT_LINE | HT_DIR_HU: return px == -py || px == -py - 16; // horizontal upper
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   583
	case HT_LINE | HT_DIR_HL: return px == -py || px == -py + 16; // horizontal lower
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   584
	case HT_LINE | HT_DIR_VL: return px == py || px == py + 16; // vertival left
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   585
	case HT_LINE | HT_DIR_VR: return px == py || px == py - 16; // vertical right
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
	default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
		NOT_REACHED();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   589
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
	/* useless, but avoids compiler warning this way */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   594
// [direction][side]
2710
44278abd3ef9 (svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents: 2676
diff changeset
   595
static const int _AutorailType[6][2] = {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   596
	{ HT_DIR_X,  HT_DIR_X },
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   597
	{ HT_DIR_Y,  HT_DIR_Y },
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   598
	{ HT_DIR_HU, HT_DIR_HL },
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   599
	{ HT_DIR_HL, HT_DIR_HU },
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   600
	{ HT_DIR_VL, HT_DIR_VR },
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   601
	{ HT_DIR_VR, HT_DIR_VL }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   602
};
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   603
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   604
#include "table/autorail.h"
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   605
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
static void DrawTileSelection(const TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
	uint32 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
	// Draw a red error square?
3281
757d7da49445 (svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents: 3279
diff changeset
   611
	if (_thd.redsq != 0 && _thd.redsq == ti->tile) {
1864
80e13d54b061 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   612
		DrawSelectionSprite(PALETTE_TILE_RED_PULSATING | (SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]), ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
	// no selection active?
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   617
	if (_thd.drawstyle == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
	// Inside the inner area?
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   620
	if (IS_INSIDE_1D(ti->x, _thd.pos.x, _thd.size.x) &&
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   621
			IS_INSIDE_1D(ti->y, _thd.pos.y, _thd.size.y)) {
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   622
		if (_thd.drawstyle & HT_RECT) {
1864
80e13d54b061 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   623
			image = SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh];
80e13d54b061 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   624
			if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
			DrawSelectionSprite(image, ti);
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   626
		} else if (_thd.drawstyle & HT_POINT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
			// Figure out the Z coordinate for the single dot.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
			byte z = ti->z;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3609
diff changeset
   629
			if (ti->tileh & SLOPE_N) {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   630
				z += TILE_HEIGHT;
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   631
				if (ti->tileh == SLOPE_STEEP_N) z += TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   632
			}
1864
80e13d54b061 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   633
			DrawGroundSpriteAt(_cur_dpi->zoom != 2 ? SPR_DOT : SPR_DOT_SMALL, ti->x, ti->y, z);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   634
		} else if (_thd.drawstyle & HT_RAIL /*&& _thd.place_mode == VHM_RAIL*/) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   635
			// autorail highlight piece under cursor
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   636
			uint type = _thd.drawstyle & 0xF;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   637
			assert(type <= 5);
2710
44278abd3ef9 (svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents: 2676
diff changeset
   638
			image = SPR_AUTORAIL_BASE + _AutorailTilehSprite[ti->tileh][_AutorailType[type][0]];
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   639
1864
80e13d54b061 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   640
			if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   641
			DrawSelectionSprite(image, ti);
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   642
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   643
		} else if (IsPartOfAutoLine(ti->x, ti->y)) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   644
			// autorail highlighting long line
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   645
			int dir = _thd.drawstyle & ~0xF0;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   646
			uint side;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   647
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   648
			if (dir < 2) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   649
				side = 0;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   650
			} else {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   651
				TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   652
				int diffx = myabs(TileX(start) - TileX(ti->tile));
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   653
				int diffy = myabs(TileY(start) - TileY(ti->tile));
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   654
				side = myabs(diffx - diffy);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   655
			}
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   656
2710
44278abd3ef9 (svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents: 2676
diff changeset
   657
			image = SPR_AUTORAIL_BASE + _AutorailTilehSprite[ti->tileh][_AutorailType[dir][side]];
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   658
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   659
			if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   660
			DrawSelectionSprite(image, ti);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   661
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   662
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
	// Check if it's inside the outer area?
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   666
	if (_thd.outersize.x &&
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   667
			_thd.size.x < _thd.size.x + _thd.outersize.x &&
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   668
			IS_INSIDE_1D(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) &&
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   669
			IS_INSIDE_1D(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
		// Draw a blue rect.
1864
80e13d54b061 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   671
		DrawSelectionSprite(PALETTE_SEL_TILE_BLUE | (SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]), ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   674
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
   676
static void ViewportAddLandscape(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
	int x, y, width, height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
	TileInfo ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
	bool direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
	_cur_ti = &ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
	// Transform into tile coordinates and round to closest full tile
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
#if !defined(NEW_ROTATION)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
	x = ((vd->dpi.top >> 1) - (vd->dpi.left >> 2)) & ~0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
	y = ((vd->dpi.top >> 1) + (vd->dpi.left >> 2) - 0x10) & ~0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
#else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
	x = ((vd->dpi.top >> 1) + (vd->dpi.left >> 2) - 0x10) & ~0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
	y = ((vd->dpi.left >> 2) - (vd->dpi.top >> 1)) & ~0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
	// determine size of area
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
		Point pt = RemapCoords(x, y, 241);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
		width = (vd->dpi.left + vd->dpi.width - pt.x + 95) >> 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
		height = (vd->dpi.top + vd->dpi.height - pt.y) >> 5 << 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
	assert(width > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
	assert(height > 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   702
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
	direction = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
		int width_cur = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
		int x_cur = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
		int y_cur = y;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   709
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
		do {
4238
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   711
			TileType tt;
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   712
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   713
			ti.x = x_cur;
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   714
			ti.y = y_cur;
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   715
			if (0 <= x_cur && x_cur < (int)MapMaxX() * TILE_SIZE &&
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   716
					0 <= y_cur && y_cur < (int)MapMaxY() * TILE_SIZE) {
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   717
				TileIndex tile = TileVirtXY(x_cur, y_cur);
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   718
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   719
				ti.tile = tile;
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   720
				ti.tileh = GetTileSlope(tile, &ti.z);
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   721
				tt = GetTileType(tile);
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   722
			} else {
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   723
				ti.tileh = SLOPE_FLAT;
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   724
				ti.tile = 0;
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   725
				ti.z = 0;
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   726
				tt = MP_VOID;
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   727
			}
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   728
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
#if !defined(NEW_ROTATION)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
			y_cur += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
			x_cur -= 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
#else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
			y_cur += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   734
			x_cur += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
			_added_tile_sprite = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
			_offset_ground_sprites = false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   738
4238
4b58d6ea4e5b (svn r5806) Inline FindLandscapeHeight() into its only remaining caller and remove the attribute "type" from struct TileInfo
tron
parents: 4231
diff changeset
   739
			_tile_type_procs[tt]->draw_tile_proc(&ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
			DrawTileSelection(&ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
		} while (--width_cur);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   742
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
#if !defined(NEW_ROTATION)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
		if ( (direction^=1) != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
			y += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
		else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
			x += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
#else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
		if ( (direction^=1) != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   750
			x += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
		else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
			y -= 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
#endif
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   754
	} while (--height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   758
static void ViewportAddTownNames(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
	if (!(_display_opt & DO_SHOW_TOWN_NAMES) || _game_mode == GM_MENU)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
	if (dpi->zoom < 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
		FOR_ALL_TOWNS(t) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4340
diff changeset
   773
			if (bottom > t->sign.top &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
					top < t->sign.top + 12 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
					right > t->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
					left < t->sign.left + t->sign.width_1) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   777
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   778
				AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   779
					_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   780
					t->index, t->population, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
	} else if (dpi->zoom == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
		right += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
		bottom += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
		FOR_ALL_TOWNS(t) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4340
diff changeset
   788
			if (bottom > t->sign.top &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
					top < t->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
					right > t->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
					left < t->sign.left + t->sign.width_1*2) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   792
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   793
				AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   794
					_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   795
					t->index, t->population, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   796
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
		right += 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
		bottom += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
		assert(dpi->zoom == 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   803
		FOR_ALL_TOWNS(t) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4340
diff changeset
   804
			if (bottom > t->sign.top &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   805
					top < t->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
					right > t->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
					left < t->sign.left + t->sign.width_2*4) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   808
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   809
				AddStringToDraw(t->sign.left + 5, t->sign.top + 1, STR_TOWN_LABEL_TINY_BLACK, t->index, 0, 0);
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   810
				AddStringToDraw(t->sign.left + 1, t->sign.top - 3, STR_TOWN_LABEL_TINY_WHITE, t->index, 0, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   811
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   816
static void ViewportAddStationNames(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   820
	StringSpriteToDraw *sstd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
	if (!(_display_opt & DO_SHOW_STATION_NAMES) || _game_mode == GM_MENU)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
	if (dpi->zoom < 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
		FOR_ALL_STATIONS(st) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4340
diff changeset
   832
			if (bottom > st->sign.top &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
					top < st->sign.top + 12 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
					right > st->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
					left < st->sign.left + st->sign.width_1) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   836
835
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
   837
				sstd=AddStringToDraw(st->sign.left + 1, st->sign.top + 1, STR_305C_0, st->index, st->facilities, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
				if (sstd != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
					sstd->color = (st->owner == OWNER_NONE || !st->facilities) ? 0xE : _player_colors[st->owner];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
					sstd->width = st->sign.width_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
	} else if (dpi->zoom == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
		right += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
		bottom += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
		FOR_ALL_STATIONS(st) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4340
diff changeset
   849
			if (bottom > st->sign.top &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
					top < st->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
					right > st->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
					left < st->sign.left + st->sign.width_1*2) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   853
835
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
   854
				sstd=AddStringToDraw(st->sign.left + 1, st->sign.top + 1, STR_305C_0, st->index, st->facilities, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
				if (sstd != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
					sstd->color = (st->owner == OWNER_NONE || !st->facilities) ? 0xE : _player_colors[st->owner];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
					sstd->width = st->sign.width_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
		assert(dpi->zoom == 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
		right += 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
		bottom += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   868
		FOR_ALL_STATIONS(st) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4340
diff changeset
   869
			if (bottom > st->sign.top &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   870
					top < st->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
					right > st->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
					left < st->sign.left + st->sign.width_2*4) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   873
1964
6f9acf485026 (svn r2470) - Fix: Display station signs correctly in smallest zoom level in transparent buildings or tranparant station signs mode. (Peter1138)
hackykid
parents: 1959
diff changeset
   874
				sstd=AddStringToDraw(st->sign.left + 1, st->sign.top + 1, STR_STATION_SIGN_TINY, st->index, st->facilities, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
				if (sstd != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
					sstd->color = (st->owner == OWNER_NONE || !st->facilities) ? 0xE : _player_colors[st->owner];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
					sstd->width = st->sign.width_2 | 0x8000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   880
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   881
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   884
static void ViewportAddSigns(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
{
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   886
	Sign *si;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
	StringSpriteToDraw *sstd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
	if (!(_display_opt & DO_SHOW_SIGNS))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   893
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
	if (dpi->zoom < 1) {
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   899
		FOR_ALL_SIGNS(si) {
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   900
			if (bottom > si->sign.top &&
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   901
					top < si->sign.top + 12 &&
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   902
					right > si->sign.left &&
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   903
					left < si->sign.left + si->sign.width_1) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   904
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   905
				sstd=AddStringToDraw(si->sign.left + 1, si->sign.top + 1, STR_2806, si->str, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
				if (sstd != NULL) {
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   907
					sstd->width = si->sign.width_1;
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   908
					sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   911
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
	} else if (dpi->zoom == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
		right += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
		bottom += 2;
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   915
		FOR_ALL_SIGNS(si) {
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   916
			if (bottom > si->sign.top &&
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   917
					top < si->sign.top + 24 &&
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   918
					right > si->sign.left &&
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   919
					left < si->sign.left + si->sign.width_1 * 2) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   920
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   921
				sstd=AddStringToDraw(si->sign.left + 1, si->sign.top + 1, STR_2806, si->str, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
				if (sstd != NULL) {
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   923
					sstd->width = si->sign.width_1;
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   924
					sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   926
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   927
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
		right += 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
		bottom += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   932
		FOR_ALL_SIGNS(si) {
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   933
			if (bottom > si->sign.top &&
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   934
					top < si->sign.top + 24 &&
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   935
					right > si->sign.left &&
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   936
					left < si->sign.left + si->sign.width_2 * 4) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   937
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   938
				sstd=AddStringToDraw(si->sign.left + 1, si->sign.top + 1, STR_2002, si->str, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
				if (sstd != NULL) {
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   940
					sstd->width = si->sign.width_2 | 0x8000;
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
   941
					sstd->color = (si->owner == OWNER_NONE) ? 14 : _player_colors[si->owner];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   944
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   948
static void ViewportAddWaypoints(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
{
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   950
	Waypoint *wp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
	StringSpriteToDraw *sstd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
395
788a9bba0889 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 193
diff changeset
   955
	if (!(_display_opt & DO_WAYPOINTS))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   958
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   962
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   963
	if (dpi->zoom < 1) {
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   964
		FOR_ALL_WAYPOINTS(wp) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4340
diff changeset
   965
			if (bottom > wp->sign.top &&
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   966
					top < wp->sign.top + 12 &&
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   967
					right > wp->sign.left &&
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   968
					left < wp->sign.left + wp->sign.width_1) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   969
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   970
				sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, STR_WAYPOINT_VIEWPORT, wp->index, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
				if (sstd != NULL) {
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   972
					sstd->width = wp->sign.width_1;
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   973
					sstd->color = (wp->deleted ? 0xE : 11);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   976
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
	} else if (dpi->zoom == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
		right += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
		bottom += 2;
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   980
		FOR_ALL_WAYPOINTS(wp) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4340
diff changeset
   981
			if (bottom > wp->sign.top &&
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   982
					top < wp->sign.top + 24 &&
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   983
					right > wp->sign.left &&
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   984
					left < wp->sign.left + wp->sign.width_1*2) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   985
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   986
				sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, STR_WAYPOINT_VIEWPORT, wp->index, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
				if (sstd != NULL) {
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   988
					sstd->width = wp->sign.width_1;
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   989
					sstd->color = (wp->deleted ? 0xE : 11);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   992
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
		right += 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
		bottom += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   997
		FOR_ALL_WAYPOINTS(wp) {
4346
66105d4f6e83 (svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
truelight
parents: 4340
diff changeset
   998
			if (bottom > wp->sign.top &&
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   999
					top < wp->sign.top + 24 &&
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1000
					right > wp->sign.left &&
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1001
					left < wp->sign.left + wp->sign.width_2*4) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1002
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1003
				sstd = AddStringToDraw(wp->sign.left + 1, wp->sign.top + 1, STR_WAYPOINT_VIEWPORT_TINY, wp->index, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1004
				if (sstd != NULL) {
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1005
					sstd->width = wp->sign.width_2 | 0x8000;
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1006
					sstd->color = (wp->deleted ? 0xE : 11);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1007
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1008
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1009
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
	char buffer[128];
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1016
	uint w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
	sign->top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
	GetString(buffer, str);
4609
954fe701062f (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4539
diff changeset
  1021
	w = GetStringBoundingBox(buffer).width + 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
	sign->width_1 = w;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1023
	sign->left = left - w / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
4609
954fe701062f (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4539
diff changeset
  1025
	/* zoomed out version */
3798
b1f5290b36b1 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3645
diff changeset
  1026
	_cur_fontsize = FS_SMALL;
4609
954fe701062f (svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents: 4539
diff changeset
  1027
	w = GetStringBoundingBox(buffer).width + 3;
3798
b1f5290b36b1 (svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents: 3645
diff changeset
  1028
	_cur_fontsize = FS_NORMAL;
1390
e7cdf3ce0fb6 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1029
	sign->width_2 = w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1031
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
410
0efd84450b01 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
  1033
static void ViewportDrawTileSprites(TileSpriteToDraw *ts)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1034
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
		Point pt = RemapCoords(ts->x, ts->y, ts->z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
		DrawSprite(ts->image, pt.x, pt.y);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1038
		ts = ts->next;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1039
	} while (ts != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1042
static void ViewportSortParentSprites(ParentSpriteToDraw *psd[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1044
	while (*psd != NULL) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1045
		ParentSpriteToDraw* ps = *psd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
		if (!(ps->unk16 & 1)) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1048
			ParentSpriteToDraw** psd2 = psd;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1049
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
			ps->unk16 |= 1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1051
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1052
			while (*++psd2 != NULL) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1053
				ParentSpriteToDraw* ps2 = *psd2;
4188
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1054
				ParentSpriteToDraw** psd3;
1934
b27bc12822cd (svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents: 1932
diff changeset
  1055
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1056
				if (ps2->unk16 & 1) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
4187
4eaf57b951c8 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1058
				/* Decide which comparator to use, based on whether the bounding
4eaf57b951c8 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1059
				 * boxes overlap
4eaf57b951c8 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1060
				 */
4eaf57b951c8 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1061
				if (ps->xmax > ps2->xmin && ps->xmin < ps2->xmax && // overlap in X?
4eaf57b951c8 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1062
						ps->ymax > ps2->ymin && ps->ymin < ps2->ymax && // overlap in Y?
4eaf57b951c8 (svn r5629) Simplify the test whether two bounding boxes overlap
tron
parents: 4186
diff changeset
  1063
						ps->zmax > ps2->zmin && ps->zmin < ps2->zmax) { // overlap in Z?
4188
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1064
					/* Use X+Y+Z as the sorting order, so sprites closer to the bottom of
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1065
					 * the screen and with higher Z elevation, are drawn in front.
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1066
					 * Here X,Y,Z are the coordinates of the "center of mass" of the sprite,
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1067
					 * i.e. X=(left+right)/2, etc.
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1068
					 * However, since we only care about order, don't actually divide / 2
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1069
					 */
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1070
					if (ps->xmin + ps->xmax + ps->ymin + ps->ymax + ps->zmin + ps->zmax <=
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1071
							ps2->xmin + ps2->xmax + ps2->ymin + ps2->ymax + ps2->zmin + ps2->zmax) {
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1072
						continue;
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1073
					}
1934
b27bc12822cd (svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents: 1932
diff changeset
  1074
				} else {
4188
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1075
					if (ps->xmax < ps2->xmin ||
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1076
							ps->ymax < ps2->ymin ||
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1077
							ps->zmax < ps2->zmin || (
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1078
								ps->xmin < ps2->xmax &&
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1079
								ps->ymin < ps2->ymax &&
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1080
								ps->zmin < ps2->zmax
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1081
							)) {
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1082
						continue;
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1083
					}
1934
b27bc12822cd (svn r2440) - Fix: [newgrf] Fix the spritesorter to handle overlapping sprites properly, this fixes display problems with really short wagons. (algorithm by patchman, ported by therax)
hackykid
parents: 1932
diff changeset
  1084
				}
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1085
4188
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1086
				// Swap the two sprites ps and ps2 using bubble-sort algorithm.
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1087
				psd3 = psd;
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1088
				do {
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1089
					ParentSpriteToDraw* temp = *psd3;
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1090
					*psd3 = ps2;
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1091
					ps2 = temp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
4188
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1093
					psd3++;
270af1cd03d4 (svn r5630) Replace a boolean variable by continue
tron
parents: 4187
diff changeset
  1094
				} while (psd3 <= psd2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
			psd++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1102
static void ViewportDrawParentSprites(ParentSpriteToDraw *psd[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1104
	for (; *psd != NULL; psd++) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1105
		const ParentSpriteToDraw* ps = *psd;
4186
6e55c6f0908b (svn r5628) Rename the attributes for the bounding box of struct ParentSpriteToDraw to something sensible. Half of them was totally off: right is left, bottom is top *sigh*
tron
parents: 4171
diff changeset
  1106
		Point pt = RemapCoords(ps->xmin, ps->ymin, ps->zmin);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1107
		const ChildScreenSpriteToDraw* cs;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
		DrawSprite(ps->image, pt.x, pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1111
		for (cs = ps->child; cs != NULL; cs = cs->next) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
			DrawSprite(cs->image, ps->left + cs->x, ps->top + cs->y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1117
static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
	DrawPixelInfo dp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
	byte zoom;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1121
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
	_cur_dpi = &dp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
	dp = *dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1125
	zoom = dp.zoom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1126
	dp.zoom = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1128
	dp.left >>= zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
	dp.top >>= zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
	dp.width >>= zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1131
	dp.height >>= zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
		if (ss->width != 0) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1135
			int x = (ss->x >> zoom) - 1;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1136
			int y = (ss->y >> zoom) - 1;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1137
			int bottom = y + 11;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1138
			int w = ss->width;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1139
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
			if (w & 0x8000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
				w &= ~0x8000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
				y--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
				bottom -= 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
				w -= 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1147
		/* Draw the rectangle if 'tranparent station signs' is off,
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1148
		 * or if we are drawing a general text sign (STR_2806) */
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1149
			if (!(_display_opt & DO_TRANS_SIGNS) || ss->string == STR_2806)
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1150
				DrawFrameRect(
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1151
					x, y, x + w, bottom, ss->color,
4439
00ac1d17d72e (svn r6211) Commit file forgotten in r6210
tron
parents: 4349
diff changeset
  1152
					(_display_opt & DO_TRANS_BUILDINGS) ? FR_TRANSPARENT : 0
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1153
				);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
534
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1156
		SetDParam(0, ss->params[0]);
306bc86eb23e (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1157
		SetDParam(1, ss->params[1]);
835
f6a341f541d7 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
  1158
		SetDParam(2, ss->params[2]);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1159
		/* if we didn't draw a rectangle, or if transparant building is on,
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1160
		 * draw the text in the color the rectangle would have */
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1161
		if ((
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1162
					(_display_opt & DO_TRANS_BUILDINGS) ||
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1163
					(_display_opt & DO_TRANS_SIGNS && ss->string != STR_2806)
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1164
				) && ss->width != 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1165
			/* Real colors need the IS_PALETTE_COLOR flag
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1166
			 * otherwise colors from _string_colormap are assumed. */
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1167
			DrawString(
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1168
				ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0),
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4439
diff changeset
  1169
				ss->string, _colour_gradient[ss->color][6] | IS_PALETTE_COLOR
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1170
			);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
		} else {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1172
			DrawString(
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1173
				ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0),
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1174
				ss->string, 16
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1175
			);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1176
		}
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1177
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1178
		ss = ss->next;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1179
	} while (ss != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1180
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1181
430
2e9a2e9fcf11 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
  1182
void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1184
	ViewportDrawer vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
	int mask;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1186
	int x;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1187
	int y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
	DrawPixelInfo *old_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
	byte mem[VIEWPORT_DRAW_MEM];
137
73f897e1bf4a (svn r138) -Add: 64x64 stations are now nicely painted (increased size of
truelight
parents: 133
diff changeset
  1191
	ParentSpriteToDraw *parent_list[6144];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1192
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1193
	_cur_vd = &vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
	old_dpi = _cur_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
	_cur_dpi = &vd.dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1197
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
	vd.dpi.zoom = vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
	mask = (-1) << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
	vd.combine_sprites = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
	vd.dpi.width = (right - left) & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1204
	vd.dpi.height = (bottom - top) & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
	vd.dpi.left = left & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
	vd.dpi.top = top & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1207
	vd.dpi.pitch = old_dpi->pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1208
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
	x = ((vd.dpi.left - (vp->virtual_left&mask)) >> vp->zoom) + vp->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
	y = ((vd.dpi.top - (vp->virtual_top&mask)) >> vp->zoom) + vp->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1212
	vd.dpi.dst_ptr = old_dpi->dst_ptr + x - old_dpi->left + (y - old_dpi->top) * old_dpi->pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1213
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
	vd.parent_list = parent_list;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1215
	vd.eof_parent_list = endof(parent_list);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
	vd.spritelist_mem = mem;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1217
	vd.eof_spritelist_mem = endof(mem) - sizeof(LARGEST_SPRITELIST_STRUCT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
	vd.last_string = &vd.first_string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
	vd.first_string = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
	vd.last_tile = &vd.first_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
	vd.first_tile = NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1222
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
	ViewportAddLandscape();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
#if !defined(NEW_ROTATION)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
	ViewportAddVehicles(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
	DrawTextEffects(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
	ViewportAddTownNames(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
	ViewportAddStationNames(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
	ViewportAddSigns(&vd.dpi);
395
788a9bba0889 (svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents: 193
diff changeset
  1231
	ViewportAddWaypoints(&vd.dpi);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1232
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1233
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
  1234
	// This assert should never happen (because the length of the parent_list
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
  1235
	//  is checked)
979
11ea18598e16 (svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents: 926
diff changeset
  1236
	assert(vd.parent_list <= endof(parent_list));
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
  1237
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1238
	if (vd.first_tile != NULL) ViewportDrawTileSprites(vd.first_tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1239
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1240
	/* null terminate parent sprite list */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
	*vd.parent_list = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
	ViewportSortParentSprites(parent_list);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1244
	ViewportDrawParentSprites(parent_list);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1245
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1246
	if (vd.first_string != NULL) ViewportDrawStrings(&vd.dpi, vd.first_string);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1247
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
	_cur_dpi = old_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
// Make sure we don't draw a too big area at a time.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
// If we do, the sprite memory will overflow.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1253
static void ViewportDrawChk(ViewPort *vp, int left, int top, int right, int bottom)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
	if (((bottom - top) * (right - left) << vp->zoom) > 180000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
		if ((bottom - top) > (right - left)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
			int t = (top + bottom) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
			ViewportDrawChk(vp, left, top, right, t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1259
			ViewportDrawChk(vp, left, t, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
			int t = (left + right) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
			ViewportDrawChk(vp, left, top, t, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
			ViewportDrawChk(vp, t, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1265
	} else {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1266
		ViewportDoDraw(vp,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1267
			((left - vp->left) << vp->zoom) + vp->virtual_left,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
			((top - vp->top) << vp->zoom) + vp->virtual_top,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
			((right - vp->left) << vp->zoom) + vp->virtual_left,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
			((bottom - vp->top) << vp->zoom) + vp->virtual_top
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1272
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
500
8e52f7797b48 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 497
diff changeset
  1275
static inline void ViewportDraw(ViewPort *vp, int left, int top, int right, int bottom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1277
	if (right <= vp->left || bottom <= vp->top) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1279
	if (left >= vp->left + vp->width) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
	if (left < vp->left) left = vp->left;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1282
	if (right > vp->left + vp->width) right = vp->left + vp->width;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1284
	if (top >= vp->top + vp->height) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
	if (top < vp->top) top = vp->top;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1287
	if (bottom > vp->top + vp->height) bottom = vp->top + vp->height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1288
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
	ViewportDrawChk(vp, left, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1292
void DrawWindowViewport(Window *w)
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1293
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
	DrawPixelInfo *dpi = _cur_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1295
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1296
	dpi->left += w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1297
	dpi->top += w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1298
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1299
	ViewportDraw(w->viewport, dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
	dpi->left -= w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
	dpi->top -= w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1305
void UpdateViewportPosition(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1307
	const ViewPort *vp = w->viewport;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1309
	if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1310
		const Vehicle* veh = GetVehicle(WP(w,vp_d).follow_vehicle);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1311
		Point pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1312
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1313
		SetViewportPosition(w, pt.x, pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1314
	} else {
632
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1315
#if !defined(NEW_ROTATION)
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1316
		int x;
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1317
		int y;
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1318
		int vx;
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1319
		int vy;
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1320
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1321
		// Center of the viewport is hot spot
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1322
		x = WP(w,vp_d).scrollpos_x + vp->virtual_width / 2;
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1323
		y = WP(w,vp_d).scrollpos_y + vp->virtual_height / 2;
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1324
		// Convert viewport coordinates to map coordinates
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1325
		// Calculation is scaled by 4 to avoid rounding errors
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1326
		vx = -x + y * 2;
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1327
		vy =  x + y * 2;
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1328
		// clamp to size of map
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1329
		vx = clamp(vx, 0 * 4, MapMaxX() * TILE_SIZE * 4);
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1330
		vy = clamp(vy, 0 * 4, MapMaxY() * TILE_SIZE * 4);
632
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1331
		// Convert map coordinates to viewport coordinates
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1332
		x = (-vx + vy) / 2;
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1333
		y = ( vx + vy) / 4;
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1334
		// Set position
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1335
		WP(w, vp_d).scrollpos_x = x - vp->virtual_width / 2;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1336
		WP(w, vp_d).scrollpos_y = y - vp->virtual_height / 2;
632
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1337
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1338
		int x,y,t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1339
		int err;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
		x = WP(w,vp_d).scrollpos_x >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1342
		y = WP(w,vp_d).scrollpos_y >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1343
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1344
		t = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
		x = x + y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
		y = x - y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1347
		err= 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1348
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1349
		if (err != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1350
			/* coordinate remap */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1351
			Point pt = RemapCoords(x, y, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1352
			t = (-1) << vp->zoom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1353
			WP(w,vp_d).scrollpos_x = pt.x & t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1354
			WP(w,vp_d).scrollpos_y = pt.y & t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1355
		}
632
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1356
#endif
6528428cbebb (svn r1063) Improve scrolling limits a bit. You now can scroll further away from the map at the NW and NE edge.
tron
parents: 534
diff changeset
  1357
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1358
		SetViewportPosition(w, WP(w, vp_d).scrollpos_x, WP(w, vp_d).scrollpos_y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1359
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1362
static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, int bottom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1364
	right -= vp->virtual_left;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1365
	if (right <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1367
	bottom -= vp->virtual_top;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1368
	if (bottom <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1370
	left = max(0, left - vp->virtual_left);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1372
	if (left >= vp->virtual_width) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1374
	top = max(0, top - vp->virtual_top);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1375
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1376
	if (top >= vp->virtual_height) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1378
	SetDirtyBlocks(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1379
		(left >> vp->zoom) + vp->left,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1380
		(top >> vp->zoom) + vp->top,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1381
		(right >> vp->zoom) + vp->left,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
		(bottom >> vp->zoom) + vp->top
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1384
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1386
void MarkAllViewportsDirty(int left, int top, int right, int bottom)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1388
	const ViewPort *vp = _viewports;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
	uint32 act = _active_viewports;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
		if (act & 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
			assert(vp->width != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
			MarkViewportDirty(vp, left, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1394
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
	} while (vp++,act>>=1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1398
void MarkTileDirtyByTile(TileIndex tile)
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1399
{
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1400
	Point pt = RemapCoords(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, GetTileZ(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
		pt.x - 31,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
		pt.y - 122,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
		pt.x - 31 + 67,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
		pt.y - 122 + 154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1406
	);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
void MarkTileDirty(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1410
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1411
	uint z = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
	Point pt;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1413
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1414
	if (IS_INT_INSIDE(x, 0, MapSizeX() * TILE_SIZE) &&
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1415
			IS_INT_INSIDE(y, 0, MapSizeY() * TILE_SIZE))
1980
6c5917cfcb78 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  1416
		z = GetTileZ(TileVirtXY(x, y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
	pt = RemapCoords(x, y, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1419
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
		pt.x - 31,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1421
		pt.y - 122,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1422
		pt.x - 31 + 67,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
		pt.y - 122 + 154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
	);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1425
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1427
static void SetSelectionTilesDirty(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1429
	int y_size, x_size;
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1430
	int x = _thd.pos.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1431
	int y = _thd.pos.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1433
	x_size = _thd.size.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1434
	y_size = _thd.size.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1436
	if (_thd.outersize.x) {
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1437
		x_size += _thd.outersize.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1438
		x += _thd.offs.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1439
		y_size += _thd.outersize.y;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1440
		y += _thd.offs.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
	assert(x_size > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
	assert(y_size > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
	x_size += x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
	y_size += y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
		int y_bk = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
			MarkTileDirty(x, y);
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1453
		} while ( (y += TILE_SIZE) != y_size);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
		y = y_bk;
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1455
	} while ( (x += TILE_SIZE) != x_size);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
1990
efb67f977138 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1459
void SetSelectionRed(bool b)
efb67f977138 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1460
{
efb67f977138 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1461
	_thd.make_square_red = b;
efb67f977138 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1462
	SetSelectionTilesDirty();
efb67f977138 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1463
}
efb67f977138 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1464
efb67f977138 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1465
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1466
static bool CheckClickOnTown(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1468
	const Town *t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1470
	if (!(_display_opt & DO_SHOW_TOWN_NAMES)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1472
	switch (vp->zoom) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1473
		case 0:
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1474
			x = x - vp->left + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1475
			y = y - vp->top  + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1476
			FOR_ALL_TOWNS(t) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1477
				if (y >= t->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1478
						y < t->sign.top + 12 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1479
						x >= t->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1480
						x < t->sign.left + t->sign.width_1) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1481
					ShowTownViewWindow(t->index);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1482
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1483
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1484
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1485
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1486
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1487
		case 1:
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1488
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1489
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1490
			FOR_ALL_TOWNS(t) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1491
				if (y >= t->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1492
						y < t->sign.top + 24 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1493
						x >= t->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1494
						x < t->sign.left + t->sign.width_1 * 2) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1495
					ShowTownViewWindow(t->index);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1496
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1497
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1498
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1499
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1500
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1501
		default:
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1502
			x = (x - vp->left + 3) * 4 + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1503
			y = (y - vp->top  + 3) * 4 + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1504
			FOR_ALL_TOWNS(t) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1505
				if (y >= t->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1506
						y < t->sign.top + 24 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1507
						x >= t->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1508
						x < t->sign.left + t->sign.width_2 * 4) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1509
					ShowTownViewWindow(t->index);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1510
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1511
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1513
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1518
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1519
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1520
static bool CheckClickOnStation(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1522
	const Station *st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1523
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1524
	if (!(_display_opt & DO_SHOW_STATION_NAMES)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1526
	switch (vp->zoom) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1527
		case 0:
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1528
			x = x - vp->left + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1529
			y = y - vp->top  + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1530
			FOR_ALL_STATIONS(st) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1531
				if (y >= st->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1532
						y < st->sign.top + 12 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1533
						x >= st->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1534
						x < st->sign.left + st->sign.width_1) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1535
					ShowStationViewWindow(st->index);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1536
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1537
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1538
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1539
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1540
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1541
		case 1:
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1542
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1543
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1544
			FOR_ALL_STATIONS(st) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1545
				if (y >= st->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1546
						y < st->sign.top + 24 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1547
						x >= st->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1548
						x < st->sign.left + st->sign.width_1 * 2) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1549
					ShowStationViewWindow(st->index);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1550
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1551
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1553
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1554
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1555
		default:
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1556
			x = (x - vp->left + 3) * 4 + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1557
			y = (y - vp->top  + 3) * 4 + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1558
			FOR_ALL_STATIONS(st) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1559
				if (y >= st->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1560
						y < st->sign.top + 24 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1561
						x >= st->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1562
						x < st->sign.left + st->sign.width_2 * 4) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1563
					ShowStationViewWindow(st->index);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1564
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1565
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1567
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1571
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1572
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1573
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1574
static bool CheckClickOnSign(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
{
4349
1016170ae0cb (svn r6050) -Codechange: mass-renamed SignStruct -> Sign and ss -> si. Now functions and variables all match eachother
truelight
parents: 4346
diff changeset
  1576
	const Sign *si;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1578
	if (!(_display_opt & DO_SHOW_SIGNS)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1580
	switch (vp->zoom) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1581
		case 0:
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1582
			x = x - vp->left + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1583
			y = y - vp->top  + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1584
			FOR_ALL_SIGNS(si) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1585
				if (y >= si->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1586
						y <  si->sign.top + 12 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1587
						x >= si->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1588
						x <  si->sign.left + si->sign.width_1) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1589
					ShowRenameSignWindow(si);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1590
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1591
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1592
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1593
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1594
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1595
		case 1:
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1596
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1597
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1598
			FOR_ALL_SIGNS(si) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1599
				if (y >= si->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1600
						y <  si->sign.top + 24 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1601
						x >= si->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1602
						x <  si->sign.left + si->sign.width_1 * 2) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1603
					ShowRenameSignWindow(si);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1604
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1605
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1606
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1607
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1608
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1609
		default:
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1610
			x = (x - vp->left + 3) * 4 + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1611
			y = (y - vp->top  + 3) * 4 + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1612
			FOR_ALL_SIGNS(si) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1613
				if (y >= si->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1614
						y <  si->sign.top + 24 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1615
						x >= si->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1616
						x <  si->sign.left + si->sign.width_2 * 4) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1617
					ShowRenameSignWindow(si);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1618
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1619
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1621
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1622
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1623
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1625
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1626
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1627
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1628
static bool CheckClickOnWaypoint(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1630
	const Waypoint *wp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1632
	if (!(_display_opt & DO_WAYPOINTS)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1634
	switch (vp->zoom) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1635
		case 0:
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1636
			x = x - vp->left + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1637
			y = y - vp->top  + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1638
			FOR_ALL_WAYPOINTS(wp) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1639
				if (y >= wp->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1640
						y < wp->sign.top + 12 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1641
						x >= wp->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1642
						x < wp->sign.left + wp->sign.width_1) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1643
					ShowRenameWaypointWindow(wp);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1644
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1645
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1647
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1648
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1649
		case 1:
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1650
			x = (x - vp->left + 1) * 2 + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1651
			y = (y - vp->top  + 1) * 2 + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1652
			FOR_ALL_WAYPOINTS(wp) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1653
				if (y >= wp->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1654
						y < wp->sign.top + 24 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1655
						x >= wp->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1656
						x < wp->sign.left + wp->sign.width_1 * 2) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1657
					ShowRenameWaypointWindow(wp);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1658
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1659
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1660
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1661
			break;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1662
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1663
		default:
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1664
			x = (x - vp->left + 3) * 4 + vp->virtual_left;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1665
			y = (y - vp->top  + 3) * 4 + vp->virtual_top;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1666
			FOR_ALL_WAYPOINTS(wp) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1667
				if (y >= wp->sign.top &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1668
						y < wp->sign.top + 24 &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1669
						x >= wp->sign.left &&
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1670
						x < wp->sign.left + wp->sign.width_2 * 4) {
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1671
					ShowRenameWaypointWindow(wp);
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1672
					return true;
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1673
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1674
			}
4471
f8130f9bd1e3 (svn r6256) if () cascades -> switch ()
tron
parents: 4444
diff changeset
  1675
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1676
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1677
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1678
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1679
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1681
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1682
static void CheckClickOnLandscape(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1683
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1684
	Point pt = TranslateXYToTileCoord(vp, x, y);
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1964
diff changeset
  1685
1980
6c5917cfcb78 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  1686
	if (pt.x != -1) ClickTile(TileVirtXY(pt.x, pt.y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1687
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1688
2662
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1689
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1690
static void SafeShowTrainViewWindow(const Vehicle* v)
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1691
{
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  1692
	if (!IsFrontEngine(v)) v = GetFirstVehicleInChain(v);
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  1693
	ShowTrainViewWindow(v);
2662
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1694
}
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1695
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1696
static void Nop(const Vehicle *v) {}
2662
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1697
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1698
typedef void OnVehicleClickProc(const Vehicle *v);
2662
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1699
static OnVehicleClickProc* const _on_vehicle_click_proc[] = {
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1700
	SafeShowTrainViewWindow,
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1701
	ShowRoadVehViewWindow,
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1702
	ShowShipViewWindow,
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1703
	ShowAircraftViewWindow,
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1704
	Nop, // Special vehicles
8b46824bd821 (svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
tron
parents: 2484
diff changeset
  1705
	Nop  // Disaster vehicles
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1706
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1707
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1708
void HandleViewportClicked(const ViewPort *vp, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1709
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1710
	const Vehicle *v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1711
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1712
	if (CheckClickOnTown(vp, x, y)) return;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1713
	if (CheckClickOnStation(vp, x, y)) return;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1714
	if (CheckClickOnSign(vp, x, y)) return;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1715
	if (CheckClickOnWaypoint(vp, x, y)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1716
	CheckClickOnLandscape(vp, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1717
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1718
	v = CheckClickOnVehicle(vp, x, y);
3809
d67cd0232924 (svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents: 3798
diff changeset
  1719
	if (v != NULL) {
d67cd0232924 (svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents: 3798
diff changeset
  1720
		DEBUG(misc, 2) ("Vehicle %d at %p", v->index, v);
d67cd0232924 (svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents: 3798
diff changeset
  1721
		_on_vehicle_click_proc[v->type - 0x10](v);
d67cd0232924 (svn r4819) -Debug: When clicking on a vehicle in the viewport, the index and address of the vehicle get dumped for "misc" debug levels >= 2
celestar
parents: 3798
diff changeset
  1722
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1723
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1724
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1725
Vehicle *CheckMouseOverVehicle(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1726
{
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1727
	const Window *w;
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1728
	const ViewPort *vp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1729
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1730
	int x = _cursor.pos.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
	int y = _cursor.pos.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1732
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1733
	w = FindWindowFromPt(x, y);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1734
	if (w == NULL) return NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1735
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
	vp = IsPtInWindowViewport(w, x, y);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1737
	return (vp != NULL) ? CheckClickOnVehicle(vp, x, y) : NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1742
void PlaceObject(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1743
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1744
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1745
	Window *w;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1746
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
	pt = GetTileBelowCursor();
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1748
	if (pt.x == -1) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1750
	if (_thd.place_mode == VHM_POINT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
		pt.x += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
		pt.y += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1754
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
	_tile_fract_coords.x = pt.x & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
	_tile_fract_coords.y = pt.y & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1758
	w = GetCallbackWnd();
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1759
	if (w != NULL) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1760
		WindowEvent e;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1761
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
		e.event = WE_PLACE_OBJ;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  1763
		e.we.place.pt = pt;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  1764
		e.we.place.tile = TileVirtXY(pt.x, pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1765
		w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1766
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1767
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1768
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1769
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1770
/* scrolls the viewport in a window to a given location */
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4164
diff changeset
  1771
bool ScrollWindowTo(int x , int y, Window *w)
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1772
{
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1773
	Point pt;
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1774
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1775
	pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y));
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1776
	WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1777
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1778
	if (WP(w, vp_d).scrollpos_x == pt.x && WP(w, vp_d).scrollpos_y == pt.y)
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1779
		return false;
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1780
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1781
	WP(w, vp_d).scrollpos_x = pt.x;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1782
	WP(w, vp_d).scrollpos_y = pt.y;
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1783
	return true;
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1784
}
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1785
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 137
diff changeset
  1786
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1787
bool ScrollMainWindowTo(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1788
{
4339
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1789
	Window *w;
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1790
	bool res = ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0));
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1791
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1792
	/* If a user scrolls to a tile (via what way what so ever) and already is on
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1793
	 *  that tile (e.g.: pressed twice), move the smallmap to that location,
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1794
	 *  so you directly see where you are on the smallmap. */
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1795
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1796
	if (res) return res;
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1797
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1798
	w = FindWindowById(WC_SMALLMAP, 0);
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1799
	if (w == NULL) return res;
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1800
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1801
	SmallMapCenterOnCurrentPos(w);
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1802
0b1c9f47e69b (svn r6040) -Add: when clicking twice on a Location Button, the SmallMap centers on your position (based on FS#54 by thomasdev)
truelight
parents: 4334
diff changeset
  1803
	return res;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1804
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1805
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1806
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1807
bool ScrollMainWindowToTile(TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
{
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
  1809
	return ScrollMainWindowTo(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1810
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1811
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1812
void SetRedErrorSquare(TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1813
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1814
	TileIndex old;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1815
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1816
	old = _thd.redsq;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1817
	_thd.redsq = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1818
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1819
	if (tile != old) {
3281
757d7da49445 (svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents: 3279
diff changeset
  1820
		if (tile != 0) MarkTileDirtyByTile(tile);
757d7da49445 (svn r3995) -Fix: Committed one file too much in 3992 (Thanks to Tron for pointing it out)
celestar
parents: 3279
diff changeset
  1821
		if (old  != 0) MarkTileDirtyByTile(old);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1824
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1825
void SetTileSelectSize(int w, int h)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1826
{
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1827
	_thd.new_size.x = w * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1828
	_thd.new_size.y = h * TILE_SIZE;
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1829
	_thd.new_outersize.x = 0;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1830
	_thd.new_outersize.y = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1831
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1832
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1833
void SetTileSelectBigSize(int ox, int oy, int sx, int sy)
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1834
{
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1835
	_thd.offs.x = ox * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1836
	_thd.offs.y = oy * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1837
	_thd.new_outersize.x = sx * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1838
	_thd.new_outersize.y = sy * TILE_SIZE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1839
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1841
/* returns the best autorail highlight type from map coordinates */
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1842
static byte GetAutorailHT(int x, int y)
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1843
{
2710
44278abd3ef9 (svn r3254) - Fix: graphical glitch with autorail tool on a certain tile-type.
Darkvater
parents: 2676
diff changeset
  1844
	return HT_RAIL | _AutorailPiece[x & 0xF][y & 0xF];
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1845
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1846
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1847
// called regular to update tile highlighting in all cases
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1848
void UpdateTileSelection(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1849
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1850
	int x1;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1851
	int y1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1852
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1853
	_thd.new_drawstyle = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1854
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1855
	if (_thd.place_mode == VHM_SPECIAL) {
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1856
		x1 = _thd.selend.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1857
		y1 = _thd.selend.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1858
		if (x1 != -1) {
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1859
			int x2 = _thd.selstart.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1860
			int y2 = _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1861
			x1 &= ~0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1862
			y1 &= ~0xF;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1863
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1864
			if (x1 >= x2) intswap(x1,x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
			if (y1 >= y2) intswap(y1,y2);
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1866
			_thd.new_pos.x = x1;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1867
			_thd.new_pos.y = y1;
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1868
			_thd.new_size.x = x2 - x1 + TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1869
			_thd.new_size.y = y2 - y1 + TILE_SIZE;
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1870
			_thd.new_drawstyle = _thd.next_drawstyle;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1871
		}
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1872
	} else if (_thd.place_mode != VHM_NONE) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1873
		Point pt = GetTileBelowCursor();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1874
		x1 = pt.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1875
		y1 = pt.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1876
		if (x1 != -1) {
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1877
			switch (_thd.place_mode) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1878
				case VHM_RECT:
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1879
					_thd.new_drawstyle = HT_RECT;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1880
					break;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1881
				case VHM_POINT:
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1882
					_thd.new_drawstyle = HT_POINT;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1883
					x1 += 8;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1884
					y1 += 8;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1885
					break;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1886
				case VHM_RAIL:
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1887
					_thd.new_drawstyle = GetAutorailHT(pt.x, pt.y); // draw one highlighted tile
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1888
			}
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1889
			_thd.new_pos.x = x1 & ~0xF;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1890
			_thd.new_pos.y = y1 & ~0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1891
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1892
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1893
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1894
	// redraw selection
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1895
	if (_thd.drawstyle != _thd.new_drawstyle ||
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1896
			_thd.pos.x != _thd.new_pos.x || _thd.pos.y != _thd.new_pos.y ||
4539
0004dc6c3777 (svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents: 4523
diff changeset
  1897
			_thd.size.x != _thd.new_size.x || _thd.size.y != _thd.new_size.y ||
0004dc6c3777 (svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents: 4523
diff changeset
  1898
	    _thd.outersize.x != _thd.new_outersize.x ||
0004dc6c3777 (svn r6368) -Fix [FS#136]: Station catchment area persists after switching tools. The
Darkvater
parents: 4523
diff changeset
  1899
	    _thd.outersize.y != _thd.new_outersize.y) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1900
		// clear the old selection?
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1901
		if (_thd.drawstyle) SetSelectionTilesDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1902
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1903
		_thd.drawstyle = _thd.new_drawstyle;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1904
		_thd.pos = _thd.new_pos;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1905
		_thd.size = _thd.new_size;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1906
		_thd.outersize = _thd.new_outersize;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1907
		_thd.dirty = 0xff;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1909
		// draw the new selection?
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1910
		if (_thd.new_drawstyle) SetSelectionTilesDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1911
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1912
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1913
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1914
// highlighting tiles while only going over them with the mouse
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1964
diff changeset
  1915
void VpStartPlaceSizing(TileIndex tile, int user)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1916
{
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1917
	_thd.userdata = user;
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1918
	_thd.selend.x = TileX(tile) * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1919
	_thd.selstart.x = TileX(tile) * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1920
	_thd.selend.y = TileY(tile) * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1921
	_thd.selstart.y = TileY(tile) * TILE_SIZE;
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1922
	if (_thd.place_mode == VHM_RECT) {
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1923
		_thd.place_mode = VHM_SPECIAL;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1924
		_thd.next_drawstyle = HT_RECT;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1925
	} else if (_thd.place_mode == VHM_RAIL) { // autorail one piece
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1926
		_thd.place_mode = VHM_SPECIAL;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1927
		_thd.next_drawstyle = _thd.drawstyle;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1928
	} else {
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1929
		_thd.place_mode = VHM_SPECIAL;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1930
		_thd.next_drawstyle = HT_POINT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
	_special_mouse_mode = WSM_SIZING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1933
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1934
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1935
void VpSetPlaceSizingLimit(int limit)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
	_thd.sizelimit = limit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1938
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1939
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1940
void VpSetPresizeRange(uint from, uint to)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
{
3421
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1942
	_thd.selend.x = TileX(to) * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1943
	_thd.selend.y = TileY(to) * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1944
	_thd.selstart.x = TileX(from) * TILE_SIZE;
7968a4b5ff0a (svn r4246) -Codechange. Replaced about 100 occurences of '16' by TILE_SIZE
celestar
parents: 3281
diff changeset
  1945
	_thd.selstart.y = TileY(from) * TILE_SIZE;
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1946
	_thd.next_drawstyle = HT_RECT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1947
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1948
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
  1949
static void VpStartPreSizing(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1950
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1951
	_thd.selend.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1952
	_special_mouse_mode = WSM_PRESIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1953
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1954
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
  1955
/* returns information about the 2x1 piece to be build.
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1956
 * The lower bits (0-3) are the track type. */
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1957
static byte Check2x1AutoRail(int mode)
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1958
{
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1959
	int fxpy = _tile_fract_coords.x + _tile_fract_coords.y;
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1960
	int sxpy = (_thd.selend.x & 0xF) + (_thd.selend.y & 0xF);
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1961
	int fxmy = _tile_fract_coords.x - _tile_fract_coords.y;
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1962
	int sxmy = (_thd.selend.x & 0xF) - (_thd.selend.y & 0xF);
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1963
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2817
diff changeset
  1964
	switch (mode) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1965
	case 0: // end piece is lower right
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1966
		if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1967
		if (fxmy < -3 && sxmy > 3) {/* DoRailroadTrack(0); */return 5; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1968
		return 1;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1969
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1970
	case 1:
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1971
		if (fxmy > 3 && sxmy < -3) { /*SwapSelection(); DoRailroadTrack(0); */return 4; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1972
		if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1973
		return 1;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1974
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1975
	case 2:
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1976
		if (fxmy > 3 && sxmy < -3) { /*DoRailroadTrack(3);*/ return 4; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1977
		if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1978
		return 0;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1979
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1980
	case 3:
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1981
		if (fxmy < -3 && sxmy > 3) { /*SwapSelection(); DoRailroadTrack(3);*/ return 5; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1982
		if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; }
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1983
		return 0;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1984
	}
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1985
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1986
	return 0; // avoids compiler warnings
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1987
}
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1988
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1989
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1990
// while dragging
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1991
static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int method)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1992
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1993
	int d;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1994
	byte b=6;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1995
	uint w,h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1996
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1997
	int dx = thd->selstart.x - (thd->selend.x&~0xF);
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1998
	int dy = thd->selstart.y - (thd->selend.y&~0xF);
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1999
	w = myabs(dx) + 16;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2000
	h = myabs(dy) + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2001
1980
6c5917cfcb78 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  2002
	if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2003
		if (method == VPM_RAILDIRS) {
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2004
			b = GetAutorailHT(x, y);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2005
		} else { // rect for autosignals on one tile
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2006
			b = HT_RECT;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2007
		}
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2008
	} else if (h == 16) { // Is this in X direction?
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2009
		if (dx == 16) { // 2x1 special handling
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2010
			b = (Check2x1AutoRail(3)) | HT_LINE;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2011
		} else if (dx == -16) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2012
			b = (Check2x1AutoRail(2)) | HT_LINE;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2013
		} else {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2014
			b = HT_LINE | HT_DIR_X;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2015
		}
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2016
		y = thd->selstart.y;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2017
	} else if (w == 16) { // Or Y direction?
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2018
		if (dy == 16) { // 2x1 special handling
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2019
			b = (Check2x1AutoRail(1)) | HT_LINE;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2020
		} else if (dy == -16) { // 2x1 other direction
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2021
			b = (Check2x1AutoRail(0)) | HT_LINE;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2022
		} else {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2023
			b = HT_LINE | HT_DIR_Y;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2024
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2025
		x = thd->selstart.x;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2026
	} else if (w > h * 2) { // still count as x dir?
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2027
		b = HT_LINE | HT_DIR_X;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2028
		y = thd->selstart.y;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2029
	} else if (h > w * 2) { // still count as y dir?
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2030
		b = HT_LINE | HT_DIR_Y;
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2031
		x = thd->selstart.x;
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2032
	} else { // complicated direction
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2033
		d = w - h;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2034
		thd->selend.x = thd->selend.x & ~0xF;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2035
		thd->selend.y = thd->selend.y & ~0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2036
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2037
		// four cases.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2038
		if (x > thd->selstart.x) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2039
			if (y > thd->selstart.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
				// south
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2041
				if (d == 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2042
					b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2043
				} else if (d >= 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2044
					x = thd->selstart.x + h;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2045
					b = HT_LINE | HT_DIR_VL;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2046
					// return px == py || px == py + 16;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2047
				} else {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2048
					y = thd->selstart.y + w;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2049
					b = HT_LINE | HT_DIR_VR;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2050
				} // return px == py || px == py - 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2051
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2052
				// west
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2053
				if (d == 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2054
					b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2055
				} else if (d >= 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2056
					x = thd->selstart.x + h;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2057
					b = HT_LINE | HT_DIR_HL;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2058
				} else {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2059
					y = thd->selstart.y - w;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2060
					b = HT_LINE | HT_DIR_HU;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2061
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2062
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2063
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2064
			if (y > thd->selstart.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2065
				// east
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2066
				if (d == 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2067
					b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2068
				} else if (d >= 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2069
					x = thd->selstart.x - h;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2070
					b = HT_LINE | HT_DIR_HU;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2071
					// return px == -py || px == -py - 16;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2072
				} else {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2073
					y = thd->selstart.y + w;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2074
					b = HT_LINE | HT_DIR_HL;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2075
				} // return px == -py || px == -py + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2076
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2077
				// north
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2078
				if (d == 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2079
					b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2080
				} else if (d >= 0) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2081
					x = thd->selstart.x - h;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2082
					b = HT_LINE | HT_DIR_VR;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2083
					// return px == py || px == py - 16;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2084
				} else {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2085
					y = thd->selstart.y - w;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2086
					b = HT_LINE | HT_DIR_VL;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2087
				} //return px == py || px == py + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2090
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2091
	thd->selend.x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2092
	thd->selend.y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2093
	thd->next_drawstyle = b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2094
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2095
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2096
// while dragging
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2097
void VpSelectTilesWithMethod(int x, int y, int method)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2098
{
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2099
	int sx;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2100
	int sy;
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2101
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2102
	if (x == -1) {
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2103
		_thd.selend.x = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2104
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2105
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2106
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2107
	// allow drag in any rail direction
58
b9fdcc9b5c90 (svn r59) -Feature: Added Autosignals, just like Autorail. Can copy signal style, convert signal<->semaphore, etc. Big thanks to betatesters Dribbel and Testman57 (Darkvater)
darkvater
parents: 0
diff changeset
  2108
	if (method == VPM_RAILDIRS || method == VPM_SIGNALDIRS) {
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2109
		_thd.selend.x = x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2110
		_thd.selend.y = y;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2111
		CalcRaildirsDrawstyle(&_thd, x, y, method);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2112
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2113
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2114
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2115
	if (_thd.next_drawstyle == HT_POINT) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2116
		x += 8;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2117
		y += 8;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2118
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2119
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2120
	sx = _thd.selstart.x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2121
	sy = _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2122
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2123
	switch (method) {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2124
		case VPM_FIX_X:
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2125
			x = sx;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2126
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2127
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2128
		case VPM_FIX_Y:
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2129
			y = sy;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2130
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2131
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2132
		case VPM_X_OR_Y:
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2133
			if (myabs(sy - y) < myabs(sx - x)) {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2134
				y = sy;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2135
			} else {
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2136
				x = sx;
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2137
			}
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2138
			break;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2139
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2140
		case VPM_X_AND_Y:
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2141
			break;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2142
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2143
		// limit the selected area to a 10x10 rect.
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2144
		case VPM_X_AND_Y_LIMITED: {
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2145
			int limit = (_thd.sizelimit - 1) * 16;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2146
			x = sx + clamp(x - sx, -limit, limit);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2147
			y = sy + clamp(y - sy, -limit, limit);
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2148
			break;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2149
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2150
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2151
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2152
	_thd.selend.x = x;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2153
	_thd.selend.y = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2154
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2155
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
  2156
// while dragging
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  2157
bool VpHandlePlaceSizingDrag(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2158
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2159
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2160
	WindowEvent e;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2161
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2162
	if (_special_mouse_mode != WSM_SIZING) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2163
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  2164
	e.we.place.userdata = _thd.userdata;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2165
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2166
	// stop drag mode if the window has been closed
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2167
	w = FindWindowById(_thd.window_class,_thd.window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2168
	if (w == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2169
		ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2170
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2171
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2172
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2173
	// while dragging execute the drag procedure of the corresponding window (mostly VpSelectTilesWithMethod() )
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2174
	if (_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2175
		e.event = WE_PLACE_DRAG;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  2176
		e.we.place.pt = GetTileBelowCursor();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2177
		w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2178
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2179
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2180
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2181
	// mouse button released..
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2182
	// keep the selected tool, but reset it to the original mode.
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2183
	_special_mouse_mode = WSM_NONE;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2184
	if (_thd.next_drawstyle == HT_RECT) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2185
		_thd.place_mode = VHM_RECT;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  2186
	} else if ((e.we.place.userdata & 0xF) == VPM_SIGNALDIRS) { // some might call this a hack... -- Dominik
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2187
		_thd.place_mode = VHM_RECT;
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2188
	} else if (_thd.next_drawstyle & HT_LINE) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2189
		_thd.place_mode = VHM_RAIL;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2190
	} else if (_thd.next_drawstyle & HT_RAIL) {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2191
		_thd.place_mode = VHM_RAIL;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2192
	} else {
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2193
		_thd.place_mode = VHM_POINT;
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2194
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2195
	SetTileSelectSize(1, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2196
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2197
	// and call the mouseup event.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2198
	e.event = WE_PLACE_MOUSEUP;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  2199
	e.we.place.pt = _thd.selend;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  2200
	e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y);
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4609
diff changeset
  2201
	e.we.place.starttile = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2202
	w->wndproc(w, &e);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2203
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2204
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2205
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2206
1914
2b4b3c3a95b4 (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
  2207
void SetObjectToPlaceWnd(CursorID icon, byte mode, Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2208
{
1914
2b4b3c3a95b4 (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
  2209
	SetObjectToPlace(icon, mode, w->window_class, w->window_number);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2210
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2211
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2212
#include "table/animcursors.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2213
1914
2b4b3c3a95b4 (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
  2214
void SetObjectToPlace(CursorID icon, byte mode, WindowClass window_class, WindowNumber window_num)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2215
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2216
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2217
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2218
	// undo clicking on button
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2219
	if (_thd.place_mode != 0) {
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2220
		_thd.place_mode = 0;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2221
		w = FindWindowById(_thd.window_class, _thd.window_number);
2116
23031555ff54 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2222
		if (w != NULL) CallWindowEventNP(w, WE_ABORT_PLACE_OBJ);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2223
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2224
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2225
	SetTileSelectSize(1, 1);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2226
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2227
	_thd.make_square_red = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2228
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2229
	if (mode == VHM_DRAG) { // mode 4 is for dragdropping trains in the depot window
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2230
		mode = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2231
		_special_mouse_mode = WSM_DRAGDROP;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2232
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2233
		_special_mouse_mode = WSM_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2234
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2235
1863
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2236
	_thd.place_mode = mode;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2237
	_thd.window_class = window_class;
74a8379bb868 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2238
	_thd.window_number = window_num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2239
1070
bd31ed783fd3 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2240
	if (mode == VHM_SPECIAL) // special tools, like tunnels or docks start with presizing mode
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2241
		VpStartPreSizing();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2242
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2243
	if ( (int)icon < 0)
4334
99abd73de061 (svn r6035) -Revert r5900 which supposedly fixed an invalid warning caused by buggy MS software
Darkvater
parents: 4272
diff changeset
  2244
		SetAnimatedMouseCursor(_animcursors[~icon]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2245
	else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2246
		SetMouseCursor(icon);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2247
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2248
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  2249
void ResetObjectToPlace(void)
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  2250
{
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2251
	SetObjectToPlace(SPR_CURSOR_MOUSE, VHM_NONE, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2252
}