viewport.c
author tron
Wed, 16 Nov 2005 12:52:01 +0000
changeset 2662 42c11a1a0a4b
parent 2484 8e0c88a833fb
child 2676 2ba71e034d97
permissions -rw-r--r--
(svn r3204) Make handling of clicking on vehicles a bit less ugly by avoiding function declarations in .c files and unnecessary indirection
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1864
diff changeset
     4
#include "openttd.h"
1299
0a6510cc889b (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1172
diff changeset
     5
#include "debug.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     6
#include "functions.h"
2662
42c11a1a0a4b (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
07514c2cc6d1 (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
dab90d4cbf2d (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
01d3de5d8039 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1349
diff changeset
    10
#include "table/sprites.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 500
diff changeset
    11
#include "table/strings.h"
679
e959706a3e4d (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
2482369a61ff (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
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
    20
#include "waypoint.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2125
diff changeset
    21
#include "variables.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
    23
#define VIEWPORT_DRAW_MEM (65536 * 2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
static bool _added_tile_sprite;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
static bool _offset_ground_sprites;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
typedef struct StringSpriteToDraw {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	uint16 string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	uint16 color;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	struct StringSpriteToDraw *next;
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    32
	int32 x;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    33
	int32 y;
835
a22d6bc16a51 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
    34
	uint32 params[3];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	uint16 width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
} StringSpriteToDraw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
typedef struct TileSpriteToDraw {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
	uint32 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
	struct TileSpriteToDraw *next;
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    41
	int32 x;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    42
	int32 y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
	byte z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
} TileSpriteToDraw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
typedef struct ChildScreenSpriteToDraw {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
	uint32 image;
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    48
	int32 x;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    49
	int32 y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	struct ChildScreenSpriteToDraw *next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
} ChildScreenSpriteToDraw;
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 ParentSpriteToDraw {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	uint32 image;
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    55
	int32 left;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    56
	int32 top;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    57
	int32 right;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    58
	int32 bottom;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    59
	int32 tile_x;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    60
	int32 tile_y;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    61
	int32 tile_right;
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
    62
	int32 tile_bottom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
	ChildScreenSpriteToDraw *child;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    64
	byte unk16;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
	byte tile_z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	byte tile_z_bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
} ParentSpriteToDraw;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
2109
c3202f3988df (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
    69
// Quick hack to know how much memory to reserve when allocating from the spritelist
c3202f3988df (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
    70
// to prevent a buffer overflow.
c3202f3988df (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
    71
#define LARGEST_SPRITELIST_STRUCT ParentSpriteToDraw
c3202f3988df (svn r2619) Fix: [viewport] Fix potential buffer overflow reported by Tron
ludde
parents: 2085
diff changeset
    72
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    73
typedef struct ViewportDrawer {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
	DrawPixelInfo dpi;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
    75
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
    76
	byte *spritelist_mem;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
    77
	const byte *eof_spritelist_mem;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
    78
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
	StringSpriteToDraw **last_string, *first_string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
	TileSpriteToDraw **last_tile, *first_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
	ChildScreenSpriteToDraw **last_child;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    84
	ParentSpriteToDraw **parent_list;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
    85
	ParentSpriteToDraw * const *eof_parent_list;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	byte combine_sprites;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
	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
    90
	bool ground_child;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
} ViewportDrawer;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
static ViewportDrawer *_cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
    95
TileHighlightData _thd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
static TileInfo *_cur_ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
    99
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
   100
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
	Point p = RemapCoords(x, y, z);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   102
	p.x -= vp->virtual_width / 2;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   103
	p.y -= vp->virtual_height / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	return p;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   107
void AssignWindowViewport(Window *w, int x, int y,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
	int width, int height, uint32 follow_flags, byte zoom)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
	ViewPort *vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
	uint32 bit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   114
	for (vp = _viewports, bit = 1; ; vp++, bit <<= 1) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   115
		assert(vp != endof(_viewports));
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   116
		if (vp->width == 0) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
	_active_viewports |= bit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
	vp->left = x + w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
	vp->top = y + w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
	vp->width = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
	vp->height = height;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   124
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
	vp->zoom = zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
	vp->virtual_width = width << zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
	vp->virtual_height = height << zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	if (follow_flags & 0x80000000) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   131
		const Vehicle *veh;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   132
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   133
		WP(w, vp_d).follow_vehicle = (VehicleID)(follow_flags & 0xFFFF);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   134
		veh = GetVehicle(WP(w, vp_d).follow_vehicle);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
		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
   136
	} else {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   137
		uint x = TileX(follow_flags) * 16;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   138
		uint y = TileY(follow_flags) * 16;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   139
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   140
		WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   141
		pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   144
	WP(w, vp_d).scrollpos_x = pt.x;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   145
	WP(w, vp_d).scrollpos_y = pt.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
	w->viewport = vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	vp->virtual_left = 0;//pt.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
	vp->virtual_top = 0;//pt.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
static Point _vp_move_offs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
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
   154
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
	for (; w < _last_window; w++) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
		if (left + width > w->left &&
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   157
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
				top + height > w->top &&
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   159
				w->top + w->height > top) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   160
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
			if (left < w->left) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
				DoSetViewportPosition(w, left, top, w->left - left, height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
				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
   164
				return;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
			if (left + width > w->left + w->width) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
				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
   169
				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
   170
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
			if (top < w->top) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
				DoSetViewportPosition(w, left, top, width, (w->top - top));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
				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
   176
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
			if (top + height > w->top + w->height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
				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
   181
				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
   182
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
		int xo = _vp_move_offs.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
		int yo = _vp_move_offs.y;
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
		if (abs(xo) >= width || abs(yo) >= height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
			/* fully_outside */
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   195
			RedrawScreenRect(left, top, left + width, top + height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
		}
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
		GfxScroll(left, top, width, height, xo, yo);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
		if (xo > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
			RedrawScreenRect(left, top, xo + left, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
			left += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
			width -= xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
		} else if (xo < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
			RedrawScreenRect(left+width+xo, top, left+width, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
			width += xo;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
		if (yo > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
			RedrawScreenRect(left, top, width+left, top + yo);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
		} else if (yo < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
			RedrawScreenRect(left, top + height + yo, width+left, top + height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
		}
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
void SetViewportPosition(Window *w, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
	ViewPort *vp = w->viewport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
	int old_left = vp->virtual_left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
	int old_top = vp->virtual_top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
	int left, top, width, height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	vp->virtual_left = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
	vp->virtual_top = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
	old_left >>= vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
	old_top >>= vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	x >>= vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
	y >>= vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	old_left -= x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
	old_top -= y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   237
	if (old_top == 0 && old_left == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
	_vp_move_offs.x = old_left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
	_vp_move_offs.y = old_top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	left = vp->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
	top = vp->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
	width = vp->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	height = vp->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	if (left < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
		width += left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
		left = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   252
	i = left + width - _screen.width;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   253
	if (i >= 0) width -= i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
	if (width > 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
		if (top < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
			height += top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
			top = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
		}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   260
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   261
		i = top + height - _screen.height;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   262
		if (i >= 0) height -= i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   264
		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
   265
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   269
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
   270
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
	ViewPort *vp = w->viewport;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   272
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	if (vp != NULL &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
	    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
   275
			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
   276
		return vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   281
static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y)
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   282
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
	int z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	int a,b;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	if ( (uint)(x -= vp->left) >= (uint)vp->width ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
				(uint)(y -= vp->top) >= (uint)vp->height) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
				Point pt = {-1, -1};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
				return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
	}
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
	x = ((x << vp->zoom) + vp->virtual_left) >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
	y = ((y << vp->zoom) + vp->virtual_top) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
#if !defined(NEW_ROTATION)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
	a = y-x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
	b = y+x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
#else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
	a = x+y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	b = x-y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	z = GetSlopeZ(a, b) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
	z = GetSlopeZ(a+z, b+z) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
	z = GetSlopeZ(a+z, b+z) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
	z = GetSlopeZ(a+z, b+z) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
	z = GetSlopeZ(a+z, b+z) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
	pt.x = a+z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
	pt.y = b+z;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   311
856
07dc27d0503e (svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents: 849
diff changeset
   312
	if ((uint)pt.x >= MapMaxX() * 16 || (uint)pt.y >= MapMaxY() * 16) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
		pt.x = pt.y = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
981
25c7b445dcb8 (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
   319
/* When used for zooming, check area below current coordinates (x,y)
25c7b445dcb8 (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
   320
 * and return the tile of the zoomed out/in position (zoom_x, zoom_y)
25c7b445dcb8 (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
   321
 * when you just want the tile, make x = zoom_x and y = zoom_y */
25c7b445dcb8 (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
   322
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
   323
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
	ViewPort *vp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
	Point pt;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   327
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   328
	if ( (w = FindWindowFromPt(x, y)) != NULL &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
			 (vp = IsPtInWindowViewport(w, x, y)) != NULL)
981
25c7b445dcb8 (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
   330
				return TranslateXYToTileCoord(vp, zoom_x, zoom_y);
0
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
	pt.y = pt.x = -1;
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
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
   336
Point GetTileBelowCursor(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
{
981
25c7b445dcb8 (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
	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
   339
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
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
   341
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
   342
Point GetTileZoomCenterWindow(bool in, Window * w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
	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
   345
	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
   346
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
   347
	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
   348
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2023
diff changeset
   349
	if (in) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   350
		x = ((_cursor.pos.x - vp->left) >> 1) + (vp->width >> 2);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   351
		y = ((_cursor.pos.y - vp->top) >> 1) + (vp->height >> 2);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   352
	} 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
   353
		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
   354
		y = vp->height - (_cursor.pos.y - vp->top);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
	}
981
25c7b445dcb8 (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
   356
	/* Get the tile below the cursor and center on the zoomed-out center */
25c7b445dcb8 (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
   357
	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
   358
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
849
c6223dbdb202 (svn r1330) Increase size of some vars from int16 to int32 to guard against future overflows
tron
parents: 835
diff changeset
   360
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
   361
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
	TileSpriteToDraw *ts;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   364
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   365
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   367
	if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
2013
1b80954e9594 (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1990
diff changeset
   368
		DEBUG(misc, 0) ("Out of sprite mem");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
	}
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   371
	ts = (TileSpriteToDraw*)vd->spritelist_mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
	vd->spritelist_mem += sizeof(TileSpriteToDraw);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   374
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
	ts->image = image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
	ts->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
	ts->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
	ts->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
	ts->z = z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
	*vd->last_tile = ts;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   381
	vd->last_tile = &ts->next;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
void DrawGroundSprite(uint32 image)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
	if (_offset_ground_sprites) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
		// offset ground sprite because of foundation?
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
		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
   389
	} else {
1083
2e9d525af38d (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   390
		_added_tile_sprite = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
		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
   392
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   395
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
void OffsetGroundSprite(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
	_cur_vd->offs_x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
	_cur_vd->offs_y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
	_offset_ground_sprites = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
}
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
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
   404
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   405
	const ViewportDrawer *vd = _cur_vd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
	Point pt = RemapCoords(x, y, z);
2319
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   407
	const Sprite* spr = GetSprite(image & SPRITE_MASK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
2319
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   409
	if (pt.x + spr->x_offs >= vd->dpi.left + vd->dpi.width ||
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   410
			pt.x + spr->x_offs + spr->width <= vd->dpi.left ||
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   411
			pt.y + spr->y_offs >= vd->dpi.top + vd->dpi.height ||
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   412
			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
   413
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   415
	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
   416
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
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
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
   420
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
	ParentSpriteToDraw *ps;
2319
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   423
	const Sprite* spr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   426
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
	if (vd->combine_sprites == 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
		AddCombinedSprite(image, x, y, z);
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   432
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
	vd->last_child = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   435
	if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
2013
1b80954e9594 (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1990
diff changeset
   436
		DEBUG(misc, 0) ("Out of sprite mem");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
	}
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   439
	ps = (ParentSpriteToDraw*)vd->spritelist_mem;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   440
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   441
	if (vd->parent_list >= vd->eof_parent_list) {
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   442
		// 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
   443
		//  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
   444
		//  sort-list, this function). To solve it, increase
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   445
		//  parent_list somewhere below to a higher number.
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
   446
		// 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
   447
		//  spots on the screen ;)
2013
1b80954e9594 (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1990
diff changeset
   448
		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
   449
		return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   450
	}
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   451
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   452
	vd->spritelist_mem += sizeof(ParentSpriteToDraw);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
	ps->image = image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
	ps->tile_x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
	ps->tile_right = x + w - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   458
	ps->tile_y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
	ps->tile_bottom = y + h - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	ps->tile_z = z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
	ps->tile_z_bottom = z + dz - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
	pt = RemapCoords(x, y, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
2319
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   466
	spr = GetSprite(image & SPRITE_MASK);
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   467
	if ((ps->left   = (pt.x += spr->x_offs)) >= vd->dpi.left + vd->dpi.width ||
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   468
			(ps->right  = (pt.x +  spr->width )) <= vd->dpi.left ||
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   469
			(ps->top    = (pt.y += spr->y_offs)) >= vd->dpi.top + vd->dpi.height ||
9902d3ffa309 (svn r2845) Remove sprite size caching, it was unused
tron
parents: 2187
diff changeset
   470
			(ps->bottom = (pt.y +  spr->height)) <= vd->dpi.top) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
	ps->unk16 = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
	ps->child = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
	vd->last_child = &ps->child;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   478
	*vd->parent_list++ = ps;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   480
	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
   481
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
   483
void StartSpriteCombine(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
	_cur_vd->combine_sprites = 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
   488
void EndSpriteCombine(void)
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
	_cur_vd->combine_sprites = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
void AddChildSpriteScreen(uint32 image, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   495
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
	ChildScreenSpriteToDraw *cs;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   497
2187
2a51f8925eeb (svn r2702) -Codechange: Cleaned up the sprite code and replaced many magic numbers
celestar
parents: 2186
diff changeset
   498
	assert((image & SPRITE_MASK) < MAX_SPRITES);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   500
	if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
2013
1b80954e9594 (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1990
diff changeset
   501
		DEBUG(misc, 0) ("Out of sprite mem");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   502
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
	}
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   504
	cs = (ChildScreenSpriteToDraw*)vd->spritelist_mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   506
	if (vd->last_child == NULL) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   507
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   508
	vd->spritelist_mem += sizeof(ChildScreenSpriteToDraw);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
	*vd->last_child = cs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   511
	vd->last_child = &cs->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
	cs->image = image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
	cs->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
	cs->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
	cs->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   519
/* Returns a StringSpriteToDraw */
835
a22d6bc16a51 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
   520
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
   521
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
	StringSpriteToDraw *ss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   525
	if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
2013
1b80954e9594 (svn r2521) -Codechange: Removed trailing "\n"s from DEBUG statements
celestar
parents: 1990
diff changeset
   526
		DEBUG(misc, 0) ("Out of sprite mem");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
		return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
	}
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   529
	ss = (StringSpriteToDraw*)vd->spritelist_mem;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
	vd->spritelist_mem += sizeof(StringSpriteToDraw);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
	ss->string = string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
	ss->next = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
	ss->x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
	ss->y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
	ss->params[0] = params_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
	ss->params[1] = params_2;
835
a22d6bc16a51 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
   539
	ss->params[2] = params_3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   540
	ss->width = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   541
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
	*vd->last_string = ss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
	vd->last_string = &ss->next;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
	return ss;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   548
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   549
#ifdef DEBUG_HILIGHT_MARKED_TILES
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   550
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   551
static void DrawHighlighedTile(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
{
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   553
	if (_m[ti->tile].extra & 0x80) {
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   554
		DrawSelectionSprite(PALETTE_TILE_RED_PULSATING | (SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]), ti);
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   555
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   557
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   558
int _debug_marked_tiles, _debug_red_tiles;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   559
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   560
// Helper functions that allow you mark a tile as red.
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   561
void DebugMarkTile(TileIndex tile) {
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   562
	_debug_marked_tiles++;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   563
	if (_m[tile].extra & 0x80)
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   564
		return;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   565
	_debug_red_tiles++;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   566
	MarkTileDirtyByTile(tile);
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   567
	_m[tile].extra = (_m[tile].extra & ~0xE0) | 0x80;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   570
void DebugClearMarkedTiles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
{
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   572
	uint size = MapSize(), i;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   573
	for(i=0; i!=size; i++) {
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   574
		if (_m[i].extra & 0x80) {
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   575
			_m[i].extra &= ~0x80;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   576
			MarkTileDirtyByTile(i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
		}
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   578
	}
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   579
	_debug_red_tiles = 0;
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   580
	_debug_red_tiles = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   583
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
static void DrawSelectionSprite(uint32 image, const TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
{
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   588
	if (_added_tile_sprite && !(_thd.drawstyle & HT_LINE)) { // draw on real ground
1083
2e9d525af38d (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   589
		DrawGroundSpriteAt(image, ti->x, ti->y, ti->z + 7);
2e9d525af38d (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   590
	} else { // draw on top of foundation
2e9d525af38d (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   591
		AddSortableSpriteToDraw(image, ti->x, ti->y, 0x10, 0x10, 1, ti->z + 7);
2e9d525af38d (svn r1584) Fix: Highlighlighting tiles under bridges works again correctly for square selection tools.
dominik
parents: 1070
diff changeset
   592
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
static bool IsPartOfAutoLine(int px, int py)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
{
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   597
	px -= _thd.selstart.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   598
	py -= _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   600
	switch(_thd.drawstyle) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   601
	case HT_LINE | HT_DIR_X:  return py == 0; // x direction
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   602
	case HT_LINE | HT_DIR_Y:  return px == 0; // y direction
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   603
	case HT_LINE | HT_DIR_HU: return px == -py || px == -py - 16; // horizontal upper
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   604
	case HT_LINE | HT_DIR_HL: return px == -py || px == -py + 16; // horizontal lower
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   605
	case HT_LINE | HT_DIR_VL: return px == py || px == py + 16; // vertival left
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   606
	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
   607
	default:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   608
		NOT_REACHED();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   610
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
	/* useless, but avoids compiler warning this way */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   615
// [direction][side]
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   616
static const int AutorailType[6][2] = {
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   617
	{ HT_DIR_X,  HT_DIR_X },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   618
	{ HT_DIR_Y,  HT_DIR_Y },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   619
	{ HT_DIR_HU, HT_DIR_HL },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   620
	{ HT_DIR_HL, HT_DIR_HU },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   621
	{ HT_DIR_VL, HT_DIR_VR },
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   622
	{ HT_DIR_VR, HT_DIR_VL }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   623
};
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   624
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   625
#include "table/autorail.h"
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   626
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
static void DrawTileSelection(const TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
	uint32 image;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
2125
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   631
#ifdef DEBUG_HILIGHT_MARKED_TILES
3098398bf7ff (svn r2635) Fix: [ntp/misc] Improve the old pathfinder. Changed it to A* instead of Dijkstra.
ludde
parents: 2116
diff changeset
   632
	DrawHighlighedTile(ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
#endif
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   634
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   635
	// Draw a red error square?
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   636
	if (_thd.redsq != 0 && _thd.redsq == ti->tile) {
1864
83c91b158180 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   637
		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
   638
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
	// no selection active?
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   642
	if (_thd.drawstyle == 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
	// Inside the inner area?
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   645
	if (IS_INSIDE_1D(ti->x, _thd.pos.x, _thd.size.x) &&
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   646
			IS_INSIDE_1D(ti->y, _thd.pos.y, _thd.size.y)) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   647
		if (_thd.drawstyle & HT_RECT) {
1864
83c91b158180 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   648
			image = SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh];
83c91b158180 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   649
			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
   650
			DrawSelectionSprite(image, ti);
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   651
		} else if (_thd.drawstyle & HT_POINT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
			// Figure out the Z coordinate for the single dot.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
			byte z = ti->z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   654
			if (ti->tileh & 8) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   655
				z += 8;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   656
				if (!(ti->tileh & 2) && (IsSteepTileh(ti->tileh))) z += 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
			}
1864
83c91b158180 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   658
			DrawGroundSpriteAt(_cur_dpi->zoom != 2 ? SPR_DOT : SPR_DOT_SMALL, ti->x, ti->y, z);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   659
		} else if (_thd.drawstyle & HT_RAIL /*&& _thd.place_mode == VHM_RAIL*/) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   660
			// autorail highlight piece under cursor
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   661
			uint type = _thd.drawstyle & 0xF;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   662
			assert(type <= 5);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   663
			image = SPR_AUTORAIL_BASE + AutorailTilehSprite[ti->tileh][AutorailType[type][0]];
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   664
1864
83c91b158180 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   665
			if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   666
			DrawSelectionSprite(image, ti);
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   667
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   668
		} else if (IsPartOfAutoLine(ti->x, ti->y)) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   669
			// autorail highlighting long line
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   670
			int dir = _thd.drawstyle & ~0xF0;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   671
			uint side;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   672
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   673
			if (dir < 2) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   674
				side = 0;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   675
			} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   676
				TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   677
				int diffx = myabs(TileX(start) - TileX(ti->tile));
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   678
				int diffy = myabs(TileY(start) - TileY(ti->tile));
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   679
				side = myabs(diffx - diffy);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   680
			}
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
   681
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   682
			image = SPR_AUTORAIL_BASE + AutorailTilehSprite[ti->tileh][AutorailType[dir][side]];
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
   683
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   684
			if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   685
			DrawSelectionSprite(image, ti);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
   686
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   690
	// Check if it's inside the outer area?
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   691
	if (_thd.outersize.x &&
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   692
			_thd.size.x < _thd.size.x + _thd.outersize.x &&
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   693
			IS_INSIDE_1D(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) &&
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
   694
			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
   695
		// Draw a blue rect.
1864
83c91b158180 (svn r2370) Replace some magic numbers with symbolic names
tron
parents: 1863
diff changeset
   696
		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
   697
		return;
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
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
   701
static void ViewportAddLandscape(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
	ViewportDrawer *vd = _cur_vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
	int x, y, width, height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
	TileInfo ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
	bool direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
	_cur_ti = &ti;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
	// 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
   711
#if !defined(NEW_ROTATION)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
	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
   713
	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
   714
#else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
	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
   716
	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
   717
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
	// determine size of area
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
	{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
		Point pt = RemapCoords(x, y, 241);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
		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
   722
		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
   723
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
	assert(width > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
	assert(height > 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   727
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
	direction = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   729
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   731
		int width_cur = width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
		int x_cur = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
		int y_cur = y;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   734
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   735
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
			FindLandscapeHeight(&ti, x_cur, y_cur);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   737
#if !defined(NEW_ROTATION)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   738
			y_cur += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
			x_cur -= 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   740
#else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
			y_cur += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   742
			x_cur += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   743
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
			_added_tile_sprite = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
			_offset_ground_sprites = false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   746
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
			DrawTile(&ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
			DrawTileSelection(&ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
		} while (--width_cur);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   750
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
#if !defined(NEW_ROTATION)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
		if ( (direction^=1) != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
			y += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
		else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
			x += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
#else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
		if ( (direction^=1) != 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
			x += 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
		else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
			y -= 0x10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
#endif
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   762
	} while (--height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   766
static void ViewportAddTownNames(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
	Town *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
	int left, top, right, bottom;
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 (!(_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
   772
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
	if (dpi->zoom < 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
		FOR_ALL_TOWNS(t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
			if (t->xy &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
			    bottom > t->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
					top < t->sign.top + 12 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
					right > t->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
					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
   786
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   787
				AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   788
					_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   789
					t->index, t->population, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
	} else if (dpi->zoom == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
		right += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
		bottom += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
		FOR_ALL_TOWNS(t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
			if (t->xy &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
			    bottom > t->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
					top < t->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
					right > t->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
					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
   802
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   803
				AddStringToDraw(t->sign.left + 1, t->sign.top + 1,
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   804
					_patches.population_in_label ? STR_TOWN_LABEL_POP : STR_TOWN_LABEL,
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   805
					t->index, t->population, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   806
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   808
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
		right += 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
		bottom += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
		assert(dpi->zoom == 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
		FOR_ALL_TOWNS(t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
			if (t->xy &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
			    bottom > t->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   816
					top < t->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
					right > t->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
					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
   819
2070
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   820
				AddStringToDraw(t->sign.left + 5, t->sign.top + 1, STR_TOWN_LABEL_TINY_BLACK, t->index, 0, 0);
26c657906f25 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2026
diff changeset
   821
				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
   822
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
		}
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   826
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   827
static void ViewportAddStationNames(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   828
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   830
	Station *st;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   831
	StringSpriteToDraw *sstd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   832
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
	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
   834
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   836
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   839
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
	if (dpi->zoom < 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
		FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
			if (st->xy &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
			    bottom > st->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
					top < st->sign.top + 12 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
					right > st->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
					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
   848
835
a22d6bc16a51 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
   849
				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
   850
				if (sstd != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
					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
   852
					sstd->width = st->sign.width_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   854
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   856
	} else if (dpi->zoom == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   857
		right += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   858
		bottom += 2;
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
		FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   861
			if (st->xy &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
			    bottom > st->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   863
					top < st->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
					right > st->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
					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
   866
835
a22d6bc16a51 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
   867
				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
   868
				if (sstd != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
					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
   870
					sstd->width = st->sign.width_1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   871
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   873
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   875
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
		assert(dpi->zoom == 2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   878
		right += 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
		bottom += 5;
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
		FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
			if (st->xy &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   883
			    bottom > st->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
					top < st->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
					right > st->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
					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
   887
1964
b425e1917ab5 (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
   888
				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
   889
				if (sstd != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   890
					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
   891
					sstd->width = st->sign.width_2 | 0x8000;
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
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   894
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   895
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   896
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   898
static void ViewportAddSigns(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   899
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
	SignStruct *ss;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
	StringSpriteToDraw *sstd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
	if (!(_display_opt & DO_SHOW_SIGNS))
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
	if (dpi->zoom < 1) {
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 981
diff changeset
   913
		FOR_ALL_SIGNS(ss) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
			if (ss->str &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
					bottom > ss->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
					top < ss->sign.top + 12 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
					right > ss->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
					left < ss->sign.left + ss->sign.width_1) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   919
835
a22d6bc16a51 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
   920
				sstd=AddStringToDraw(ss->sign.left + 1, ss->sign.top + 1, STR_2806, ss->str, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
				if (sstd != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
					sstd->width = ss->sign.width_1;
1165
2cdf7a0e217a (svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents: 1109
diff changeset
   923
					sstd->color = (ss->owner==OWNER_NONE)?14:_player_colors[ss->owner];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   926
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
	} else if (dpi->zoom == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
		right += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
		bottom += 2;
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 981
diff changeset
   930
		FOR_ALL_SIGNS(ss) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   931
			if (ss->str &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
					bottom > ss->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
					top < ss->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   934
					right > ss->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
					left < ss->sign.left + ss->sign.width_1*2) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   936
835
a22d6bc16a51 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
   937
				sstd=AddStringToDraw(ss->sign.left + 1, ss->sign.top + 1, STR_2806, ss->str, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
				if (sstd != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
					sstd->width = ss->sign.width_1;
1172
ef009694695c (svn r1674) - Fix: Signs are now displayed in the correct color at all zoom levels
dominik
parents: 1165
diff changeset
   940
					sstd->color = (ss->owner==OWNER_NONE)?14:_player_colors[ss->owner];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   943
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
		right += 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
		bottom += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 981
diff changeset
   948
		FOR_ALL_SIGNS(ss) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
			if (ss->str &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   950
					bottom > ss->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
					top < ss->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
					right > ss->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
					left < ss->sign.left + ss->sign.width_2*4) {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   954
1172
ef009694695c (svn r1674) - Fix: Signs are now displayed in the correct color at all zoom levels
dominik
parents: 1165
diff changeset
   955
				sstd=AddStringToDraw(ss->sign.left + 1, ss->sign.top + 1, STR_2002, ss->str, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
				if (sstd != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
					sstd->width = ss->sign.width_2 | 0x8000;
1172
ef009694695c (svn r1674) - Fix: Signs are now displayed in the correct color at all zoom levels
dominik
parents: 1165
diff changeset
   958
					sstd->color = (ss->owner==OWNER_NONE)?14:_player_colors[ss->owner];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   960
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   961
		}
0
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   964
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
   965
static void ViewportAddWaypoints(DrawPixelInfo *dpi)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   966
{
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   967
	Waypoint *wp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
	int left, top, right, bottom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
	StringSpriteToDraw *sstd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
395
4c990f33dab7 (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
   972
	if (!(_display_opt & DO_WAYPOINTS))
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
		return;
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
	left = dpi->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	top = dpi->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   977
	right = left + dpi->width;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   978
	bottom = top + dpi->height;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
	if (dpi->zoom < 1) {
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   981
		FOR_ALL_WAYPOINTS(wp) {
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   982
			if (wp->xy &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   983
					bottom > wp->sign.top &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   984
					top < wp->sign.top + 12 &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   985
					right > wp->sign.left &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   986
					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
   987
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   988
				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
   989
				if (sstd != NULL) {
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   990
					sstd->width = wp->sign.width_1;
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   991
					sstd->color = (wp->deleted ? 0xE : 11);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   992
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
   994
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
	} else if (dpi->zoom == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
		right += 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
		bottom += 2;
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   998
		FOR_ALL_WAYPOINTS(wp) {
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
   999
			if (wp->xy &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1000
					bottom > wp->sign.top &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1001
					top < wp->sign.top + 24 &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1002
					right > wp->sign.left &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1003
					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
  1004
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1005
				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
  1006
				if (sstd != NULL) {
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1007
					sstd->width = wp->sign.width_1;
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1008
					sstd->color = (wp->deleted ? 0xE : 11);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1009
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1010
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1011
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1013
		right += 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
		bottom += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1015
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1016
		FOR_ALL_WAYPOINTS(wp) {
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1017
			if (wp->xy &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1018
					bottom > wp->sign.top &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1019
					top < wp->sign.top + 24 &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1020
					right > wp->sign.left &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1021
					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
  1022
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1023
				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
  1024
				if (sstd != NULL) {
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1025
					sstd->width = wp->sign.width_2 | 0x8000;
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1026
					sstd->color = (wp->deleted ? 0xE : 11);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1029
		}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
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
  1034
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
	char buffer[128];
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1036
	uint w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
	sign->top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
	GetString(buffer, str);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
	w = GetStringWidth(buffer) + 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
	sign->width_1 = w;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1043
	sign->left = left - w / 2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1045
	// zoomed out version
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
	_stringwidth_base = 0xE0;
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1047
	w = GetStringWidth(buffer) + 3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
	_stringwidth_base = 0;
1390
53a5713cf3f9 (svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
Darkvater
parents: 1363
diff changeset
  1049
	sign->width_2 = w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1050
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
410
8de2aaf20800 (svn r607) -Patch: [ 985102 ] static cleanup
tron
parents: 395
diff changeset
  1053
static void ViewportDrawTileSprites(TileSpriteToDraw *ts)
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1054
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1055
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
		Point pt = RemapCoords(ts->x, ts->y, ts->z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
		DrawSprite(ts->image, pt.x, pt.y);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1058
		ts = ts->next;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1059
	} while (ts != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1062
static void ViewportSortParentSprites(ParentSpriteToDraw* psd[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1064
	while (*psd != NULL) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1065
		ParentSpriteToDraw* ps = *psd;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
		if (!(ps->unk16 & 1)) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1068
			ParentSpriteToDraw** psd2 = psd;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1069
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
			ps->unk16 |= 1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1071
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1072
			while (*++psd2 != NULL) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1073
				ParentSpriteToDraw* ps2 = *psd2;
1934
b3d568113d4d (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
				bool mustswap = false;
b3d568113d4d (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
  1075
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1076
				if (ps2->unk16 & 1) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
1934
b3d568113d4d (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
  1078
				// Decide which sort order algorithm to use, based on whether the sprites have some overlapping area.
b3d568113d4d (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
  1079
				if (((ps2->tile_x > ps->tile_x && ps2->tile_x < ps->tile_right) ||
b3d568113d4d (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
  1080
				    (ps2->tile_right > ps->tile_x && ps2->tile_x < ps->tile_right)) &&        // overlap in X
b3d568113d4d (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
  1081
				    ((ps2->tile_y > ps->tile_y && ps2->tile_y < ps->tile_bottom) ||
b3d568113d4d (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
  1082
				    (ps2->tile_bottom > ps->tile_y && ps2->tile_y < ps->tile_bottom)) &&      // overlap in Y
b3d568113d4d (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
  1083
				    ((ps2->tile_z > ps->tile_z && ps2->tile_z < ps->tile_z_bottom) ||
b3d568113d4d (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
				    (ps2->tile_z_bottom > ps->tile_z && ps2->tile_z < ps->tile_z_bottom)) ) { // overlap in Z
b3d568113d4d (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
  1085
					// Sprites overlap.
b3d568113d4d (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
  1086
					// Use X+Y+Z as the sorting order, so sprites nearer the bottom of the screen,
b3d568113d4d (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
  1087
					// and with higher Z elevation, draw in front.
b3d568113d4d (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
  1088
					// Here X,Y,Z are the coordinates of the "center of mass" of the sprite,
b3d568113d4d (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
  1089
					// i.e. X=(left+right)/2, etc.
b3d568113d4d (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
  1090
					// However, since we only care about order, don't actually calculate the division / 2.
b3d568113d4d (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
  1091
					mustswap = ps->tile_x + ps->tile_right + ps->tile_y + ps->tile_bottom + ps->tile_z + ps->tile_z_bottom >
b3d568113d4d (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
  1092
					           ps2->tile_x + ps2->tile_right + ps2->tile_y + ps2->tile_bottom + ps2->tile_z + ps2->tile_z_bottom;
b3d568113d4d (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
  1093
				} else {
b3d568113d4d (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
  1094
					// No overlap; use the original TTD sort algorithm.
b3d568113d4d (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
  1095
					mustswap = (ps->tile_right >= ps2->tile_x &&
b3d568113d4d (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
  1096
					            ps->tile_bottom >= ps2->tile_y &&
b3d568113d4d (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
  1097
					            ps->tile_z_bottom >= ps2->tile_z &&
b3d568113d4d (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
  1098
					           (ps->tile_x >= ps2->tile_right ||
b3d568113d4d (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
  1099
					            ps->tile_y >= ps2->tile_bottom ||
b3d568113d4d (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
  1100
					            ps->tile_z >= ps2->tile_z_bottom));
b3d568113d4d (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
  1101
				}
b3d568113d4d (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
  1102
				if (mustswap) {
b3d568113d4d (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
  1103
					// Swap the two sprites ps and ps2 using bubble-sort algorithm.
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1104
					ParentSpriteToDraw** psd3 = psd;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1105
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1106
					do {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1107
						ParentSpriteToDraw* temp = *psd3;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
						*psd3 = ps2;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1109
						ps2 = temp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
						psd3++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
					} while (psd3 <= psd2);
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
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
			psd++;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
		}
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1121
static void ViewportDrawParentSprites(ParentSpriteToDraw *psd[])
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1123
	for (; *psd != NULL; psd++) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1124
		const ParentSpriteToDraw* ps = *psd;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1125
		Point pt = RemapCoords(ps->tile_x, ps->tile_y, ps->tile_z);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1126
		const ChildScreenSpriteToDraw* cs;
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
		DrawSprite(ps->image, pt.x, pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1130
		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
  1131
			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
  1132
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1133
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1134
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1136
static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
	DrawPixelInfo dp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1139
	byte zoom;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1140
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
	_cur_dpi = &dp;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	dp = *dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1144
	zoom = dp.zoom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1145
	dp.zoom = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
	dp.left >>= zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
	dp.top >>= zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
	dp.width >>= zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1150
	dp.height >>= zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1153
		if (ss->width != 0) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1154
			int x = (ss->x >> zoom) - 1;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1155
			int y = (ss->y >> zoom) - 1;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1156
			int bottom = y + 11;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1157
			int w = ss->width;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1158
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
			if (w & 0x8000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
				w &= ~0x8000;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
				y--;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
				bottom -= 6;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1163
				w -= 3;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1166
		/* Draw the rectangle if 'tranparent station signs' is off,
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1167
		 * or if we are drawing a general text sign (STR_2806) */
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1168
			if (!(_display_opt & DO_TRANS_SIGNS) || ss->string == STR_2806)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1169
				DrawFrameRect(
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1170
					x, y, x + w, bottom, ss->color,
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1171
					(_display_opt & DO_TRANS_BUILDINGS) ? FR_TRANSPARENT | FR_NOBORDER : 0
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1172
				);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
534
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1175
		SetDParam(0, ss->params[0]);
17ab2f22ff74 (svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents: 507
diff changeset
  1176
		SetDParam(1, ss->params[1]);
835
a22d6bc16a51 (svn r1312) -Add: Patch which is on by default: population in label of the town
truelight
parents: 679
diff changeset
  1177
		SetDParam(2, ss->params[2]);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1178
		/* if we didn't draw a rectangle, or if transparant building is on,
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1179
		 * draw the text in the color the rectangle would have */
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1180
		if ((
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1181
					(_display_opt & DO_TRANS_BUILDINGS) ||
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1182
					(_display_opt & DO_TRANS_SIGNS && ss->string != STR_2806)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1183
				) && ss->width != 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1184
			/* Real colors need the IS_PALETTE_COLOR flag
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1185
			 * otherwise colors from _string_colormap are assumed. */
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1186
			DrawString(
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1187
				ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0),
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1188
				ss->string, (_color_list[ss->color].window_color_bgb | IS_PALETTE_COLOR)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1189
			);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
		} else {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1191
			DrawString(
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1192
				ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0),
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1193
				ss->string, 16
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1194
			);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
		}
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1196
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1197
		ss = ss->next;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1198
	} while (ss != NULL);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1199
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
	_cur_dpi = dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
430
75820dedf4f1 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 410
diff changeset
  1203
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
  1204
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
	ViewportDrawer vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1206
	int mask;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1207
	int x;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1208
	int y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1209
	DrawPixelInfo *old_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
	byte mem[VIEWPORT_DRAW_MEM];
137
73f897e1bf4a (svn r138) -Add: 64x64 stations are now nicely painted (increased size of
truelight
parents: 133
diff changeset
  1212
	ParentSpriteToDraw *parent_list[6144];
0
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
	_cur_vd = &vd;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1215
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
	old_dpi = _cur_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
	_cur_dpi = &vd.dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
	vd.dpi.zoom = vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
	mask = (-1) << vp->zoom;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1222
	vd.combine_sprites = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1223
	vd.ground_child = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1224
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1225
	vd.dpi.width = (right - left) & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1226
	vd.dpi.height = (bottom - top) & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1227
	vd.dpi.left = left & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1228
	vd.dpi.top = top & mask;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1229
	vd.dpi.pitch = old_dpi->pitch;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
	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
  1232
	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
  1233
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
	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
  1235
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1236
	vd.parent_list = parent_list;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1237
	vd.eof_parent_list = endof(parent_list);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1238
	vd.spritelist_mem = mem;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1239
	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
  1240
	vd.last_string = &vd.first_string;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
	vd.first_string = NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
	vd.last_tile = &vd.first_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
	vd.first_tile = NULL;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1244
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
	ViewportAddLandscape();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1246
#if !defined(NEW_ROTATION)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1247
	ViewportAddVehicles(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
	DrawTextEffects(&vd.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
	ViewportAddTownNames(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
	ViewportAddStationNames(&vd.dpi);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1252
	ViewportAddSigns(&vd.dpi);
395
4c990f33dab7 (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
  1253
	ViewportAddWaypoints(&vd.dpi);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
#endif
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
  1256
	// 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
  1257
	//  is checked)
979
f12f96116cdd (svn r1475) Fix some more signed/unsigned comparison warnings
tron
parents: 926
diff changeset
  1258
	assert(vd.parent_list <= endof(parent_list));
133
321532e90bc8 (svn r134) -Fix: [976583] parent_list was too small
truelight
parents: 58
diff changeset
  1259
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1260
	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
  1261
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
	/* null terminate parent sprite list */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1263
	*vd.parent_list = NULL;
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
	ViewportSortParentSprites(parent_list);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1266
	ViewportDrawParentSprites(parent_list);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1267
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1268
	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
  1269
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
	_cur_dpi = old_dpi;
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
// 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
  1274
// If we do, the sprite memory will overflow.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1275
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
  1276
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
	if (((bottom - top) * (right - left) << vp->zoom) > 180000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1278
		if ((bottom - top) > (right - left)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1279
			int t = (top + bottom) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
			ViewportDrawChk(vp, left, top, right, t);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
			ViewportDrawChk(vp, left, t, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1282
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1283
			int t = (left + right) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1284
			ViewportDrawChk(vp, left, top, t, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
			ViewportDrawChk(vp, t, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
	} else {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1288
		ViewportDoDraw(vp,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1289
			((left - vp->left) << vp->zoom) + vp->virtual_left,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1290
			((top - vp->top) << vp->zoom) + vp->virtual_top,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
			((right - vp->left) << vp->zoom) + vp->virtual_left,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1292
			((bottom - vp->top) << vp->zoom) + vp->virtual_top
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1293
		);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1294
	}
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
500
ef288590e096 (svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents: 497
diff changeset
  1297
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
  1298
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1299
	if (right <= vp->left || bottom <= vp->top) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1300
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1301
	if (left >= vp->left + vp->width) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
	if (left < vp->left) left = vp->left;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1304
	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
  1305
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1306
	if (top >= vp->top + vp->height) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1307
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1308
	if (top < vp->top) top = vp->top;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1309
	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
  1310
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1311
	ViewportDrawChk(vp, left, top, right, bottom);
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
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1314
void DrawWindowViewport(Window *w)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1315
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1316
	DrawPixelInfo *dpi = _cur_dpi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1317
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1318
	dpi->left += w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1319
	dpi->top += w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1320
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1321
	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
  1322
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1323
	dpi->left -= w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1324
	dpi->top -= w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1325
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1326
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1327
void UpdateViewportPosition(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1328
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1329
	const ViewPort *vp = w->viewport;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1330
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1331
	if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1332
		const Vehicle* veh = GetVehicle(WP(w,vp_d).follow_vehicle);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1333
		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
  1334
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1335
		SetViewportPosition(w, pt.x, pt.y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1336
	} else {
632
0e71f12b846b (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
#if !defined(NEW_ROTATION)
0e71f12b846b (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
  1338
		int x;
0e71f12b846b (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
  1339
		int y;
0e71f12b846b (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
  1340
		int vx;
0e71f12b846b (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
  1341
		int vy;
0e71f12b846b (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
  1342
0e71f12b846b (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
  1343
		// Center of the viewport is hot spot
0e71f12b846b (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
  1344
		x = WP(w,vp_d).scrollpos_x + vp->virtual_width / 2;
0e71f12b846b (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
  1345
		y = WP(w,vp_d).scrollpos_y + vp->virtual_height / 2;
0e71f12b846b (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
  1346
		// Convert viewport coordinates to map coordinates
0e71f12b846b (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
  1347
		// Calculation is scaled by 4 to avoid rounding errors
0e71f12b846b (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
  1348
		vx = -x + y * 2;
0e71f12b846b (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
  1349
		vy =  x + y * 2;
0e71f12b846b (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
  1350
		// clamp to size of map
856
07dc27d0503e (svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents: 849
diff changeset
  1351
		vx = clamp(vx, 0 * 4, MapMaxX() * 16 * 4);
07dc27d0503e (svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents: 849
diff changeset
  1352
		vy = clamp(vy, 0 * 4, MapMaxY() * 16 * 4);
632
0e71f12b846b (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
  1353
		// Convert map coordinates to viewport coordinates
0e71f12b846b (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
  1354
		x = (-vx + vy) / 2;
0e71f12b846b (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
  1355
		y = ( vx + vy) / 4;
0e71f12b846b (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
		// Set position
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1357
		WP(w, vp_d).scrollpos_x = x - vp->virtual_width / 2;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1358
		WP(w, vp_d).scrollpos_y = y - vp->virtual_height / 2;
632
0e71f12b846b (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
  1359
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1360
		int x,y,t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1361
		int err;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1362
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1363
		x = WP(w,vp_d).scrollpos_x >> 2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1364
		y = WP(w,vp_d).scrollpos_y >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1365
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1366
		t = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1367
		x = x + y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1368
		y = x - y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1369
		err= 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1370
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1371
		if (err != 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1372
			/* coordinate remap */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1373
			Point pt = RemapCoords(x, y, 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1374
			t = (-1) << vp->zoom;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1375
			WP(w,vp_d).scrollpos_x = pt.x & t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1376
			WP(w,vp_d).scrollpos_y = pt.y & t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1377
		}
632
0e71f12b846b (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
  1378
#endif
0e71f12b846b (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
  1379
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1380
		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
  1381
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1382
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1383
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1384
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
  1385
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1386
	right -= vp->virtual_left;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1387
	if (right <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1389
	bottom -= vp->virtual_top;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1390
	if (bottom <= 0) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1392
	left = max(0, left - vp->virtual_left);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1394
	if (left >= vp->virtual_width) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1396
	top = max(0, top - vp->virtual_top);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1397
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1398
	if (top >= vp->virtual_height) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1399
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1400
	SetDirtyBlocks(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1401
		(left >> vp->zoom) + vp->left,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1402
		(top >> vp->zoom) + vp->top,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
		(right >> vp->zoom) + vp->left,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
		(bottom >> vp->zoom) + vp->top
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
	);
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
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
  1409
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1410
	const ViewPort *vp = _viewports;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1411
	uint32 act = _active_viewports;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1412
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1413
		if (act & 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1414
			assert(vp->width != 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1415
			MarkViewportDirty(vp, left, top, right, bottom);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
	} while (vp++,act>>=1);
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
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1420
void MarkTileDirtyByTile(TileIndex tile)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1421
{
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1422
	Point pt = RemapCoords(TileX(tile) * 16, TileY(tile) * 16, GetTileZ(tile));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
		pt.x - 31,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
		pt.y - 122,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1426
		pt.x - 31 + 67,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
		pt.y - 122 + 154
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1430
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
void MarkTileDirty(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1433
	uint z = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
	Point pt;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1435
863
8d09f9331a80 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 856
diff changeset
  1436
	if (IS_INT_INSIDE(x, 0, MapSizeX() * 16) &&
8d09f9331a80 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 856
diff changeset
  1437
			IS_INT_INSIDE(y, 0, MapSizeY() * 16))
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  1438
		z = GetTileZ(TileVirtXY(x, y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1439
	pt = RemapCoords(x, y, z);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
	MarkAllViewportsDirty(
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
		pt.x - 31,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
		pt.y - 122,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
		pt.x - 31 + 67,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
		pt.y - 122 + 154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1446
	);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1447
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1449
static void SetSelectionTilesDirty(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
	int y_size, x_size;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1452
	int x = _thd.pos.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1453
	int y = _thd.pos.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1455
	x_size = _thd.size.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1456
	y_size = _thd.size.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1458
	if (_thd.outersize.x) {
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1459
		x_size += _thd.outersize.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1460
		x += _thd.offs.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1461
		y_size += _thd.outersize.y;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1462
		y += _thd.offs.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
	assert(x_size > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1466
	assert(y_size > 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
	x_size += x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
	y_size += y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1471
	do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
		int y_bk = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
		do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
			MarkTileDirty(x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
		} while ( (y+=16) != y_size);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
		y = y_bk;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
	} while ( (x+=16) != x_size);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1480
1990
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1481
void SetSelectionRed(bool b)
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1482
{
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1483
	_thd.make_square_red = b;
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1484
	SetSelectionTilesDirty();
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1485
}
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1486
90eb49e87b90 (svn r2496) -Fix: [1179933] When toggling build/remove via keyboard the selection wasn't correctly redrawn
tron
parents: 1980
diff changeset
  1487
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1488
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
  1489
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1490
	const Town *t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1491
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1492
	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
  1493
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
	if (vp->zoom < 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
		x = x - vp->left + vp->virtual_left;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1496
		y = y - vp->top + vp->virtual_top;
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1497
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1498
		FOR_ALL_TOWNS(t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1499
			if (t->xy &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1500
			    y >= t->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
					y < t->sign.top + 12 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1502
					x >= t->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1503
					x < t->sign.left + t->sign.width_1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1504
				ShowTownViewWindow(t->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1505
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1508
	} else if (vp->zoom == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
		x = (x - vp->left + 1) * 2 + vp->virtual_left;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1510
		y = (y - vp->top + 1) * 2 + vp->virtual_top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1511
		FOR_ALL_TOWNS(t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
			if (t->xy &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
			    y >= t->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
					y < t->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
					x >= t->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
					x < t->sign.left + t->sign.width_1 * 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
				ShowTownViewWindow(t->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1518
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1520
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1521
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1522
		x = (x - vp->left + 3) * 4 + vp->virtual_left;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1523
		y = (y - vp->top + 3) * 4 + vp->virtual_top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
		FOR_ALL_TOWNS(t) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1525
			if (t->xy &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
			    y >= t->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
					y < t->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1528
					x >= t->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
					x < t->sign.left + t->sign.width_2 * 4) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1530
				ShowTownViewWindow(t->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1531
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1532
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1533
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1534
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1538
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1539
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
  1540
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1541
	const Station *st;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1542
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1543
	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
  1544
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1545
	if (vp->zoom < 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1546
		x = x - vp->left + vp->virtual_left;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1547
		y = y - vp->top + vp->virtual_top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1548
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
		FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1550
			if (st->xy &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
			    y >= st->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
					y < st->sign.top + 12 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
					x >= st->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
					x < st->sign.left + st->sign.width_1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1555
				ShowStationViewWindow(st->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
	} else if (vp->zoom == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1560
		x = (x - vp->left + 1) * 2 + vp->virtual_left;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1561
		y = (y - vp->top + 1) * 2 + vp->virtual_top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1562
		FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
			if (st->xy &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1564
			    y >= st->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1565
					y < st->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1566
					x >= st->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
					x < st->sign.left + st->sign.width_1 * 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
				ShowStationViewWindow(st->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1569
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1570
			}
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
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
		x = (x - vp->left + 3) * 4 + vp->virtual_left;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1574
		y = (y - vp->top + 3) * 4 + vp->virtual_top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
		FOR_ALL_STATIONS(st) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1576
			if (st->xy &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1577
			    y >= st->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1578
					y < st->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1579
					x >= st->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1580
					x < st->sign.left + st->sign.width_2 * 4) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1581
				ShowStationViewWindow(st->index);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1582
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1583
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1584
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1585
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1586
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1587
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1588
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1589
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1590
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
  1591
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1592
	const SignStruct *ss;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1593
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1594
	if (!(_display_opt & DO_SHOW_SIGNS)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1595
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1596
	if (vp->zoom < 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1597
		x = x - vp->left + vp->virtual_left;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1598
		y = y - vp->top + vp->virtual_top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1599
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 981
diff changeset
  1600
		FOR_ALL_SIGNS(ss) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1601
			if (ss->str &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1602
			    y >= ss->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1603
					y < ss->sign.top + 12 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
					x >= ss->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
					x < ss->sign.left + ss->sign.width_1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1606
				ShowRenameSignWindow(ss);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1607
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1608
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1609
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
	} else if (vp->zoom == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1611
		x = (x - vp->left + 1) * 2 + vp->virtual_left;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1612
		y = (y - vp->top + 1) * 2 + vp->virtual_top;
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 981
diff changeset
  1613
		FOR_ALL_SIGNS(ss) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1614
			if (ss->str &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1615
			    y >= ss->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1616
					y < ss->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1617
					x >= ss->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1618
					x < ss->sign.left + ss->sign.width_1 * 2) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1619
				ShowRenameSignWindow(ss);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1621
			}
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
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
		x = (x - vp->left + 3) * 4 + vp->virtual_left;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1625
		y = (y - vp->top + 3) * 4 + vp->virtual_top;
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 981
diff changeset
  1626
		FOR_ALL_SIGNS(ss) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1627
			if (ss->str &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1628
			    y >= ss->sign.top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1629
					y < ss->sign.top + 24 &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1630
					x >= ss->sign.left &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1631
					x < ss->sign.left + ss->sign.width_2 * 4) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1632
				ShowRenameSignWindow(ss);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1633
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1634
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1635
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1636
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1637
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1638
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1639
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1641
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
  1642
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1643
	const Waypoint *wp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1645
	if (!(_display_opt & DO_WAYPOINTS)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1647
	if (vp->zoom < 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1648
		x = x - vp->left + vp->virtual_left;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1649
		y = y - vp->top + vp->virtual_top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1650
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1651
		FOR_ALL_WAYPOINTS(wp) {
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1652
			if (wp->xy &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1653
			    y >= wp->sign.top &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1654
					y < wp->sign.top + 12 &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1655
					x >= wp->sign.left &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1656
					x < wp->sign.left + wp->sign.width_1) {
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1657
				ShowRenameWaypointWindow(wp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1658
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1659
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1660
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1661
	} else if (vp->zoom == 1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1662
		x = (x - vp->left + 1) * 2 + vp->virtual_left;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1663
		y = (y - vp->top + 1) * 2 + vp->virtual_top;
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1664
		FOR_ALL_WAYPOINTS(wp) {
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1665
			if (wp->xy &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1666
			    y >= wp->sign.top &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1667
					y < wp->sign.top + 24 &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1668
					x >= wp->sign.left &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1669
					x < wp->sign.left + wp->sign.width_1 * 2) {
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1670
				ShowRenameWaypointWindow(wp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1671
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1672
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1673
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1674
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1675
		x = (x - vp->left + 3) * 4 + vp->virtual_left;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1676
		y = (y - vp->top + 3) * 4 + vp->virtual_top;
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1677
		FOR_ALL_WAYPOINTS(wp) {
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1678
			if (wp->xy &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1679
			    y >= wp->sign.top &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1680
					y < wp->sign.top + 24 &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1681
					x >= wp->sign.left &&
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1682
					x < wp->sign.left + wp->sign.width_2 * 4) {
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1390
diff changeset
  1683
				ShowRenameWaypointWindow(wp);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1684
				return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1685
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1686
		}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1689
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1690
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1691
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1692
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1693
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
  1694
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1695
	Point pt = TranslateXYToTileCoord(vp, x, y);
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1964
diff changeset
  1696
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  1697
	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
  1698
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1699
2662
42c11a1a0a4b (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
42c11a1a0a4b (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
static void SafeShowTrainViewWindow(const Vehicle* v)
42c11a1a0a4b (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
{
42c11a1a0a4b (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
  if (v->subtype != TS_Front_Engine) v = GetFirstVehicleInChain(v);
42c11a1a0a4b (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
  ShowTrainViewWindow(v);
42c11a1a0a4b (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
}
42c11a1a0a4b (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
  1706
42c11a1a0a4b (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
  1707
static void Nop(const Vehicle* v) {}
42c11a1a0a4b (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
  1708
42c11a1a0a4b (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
  1709
typedef void OnVehicleClickProc(const Vehicle* v);
42c11a1a0a4b (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
  1710
static OnVehicleClickProc* const _on_vehicle_click_proc[] = {
42c11a1a0a4b (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
  1711
	SafeShowTrainViewWindow,
42c11a1a0a4b (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
  1712
	ShowRoadVehViewWindow,
42c11a1a0a4b (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
  1713
	ShowShipViewWindow,
42c11a1a0a4b (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
  1714
	ShowAircraftViewWindow,
42c11a1a0a4b (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
  1715
	Nop, // Special vehicles
42c11a1a0a4b (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
  1716
	Nop  // Disaster vehicles
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1717
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1718
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1719
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
  1720
{
2662
42c11a1a0a4b (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
  1721
	const Vehicle* v;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1722
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1723
	if (CheckClickOnTown(vp, x, y)) return;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1724
	if (CheckClickOnStation(vp, x, y)) return;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1725
	if (CheckClickOnSign(vp, x, y)) return;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1726
	if (CheckClickOnWaypoint(vp, x, y)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1727
	CheckClickOnLandscape(vp, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1729
	v = CheckClickOnVehicle(vp, x, y);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1730
	if (v != NULL) _on_vehicle_click_proc[v->type - 0x10](v);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1731
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1732
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1733
Vehicle *CheckMouseOverVehicle(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1735
	const Window* w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1736
	const ViewPort* vp;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1737
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1738
	int x = _cursor.pos.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1739
	int y = _cursor.pos.y;
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
	w = FindWindowFromPt(x, y);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1742
	if (w == NULL) return NULL;
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
	vp = IsPtInWindowViewport(w, x, y);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1745
	return (vp != NULL) ? CheckClickOnVehicle(vp, x, y) : NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1746
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1747
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1748
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1749
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1750
void PlaceObject(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
	Window *w;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1754
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1755
	pt = GetTileBelowCursor();
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1756
	if (pt.x == -1) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1757
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1758
	if (_thd.place_mode == VHM_POINT) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
		pt.x += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
		pt.y += 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1761
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1762
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1763
	_tile_fract_coords.x = pt.x & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1764
	_tile_fract_coords.y = pt.y & 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1765
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1766
	w = GetCallbackWnd();
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1767
	if (w != NULL) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1768
		WindowEvent e;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1769
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1770
		e.event = WE_PLACE_OBJ;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1771
		e.place.pt = pt;
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  1772
		e.place.tile = TileVirtXY(pt.x, pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1773
		w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1774
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1775
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1776
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
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
  1778
/* scrolls the viewport in a window to a given location */
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1779
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
  1780
{
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
  1781
	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
  1782
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
	pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y));
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1784
	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
  1785
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1786
	if (WP(w, vp_d).scrollpos_x == pt.x && WP(w, vp_d).scrollpos_y == pt.y)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1787
		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
  1788
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1789
	WP(w, vp_d).scrollpos_x = pt.x;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1790
	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
  1791
	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
  1792
}
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
  1793
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
  1794
/* scrolls the viewport in a window to a given tile */
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1795
bool ScrollWindowToTile(TileIndex tile, 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
  1796
{
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1797
	return ScrollWindowTo(TileX(tile) * 16 + 8, TileY(tile) * 16 + 8, 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
  1798
}
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
  1799
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
  1800
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
  1801
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1802
bool ScrollMainWindowTo(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1803
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1804
	return ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0));
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
bool ScrollMainWindowToTile(TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1809
{
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 919
diff changeset
  1810
	return ScrollMainWindowTo(TileX(tile) * 16 + 8, TileY(tile) * 16 + 8);
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1813
void SetRedErrorSquare(TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1814
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1815
	TileIndex old;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1816
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1817
	old = _thd.redsq;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1818
	_thd.redsq = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1819
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1820
	if (tile != old) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1821
		if (tile != 0) MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
		if (old  != 0) MarkTileDirtyByTile(old);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1826
void SetTileSelectSize(int w, int h)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1827
{
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1828
	_thd.new_size.x = w * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1829
	_thd.new_size.y = h * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1830
	_thd.new_outersize.x = 0;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1831
	_thd.new_outersize.y = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1832
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1833
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1834
void SetTileSelectBigSize(int ox, int oy, int sx, int sy)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1835
{
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1836
	_thd.offs.x = ox * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1837
	_thd.offs.y = oy * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1838
	_thd.new_outersize.x = sx * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1839
	_thd.new_outersize.y = sy * 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1840
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1841
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1842
/* returns the best autorail highlight type from map coordinates */
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1843
static byte GetAutorailHT(int x, int y)
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1844
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1845
	return HT_RAIL | AutorailPiece[x & 0xF][y & 0xF];
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1846
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1847
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1848
// called regular to update tile highlighting in all cases
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1849
void UpdateTileSelection(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1850
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1851
	int x1;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1852
	int y1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1853
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1854
	_thd.new_drawstyle = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1855
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1856
	if (_thd.place_mode == VHM_SPECIAL) {
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1857
		x1 = _thd.selend.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1858
		y1 = _thd.selend.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1859
		if (x1 != -1) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1860
			int x2 = _thd.selstart.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1861
			int y2 = _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1862
			x1 &= ~0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1863
			y1 &= ~0xF;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1864
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1865
			if (x1 >= x2) intswap(x1,x2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1866
			if (y1 >= y2) intswap(y1,y2);
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1867
			_thd.new_pos.x = x1;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1868
			_thd.new_pos.y = y1;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1869
			_thd.new_size.x = x2 - x1 + 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1870
			_thd.new_size.y = y2 - y1 + 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1871
			_thd.new_drawstyle = _thd.next_drawstyle;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1872
		}
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1873
	} else if (_thd.place_mode != VHM_NONE) {
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  1874
		Point pt = GetTileBelowCursor();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1875
		x1 = pt.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1876
		y1 = pt.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1877
		if (x1 != -1) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1878
			switch (_thd.place_mode) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1879
				case VHM_RECT:
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1880
					_thd.new_drawstyle = HT_RECT;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1881
					break;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1882
				case VHM_POINT:
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1883
					_thd.new_drawstyle = HT_POINT;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1884
					x1 += 8;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1885
					y1 += 8;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1886
					break;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1887
				case VHM_RAIL:
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1888
					_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
  1889
			}
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1890
			_thd.new_pos.x = x1 & ~0xF;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1891
			_thd.new_pos.y = y1 & ~0xF;
0
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1894
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1895
	// redraw selection
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1896
	if (_thd.drawstyle != _thd.new_drawstyle ||
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1897
			_thd.pos.x != _thd.new_pos.x || _thd.pos.y != _thd.new_pos.y ||
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1898
			_thd.size.x != _thd.new_size.x || _thd.size.y != _thd.new_size.y) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1899
		// clear the old selection?
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1900
		if (_thd.drawstyle) SetSelectionTilesDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1901
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1902
		_thd.drawstyle = _thd.new_drawstyle;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1903
		_thd.pos = _thd.new_pos;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1904
		_thd.size = _thd.new_size;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1905
		_thd.outersize = _thd.new_outersize;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1906
		_thd.dirty = 0xff;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1907
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
		// draw the new selection?
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1909
		if (_thd.new_drawstyle) SetSelectionTilesDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1910
	}
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
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1913
// highlighting tiles while only going over them with the mouse
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1964
diff changeset
  1914
void VpStartPlaceSizing(TileIndex tile, int user)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1915
{
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1916
	_thd.userdata = user;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1917
	_thd.selend.x = TileX(tile) * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1918
	_thd.selstart.x = TileX(tile) * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1919
	_thd.selend.y = TileY(tile) * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1920
	_thd.selstart.y = TileY(tile) * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1921
	if (_thd.place_mode == VHM_RECT) {
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1922
		_thd.place_mode = VHM_SPECIAL;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1923
		_thd.next_drawstyle = HT_RECT;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1924
	} else if (_thd.place_mode == VHM_RAIL) { // autorail one piece
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1925
		_thd.place_mode = VHM_SPECIAL;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1926
		_thd.next_drawstyle = _thd.drawstyle;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
	} else {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1928
		_thd.place_mode = VHM_SPECIAL;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1929
		_thd.next_drawstyle = HT_POINT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1930
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
	_special_mouse_mode = WSM_SIZING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1932
}
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
void VpSetPlaceSizingLimit(int limit)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1935
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
	_thd.sizelimit = limit;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
}
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
void VpSetPresizeRange(uint from, uint to)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1940
{
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1941
	_thd.selend.x = TileX(to) * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1942
	_thd.selend.y = TileY(to) * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1943
	_thd.selstart.x = TileX(from) * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1944
	_thd.selstart.y = TileY(from) * 16;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1945
	_thd.next_drawstyle = HT_RECT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1947
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  1948
void VpStartPreSizing(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1949
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1950
	_thd.selend.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1951
	_special_mouse_mode = WSM_PRESIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1952
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1953
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
  1954
/* returns information about the 2x1 piece to be build.
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1955
 * The lower bits (0-3) are the track type. */
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1956
static byte Check2x1AutoRail(int mode)
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1957
{
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1958
	int fxpy = _tile_fract_coords.x + _tile_fract_coords.y;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1959
	int sxpy = (_thd.selend.x & 0xF) + (_thd.selend.y & 0xF);
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1960
	int fxmy = _tile_fract_coords.x - _tile_fract_coords.y;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  1961
	int sxmy = (_thd.selend.x & 0xF) - (_thd.selend.y & 0xF);
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1962
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1963
	switch(mode) {
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1964
	case 0: // end piece is lower right
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1965
		if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1966
		if (fxmy < -3 && sxmy > 3) {/* DoRailroadTrack(0); */return 5; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1967
		return 1;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1968
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1969
	case 1:
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1970
		if (fxmy > 3 && sxmy < -3) { /*SwapSelection(); DoRailroadTrack(0); */return 4; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1971
		if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1972
		return 1;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1973
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1974
	case 2:
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1975
		if (fxmy > 3 && sxmy < -3) { /*DoRailroadTrack(3);*/ return 4; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1976
		if (fxpy >= 20 && sxpy <= 12) { /*SwapSelection(); DoRailroadTrack(0); */return 3; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1977
		return 0;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1978
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1979
	case 3:
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1980
		if (fxmy < -3 && sxmy > 3) { /*SwapSelection(); DoRailroadTrack(3);*/ return 5; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1981
		if (fxpy <= 12 && sxpy >= 20) { /*DoRailroadTrack(0); */return 2; }
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1982
		return 0;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1983
	}
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1984
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1985
	return 0; // avoids compiler warnings
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1986
}
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1987
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1988
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1989
// while dragging
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1990
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
  1991
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1992
	int d;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1993
	byte b=6;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1994
	uint w,h;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  1995
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1996
	int dx = thd->selstart.x - (thd->selend.x&~0xF);
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1997
	int dy = thd->selstart.y - (thd->selend.y&~0xF);
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1998
	w = myabs(dx) + 16;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  1999
	h = myabs(dy) + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2000
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  2001
	if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2002
		if (method == VPM_RAILDIRS)
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2003
			b = GetAutorailHT(x, y);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2004
		else // rect for autosignals on one tile
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2005
			b = HT_RECT;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2006
	} else if (h == 16) { // Is this in X direction?
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2007
		if (dx == 16) // 2x1 special handling
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2008
			b = (Check2x1AutoRail(3)) | HT_LINE;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2009
		else if (dx == -16)
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2010
			b = (Check2x1AutoRail(2)) | HT_LINE;
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
  2011
		else
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2012
			b = HT_LINE | HT_DIR_X;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2013
		y = thd->selstart.y;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2014
	} else if (w == 16) { // Or Y direction?
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2015
		if (dy == 16) // 2x1 special handling
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2016
			b = (Check2x1AutoRail(1)) | HT_LINE;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2017
		else if (dy == -16) // 2x1 other direction
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2018
			b = (Check2x1AutoRail(0)) | HT_LINE;
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
  2019
		else
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2020
			b = HT_LINE | HT_DIR_Y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2021
		x = thd->selstart.x;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2022
	} else if (w > h * 2) { // still count as x dir?
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2023
		b = HT_LINE | HT_DIR_X;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2024
		y = thd->selstart.y;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2025
	} else if (h > w * 2) { // still count as y dir?
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2026
		b = HT_LINE | HT_DIR_Y;
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2027
		x = thd->selstart.x;
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2028
	} else { // complicated direction
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2029
		d = w - h;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2030
		thd->selend.x = thd->selend.x & ~0xF;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2031
		thd->selend.y = thd->selend.y & ~0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2032
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2033
		// four cases.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2034
		if (x > thd->selstart.x) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2035
			if (y > thd->selstart.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2036
				// south
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2037
				if (d == 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2038
					b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2039
				} else if (d >= 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2040
					x = thd->selstart.x + h;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2041
					b = HT_LINE | HT_DIR_VL;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2042
					// return px == py || px == py + 16;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2043
				} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2044
					y = thd->selstart.y + w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2045
					b = HT_LINE | HT_DIR_VR;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2046
				} // return px == py || px == py - 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2047
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2048
				// west
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2049
				if (d == 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2050
					b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2051
				} else if (d >= 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2052
					x = thd->selstart.x + h;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2053
					b = HT_LINE | HT_DIR_HL;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2054
				} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2055
					y = thd->selstart.y - w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2056
					b = HT_LINE | HT_DIR_HU;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2057
				}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2058
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2059
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2060
			if (y > thd->selstart.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2061
				// east
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2062
				if (d == 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2063
					b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2064
				} else if (d >= 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2065
					x = thd->selstart.x - h;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2066
					b = HT_LINE | HT_DIR_HU;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2067
					// return px == -py || px == -py - 16;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2068
				} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2069
					y = thd->selstart.y + w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2070
					b = HT_LINE | HT_DIR_HL;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2071
				} // return px == -py || px == -py + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2072
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2073
				// north
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2074
				if (d == 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2075
					b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2076
				} else if (d >= 0) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2077
					x = thd->selstart.x - h;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2078
					b = HT_LINE | HT_DIR_VR;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2079
					// return px == py || px == py - 16;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2080
				} else {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2081
					y = thd->selstart.y - w;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2082
					b = HT_LINE | HT_DIR_VL;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2083
				} //return px == py || px == py + 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2084
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2085
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2086
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2087
	thd->selend.x = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2088
	thd->selend.y = y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
	thd->next_drawstyle = b;
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
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2092
// while dragging
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2093
void VpSelectTilesWithMethod(int x, int y, int method)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2094
{
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2095
	int sx;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2096
	int sy;
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2097
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2098
	if (x == -1) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2099
		_thd.selend.x = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2100
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2101
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2102
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2103
	// 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
  2104
	if (method == VPM_RAILDIRS || method == VPM_SIGNALDIRS) {
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2105
		_thd.selend.x = x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2106
		_thd.selend.y = y;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2107
		CalcRaildirsDrawstyle(&_thd, x, y, method);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2108
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2109
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2110
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2111
	if (_thd.next_drawstyle == HT_POINT) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2112
		x += 8;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2113
		y += 8;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2114
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2115
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2116
	sx = _thd.selstart.x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2117
	sy = _thd.selstart.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2118
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2119
	switch (method) {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2120
		case VPM_FIX_X:
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2121
			x = sx;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2122
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2123
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2124
		case VPM_FIX_Y:
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2125
			y = sy;
cdfc27b696b7 (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
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2128
		case VPM_X_OR_Y:
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2129
			if (myabs(sy - y) < myabs(sx - x)) y = sy; else x = sx;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2130
			break;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2131
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2132
		case VPM_X_AND_Y:
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2133
			break;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2134
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2135
		// limit the selected area to a 10x10 rect.
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2136
		case VPM_X_AND_Y_LIMITED: {
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2137
			int limit = (_thd.sizelimit - 1) * 16;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2138
			x = sx + clamp(x - sx, -limit, limit);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2139
			y = sy + clamp(y - sy, -limit, limit);
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2140
			break;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2141
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2142
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2143
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2144
	_thd.selend.x = x;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2145
	_thd.selend.y = y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2146
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2147
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1095
diff changeset
  2148
// while dragging
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  2149
bool VpHandlePlaceSizingDrag(void)
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
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2152
	WindowEvent e;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2153
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2154
	if (_special_mouse_mode != WSM_SIZING) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2155
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2156
	e.place.userdata = _thd.userdata;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2157
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2158
	// 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
  2159
	w = FindWindowById(_thd.window_class,_thd.window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2160
	if (w == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2161
		ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2162
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2163
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2164
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2165
	// 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
  2166
	if (_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2167
		e.event = WE_PLACE_DRAG;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2168
		e.place.pt = GetTileBelowCursor();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2169
		w->wndproc(w, &e);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2173
	// mouse button released..
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2174
	// 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
  2175
	_special_mouse_mode = WSM_NONE;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2176
	if (_thd.next_drawstyle == HT_RECT) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2177
		_thd.place_mode = VHM_RECT;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2178
	} else if ((e.place.userdata & 0xF) == VPM_SIGNALDIRS) { // some might call this a hack... -- Dominik
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2179
		_thd.place_mode = VHM_RECT;
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2180
	} else if (_thd.next_drawstyle & HT_LINE) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2181
		_thd.place_mode = VHM_RAIL;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2182
	} else if (_thd.next_drawstyle & HT_RAIL) {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2183
		_thd.place_mode = VHM_RAIL;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2184
	} else {
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2185
		_thd.place_mode = VHM_POINT;
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2186
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2187
	SetTileSelectSize(1, 1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2188
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2189
	// and call the mouseup event.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2190
	e.event = WE_PLACE_MOUSEUP;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2191
	e.place.pt = _thd.selend;
1980
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  2192
	e.place.tile = TileVirtXY(e.place.pt.x, e.place.pt.y);
9ea0c89fbb58 (svn r2486) Turn TILE_FROM_XY into an inline function and rename it to TileVirtXY
tron
parents: 1977
diff changeset
  2193
	e.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
  2194
	w->wndproc(w, &e);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2195
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2196
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2197
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2198
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
  2199
void SetObjectToPlaceWnd(CursorID icon, byte mode, Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2200
{
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
  2201
	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
  2202
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2203
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2204
#include "table/animcursors.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2205
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
  2206
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
  2207
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2208
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2209
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2210
	// undo clicking on button
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2211
	if (_thd.place_mode != 0) {
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2212
		_thd.place_mode = 0;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2213
		w = FindWindowById(_thd.window_class, _thd.window_number);
2116
cdfc27b696b7 (svn r2626) static, const, misc.
tron
parents: 2109
diff changeset
  2214
		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
  2215
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2216
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2217
	SetTileSelectSize(1, 1);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2218
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2219
	_thd.make_square_red = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2220
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2221
	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
  2222
		mode = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2223
		_special_mouse_mode = WSM_DRAGDROP;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2224
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2225
		_special_mouse_mode = WSM_NONE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2226
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2227
1863
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2228
	_thd.place_mode = mode;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2229
	_thd.window_class = window_class;
610acc8bc189 (svn r2369) Remove _thd_ptr: It always holds the address of _thd
tron
parents: 1542
diff changeset
  2230
	_thd.window_number = window_num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2231
1070
bef634a62323 (svn r1571) Feature: Visually enhanced autorail placing
dominik
parents: 988
diff changeset
  2232
	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
  2233
		VpStartPreSizing();
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 152
diff changeset
  2234
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2235
	if ( (int)icon < 0)
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2482
diff changeset
  2236
		SetAnimatedMouseCursor(_animcursors[~icon]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2237
	else
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2238
		SetMouseCursor(icon);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2239
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2240
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  2241
void ResetObjectToPlace(void)
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1083
diff changeset
  2242
{
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
  2243
	SetObjectToPlace(SPR_CURSOR_MOUSE, 0, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2244
}