src/landscape.cpp
author celestar
Tue, 19 Jun 2007 07:21:01 +0000
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
permissions -rw-r--r--
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
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: 1793
diff changeset
     4
#include "openttd.h"
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4990
diff changeset
     5
#include "bridge_map.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
     6
#include "heightmap.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3111
diff changeset
     7
#include "clear_map.h"
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
     8
#include "date.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     9
#include "functions.h"
679
e959706a3e4d (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 473
diff changeset
    10
#include "map.h"
2154
63a6b880b4c0 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2150
diff changeset
    11
#include "player.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: 1335
diff changeset
    12
#include "spritecache.h"
1363
01d3de5d8039 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1359
diff changeset
    13
#include "table/sprites.h"
1209
a1ac96655b79 (svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents: 1202
diff changeset
    14
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
#include "command.h"
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
    18
#include "landscape.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
#include "vehicle.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    20
#include "variables.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3111
diff changeset
    21
#include "void_map.h"
3111
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3078
diff changeset
    22
#include "water_map.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
    23
#include "tgp.h"
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
    24
#include "genworld.h"
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
    25
#include "heightmap.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
    27
extern const TileTypeProcs
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	_tile_type_clear_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	_tile_type_rail_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	_tile_type_road_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	_tile_type_town_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	_tile_type_trees_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	_tile_type_station_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	_tile_type_water_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	_tile_type_dummy_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	_tile_type_industry_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
	_tile_type_tunnelbridge_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	_tile_type_unmovable_procs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
const TileTypeProcs * const _tile_type_procs[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
	&_tile_type_clear_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
	&_tile_type_rail_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
	&_tile_type_road_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
	&_tile_type_town_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
	&_tile_type_trees_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
	&_tile_type_station_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
	&_tile_type_water_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
	&_tile_type_dummy_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
	&_tile_type_industry_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	&_tile_type_tunnelbridge_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
	&_tile_type_unmovable_procs,
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
/* landscape slope => sprite */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
const byte _tileh_to_sprite[32] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
    56
	0, 1, 2, 3, 4, 5, 6,  7, 8, 9, 10, 11, 12, 13, 14, 0,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
    57
	0, 0, 0, 0, 0, 0, 0, 16, 0, 0,  0, 17,  0, 15, 18, 0,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
    60
const Slope _inclined_tileh[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
    61
	SLOPE_SW,  SLOPE_NW,  SLOPE_SW,  SLOPE_SE, SLOPE_NE, SLOPE_SE, SLOPE_NE, SLOPE_NW,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
    62
	SLOPE_E,   SLOPE_N,   SLOPE_W,   SLOPE_S,
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
    63
	SLOPE_NWS, SLOPE_WSE, SLOPE_SEN, SLOPE_ENW
1958
625d71cd6898 (svn r2464) Move definition of _inclined_tileh out of variables.h
tron
parents: 1902
diff changeset
    64
};
625d71cd6898 (svn r2464) Move definition of _inclined_tileh out of variables.h
tron
parents: 1902
diff changeset
    65
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
    66
SnowLine *_snow_line = NULL;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    68
uint GetPartialZ(int x, int y, Slope corners)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
	int z = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
    72
	switch (corners) {
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    73
	case SLOPE_W:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
		if (x - y >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
			z = (x - y) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
		break;
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
    77
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    78
	case SLOPE_S:
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
    79
		y ^= 0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
		if ( (x - y) >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
			z = (x - y) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    82
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    83
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    84
	case SLOPE_SW:
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
    85
		z = (x >> 1) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    88
	case SLOPE_E:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    89
		if (y - x >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    90
			z = (y - x) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    91
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    93
	case SLOPE_EW:
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    94
	case SLOPE_NS:
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    95
	case SLOPE_ELEVATED:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
		z = 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    97
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    99
	case SLOPE_SE:
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
   100
		z = (y >> 1) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   103
	case SLOPE_WSE:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
		z = 8;
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
   105
		y ^= 0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
		if (x - y < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
			z += (x - y) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   110
	case SLOPE_N:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
		y ^= 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
		if (y - x >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
			z = (y - x) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   116
	case SLOPE_NW:
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
   117
		z = (y ^ 0xF) >> 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   120
	case SLOPE_NWS:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
		z = 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
		if (x - y < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
			z += (x - y) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   126
	case SLOPE_NE:
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
   127
		z = (x ^ 0xF) >> 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   130
	case SLOPE_ENW:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
		z = 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
		y ^= 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
		if (y - x < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
			z += (y - x) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   137
	case SLOPE_SEN:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
		z = 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
		if (y - x < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
			z += (y - x) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   143
	case SLOPE_STEEP_S:
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
   144
		z = 1 + ((x + y) >> 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   147
	case SLOPE_STEEP_W:
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
   148
		z = 1 + ((x + (y ^ 0xF)) >> 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   151
	case SLOPE_STEEP_N:
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
   152
		z = 1 + (((x ^ 0xF) + (y ^ 0xF)) >> 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
		break;
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   154
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   155
	case SLOPE_STEEP_E:
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
   156
		z = 1 + (((x ^ 0xF) + (y ^ 0xF)) >> 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
		break;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   158
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   159
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	return z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   165
uint GetSlopeZ(int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
   167
	TileIndex tile = TileVirtXY(x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
   169
	return _tile_type_procs[GetTileType(tile)]->get_slope_z_proc(tile, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   171
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   172
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   173
static Slope GetFoundationSlope(TileIndex tile, uint* z)
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
   174
{
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   175
	Slope tileh = GetTileSlope(tile, z);
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   176
	Slope slope = _tile_type_procs[GetTileType(tile)]->get_slope_tileh_proc(tile, tileh);
50
7cdbf3ed0501 (svn r51) Yet another slope graphics fix
dominik
parents: 39
diff changeset
   177
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   178
	/* Flatter slope -> higher base height */
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   179
	if (slope < tileh) *z += TILE_HEIGHT;
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   180
	return slope;
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   181
}
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 37
diff changeset
   182
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   183
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   184
static bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   185
{
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   186
	uint z;
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   187
	Slope slope = GetFoundationSlope(TILE_ADDXY(tile, 0, -1), &z);
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   188
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   189
	return
4990
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   190
		(
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   191
			z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) + (slope_here == SLOPE_STEEP_N ? TILE_HEIGHT : 0) >
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   192
			z      + (slope      & SLOPE_E ? TILE_HEIGHT : 0) + (slope      == SLOPE_STEEP_E ? TILE_HEIGHT : 0)
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   193
		) || (
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   194
			z_here + (slope_here & SLOPE_W ? TILE_HEIGHT : 0) + (slope_here == SLOPE_STEEP_W ? TILE_HEIGHT : 0) >
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   195
			z      + (slope      & SLOPE_S ? TILE_HEIGHT : 0) + (slope      == SLOPE_STEEP_S ? TILE_HEIGHT : 0)
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   196
		);
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
   197
}
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
   198
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   199
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   200
static bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   201
{
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   202
	uint z;
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   203
	Slope slope = GetFoundationSlope(TILE_ADDXY(tile, -1, 0), &z);
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   204
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   205
	return
4990
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   206
		(
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   207
			z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) + (slope_here == SLOPE_STEEP_N ? TILE_HEIGHT : 0) >
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   208
			z      + (slope      & SLOPE_W ? TILE_HEIGHT : 0) + (slope      == SLOPE_STEEP_W ? TILE_HEIGHT : 0)
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   209
		) || (
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   210
			z_here + (slope_here & SLOPE_E ? TILE_HEIGHT : 0) + (slope_here == SLOPE_STEEP_E ? TILE_HEIGHT : 0) >
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   211
			z      + (slope      & SLOPE_S ? TILE_HEIGHT : 0) + (slope      == SLOPE_STEEP_S ? TILE_HEIGHT : 0)
776ba4323093 (svn r6993) -Regression (r5833): Rails/roads on steep slopes incorrectly show a foundation edge if the NE/NW adjacent tile is a steep tile
tron
parents: 4344
diff changeset
   212
		);
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   213
}
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   214
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   215
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
void DrawFoundation(TileInfo *ti, uint f)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
{
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5847
diff changeset
   218
	SpriteID sprite_base = SPR_SLOPES_BASE - 15;
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   219
	Slope slope;
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   220
	uint z;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 37
diff changeset
   221
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   222
	slope = GetFoundationSlope(ti->tile, &z);
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   223
	if (!HasFoundationNW(ti->tile, slope, z)) sprite_base += 22;
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   224
	if (!HasFoundationNE(ti->tile, slope, z)) sprite_base += 44;
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
   225
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   226
	if (IsSteepSlope(ti->tileh)) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5847
diff changeset
   227
		SpriteID lower_base;
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
   228
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   229
		/* Lower part of foundation */
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   230
		lower_base = sprite_base;
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   231
		if (lower_base == SPR_SLOPES_BASE - 15) lower_base = SPR_FOUNDATION_BASE;
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   232
		AddSortableSpriteToDraw(
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5847
diff changeset
   233
			lower_base + (ti->tileh & ~SLOPE_STEEP), PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   234
		);
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   235
		ti->z += TILE_HEIGHT;
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   236
		ti->tileh = _inclined_tileh[f - 15];
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   237
		if (f < 15 + 8) {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   238
			/* inclined */
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5847
diff changeset
   239
			AddSortableSpriteToDraw(sprite_base + f, PAL_NONE, ti->x, ti->y, 16, 16, 1, ti->z);
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   240
			OffsetGroundSprite(31, 9);
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   241
		} else if (f >= 15 + 8 + 4) {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   242
			/* three corners raised */
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5847
diff changeset
   243
			SpriteID upper = sprite_base + 15 + (f - 15 - 8 - 4) * 2;
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   244
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5847
diff changeset
   245
			AddSortableSpriteToDraw(upper, PAL_NONE, ti->x, ti->y, 16, 16, 1, ti->z);
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5847
diff changeset
   246
			AddChildSpriteScreen(upper + 1, PAL_NONE, 31, 9);
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   247
			OffsetGroundSprite(31, 9);
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   248
		} else {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   249
			/* one corner raised */
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   250
			OffsetGroundSprite(31, 1);
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   251
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
	} else {
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   253
		if (f < 15) {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   254
			/* leveled foundation
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   255
			 * Use the original slope sprites if NW and NE borders should be visible */
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   256
			if (sprite_base  == SPR_SLOPES_BASE - 15) sprite_base = SPR_FOUNDATION_BASE;
4246
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4240
diff changeset
   257
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5847
diff changeset
   258
			AddSortableSpriteToDraw(sprite_base + f, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
4246
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4240
diff changeset
   259
			ti->z += TILE_HEIGHT;
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   260
			ti->tileh = SLOPE_FLAT;
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   261
			OffsetGroundSprite(31, 1);
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   262
		} else {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   263
			/* inclined foundation */
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5847
diff changeset
   264
			AddSortableSpriteToDraw(sprite_base + f, PAL_NONE, ti->x, ti->y, 16, 16, 1, ti->z);
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   265
			ti->tileh = _inclined_tileh[f - 15];
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   266
			OffsetGroundSprite(31, 9);
4246
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4240
diff changeset
   267
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
1589
58d173b56509 (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   271
void DoClearSquare(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
{
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   273
	MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   274
	MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9910
diff changeset
   277
uint32 GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
{
9912
1ac8aac92385 (svn r10136) [gamebalance] -Sync: r9900:10100 from trunk
celestar
parents: 9910
diff changeset
   279
	return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode, sub_mode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   282
void ChangeTileOwner(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   284
	_tile_type_procs[GetTileType(tile)]->change_tile_owner_proc(tile, old_player, new_player);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
1589
58d173b56509 (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   287
void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
	memset(ac, 0, sizeof(AcceptedCargo));
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   290
	_tile_type_procs[GetTileType(tile)]->get_accepted_cargo_proc(tile, ac);
0
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
1589
58d173b56509 (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   293
void AnimateTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   295
	_tile_type_procs[GetTileType(tile)]->animate_tile_proc(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
1589
58d173b56509 (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   298
void ClickTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   300
	_tile_type_procs[GetTileType(tile)]->click_tile_proc(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
1589
58d173b56509 (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   303
void GetTileDesc(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   305
	_tile_type_procs[GetTileType(tile)]->get_tile_desc_proc(tile, td);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   307
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   308
/**
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   309
 * Has a snow line table already been loaded.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   310
 * @return true if the table has been loaded already.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   311
 */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   312
bool IsSnowLineSet(void)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   313
{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   314
	return _snow_line != NULL;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   315
}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   316
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   317
/**
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   318
 * Set a variable snow line, as loaded from a newgrf file.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   319
 * @param table the 12 * 32 byte table containing the snowline for each day
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   320
 */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   321
void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   322
{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   323
	_snow_line = CallocT<SnowLine>(1);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   324
	memcpy(_snow_line->table, table, sizeof(_snow_line->table));
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   325
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   326
	for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   327
		for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   328
			_snow_line->highest_value = max(_snow_line->highest_value, table[i][j]);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   329
		}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   330
	}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   331
}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   332
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   333
/**
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   334
 * Get the current snow line, either variable or static.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   335
 * @return the snow line height.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   336
 */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   337
byte GetSnowLine(void)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   338
{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   339
	if (_snow_line == NULL) return _opt.snow_line;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   340
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   341
	YearMonthDay ymd;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   342
	ConvertDateToYMD(_date, &ymd);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   343
	return _snow_line->table[ymd.month][ymd.day];
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   344
}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   345
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   346
/**
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   347
 * Get the highest possible snow line height, either variable or static.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   348
 * @return the highest snow line height.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   349
 */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   350
byte HighestSnowLine(void)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   351
{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   352
	return _snow_line == NULL ? _opt.snow_line : _snow_line->highest_value;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   353
}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   354
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   355
/**
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   356
 * Clear the variable snow line table and free the memory.
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   357
 */
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   358
void ClearSnowLine(void)
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   359
{
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   360
	free(_snow_line);
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   361
	_snow_line = NULL;
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   362
}
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   363
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1589
diff changeset
   364
/** Clear a piece of landscape
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   365
 * @param tile tile to clear
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   366
 * @param flags of operation to conduct
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1589
diff changeset
   367
 * @param p1 unused
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1589
diff changeset
   368
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
 */
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   370
CommandCost CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   374
	return _tile_type_procs[GetTileType(tile)]->clear_tile_proc(tile, flags);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   377
/** Clear a big piece of landscape
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   378
 * @param tile end tile of area dragging
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   379
 * @param p1 start tile of area dragging
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   380
 * @param flags of operation to conduct
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   381
 * @param p2 unused
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   382
 */
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   383
CommandCost CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
{
9913
e79cd19772dd (svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents: 9912
diff changeset
   385
	CommandCost cost, ret, money;
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   386
	int ex;
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   387
	int ey;
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
   388
	int sx, sy;
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
   389
	int x, y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	bool success = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
2934
3b7eef9871f8 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2639
diff changeset
   392
	if (p1 >= MapSize()) return CMD_ERROR;
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   393
889
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 863
diff changeset
   394
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 863
diff changeset
   395
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   396
	/* make sure sx,sy are smaller than ex,ey */
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   397
	ex = TileX(tile);
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   398
	ey = TileY(tile);
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   399
	sx = TileX(p1);
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   400
	sy = TileY(p1);
6432
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 5919
diff changeset
   401
	if (ex < sx) Swap(ex, sx);
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 5919
diff changeset
   402
	if (ey < sy) Swap(ey, sy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
	money = GetAvailableMoneyForCommand();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
	cost = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   407
	for (x = sx; x <= ex; ++x) {
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   408
		for (y = sy; y <= ey; ++y) {
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   409
			ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   410
			if (CmdFailed(ret)) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
			cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
			success = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
			if (flags & DC_EXEC) {
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   415
				if (ret > 0 && (money -= ret) < 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
					_additional_cash_required = ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
					return cost - ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
				}
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   419
				DoCommand(TileXY(x, y), 0, 0, flags, CMD_LANDSCAPE_CLEAR);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   421
				/* draw explosion animation... */
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   422
				if ((x == sx || x == ex) && (y == sy || y == ey)) {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   423
					/* big explosion in each corner, or small explosion for single tiles */
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   424
					CreateEffectVehicleAbove(x * TILE_SIZE + TILE_SIZE / 2, y * TILE_SIZE + TILE_SIZE / 2, 2,
1359
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1350
diff changeset
   425
						sy == ey && sx == ex ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1350
diff changeset
   426
					);
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
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   432
	return (success) ? cost : CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
#define TILELOOP_BITS 4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
#define TILELOOP_SIZE (1 << TILELOOP_BITS)
9910
0b2aebc8283e (svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents: 9906
diff changeset
   438
#define TILELOOP_ASSERTMASK ((TILELOOP_SIZE - 1) + ((TILELOOP_SIZE - 1) << MapLogX()))
927
28f45a22a564 (svn r1415) Move TILE_FROM_XY and TILE_XY to map.h and push TILE_[XY] bits from map.h into map.c.
tron
parents: 926
diff changeset
   439
#define TILELOOP_CHKMASK (((1 << (MapLogX() - TILELOOP_BITS))-1) << TILELOOP_BITS)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6527
diff changeset
   441
void RunTileLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
{
1589
58d173b56509 (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   443
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
	uint count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
	tile = _cur_tileloop_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
	assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
863
8d09f9331a80 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 857
diff changeset
   449
	count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
	do {
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   451
		_tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
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: 925
diff changeset
   453
		if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   454
			tile += TILELOOP_SIZE; // no overflow
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
		} else {
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   456
			tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE - 1) + TileDiffXY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
0
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
	} while (--count);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
	assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
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
	tile += 9;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
	if (tile & TILELOOP_CHKMASK)
863
8d09f9331a80 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 857
diff changeset
   463
		tile = (tile + MapSizeX()) & TILELOOP_ASSERTMASK;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
	_cur_tileloop_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6527
diff changeset
   467
void InitializeLandscape()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
{
3078
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   469
	uint maxx = MapMaxX();
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   470
	uint maxy = MapMaxY();
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   471
	uint sizex = MapSizeX();
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   472
	uint x;
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   473
	uint y;
1218
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1214
diff changeset
   474
3078
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   475
	for (y = 0; y < maxy; y++) {
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   476
		for (x = 0; x < maxx; x++) {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   477
			MakeClear(sizex * y + x, CLEAR_GRASS, 3);
3078
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   478
			SetTileHeight(sizex * y + x, 0);
5847
9ce114e1d90d (svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents: 5838
diff changeset
   479
			SetTropicZone(sizex * y + x, TROPICZONE_INVALID);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4990
diff changeset
   480
			ClearBridgeMiddle(sizex * y + x);
3078
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   481
		}
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   482
		MakeVoid(sizex * y + x);
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   483
	}
3078
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   484
	for (x = 0; x < sizex; x++) MakeVoid(sizex * y + x);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   485
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6527
diff changeset
   487
void ConvertGroundTilesIntoWaterTiles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
{
4000
bab1ebc37da0 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
   489
	TileIndex tile;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   490
	uint z;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   491
	Slope slope;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   493
	for (tile = 0; tile < MapSize(); ++tile) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   494
		slope = GetTileSlope(tile, &z);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   495
		if (IsTileType(tile, MP_CLEAR) && z == 0) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   496
			/* Make both water for tiles at level 0
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   497
			 * and make shore, as that looks much better
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   498
			 * during the generation. */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   499
			switch (slope) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   500
				case SLOPE_FLAT:
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   501
					MakeWater(tile);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   502
					break;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   503
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   504
				case SLOPE_N:
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   505
				case SLOPE_E:
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   506
				case SLOPE_S:
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   507
				case SLOPE_W:
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   508
				case SLOPE_NW:
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   509
				case SLOPE_SW:
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   510
				case SLOPE_SE:
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   511
				case SLOPE_NE:
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   512
					MakeShore(tile);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   513
					break;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   514
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   515
				default:
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   516
					break;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   517
			}
0
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   520
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   522
static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4  };
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   523
static const byte _genterrain_tbl_2[5] = {  0,  0,  0,  0, 33 };
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
static void GenerateTerrain(int type, int flag)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	uint32 r;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   528
	uint x;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   529
	uint y;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   530
	uint w;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   531
	uint h;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   532
	const Sprite* templ;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   533
	const byte *p;
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   534
	Tile* tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   535
	byte direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   536
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   537
	r = Random();
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   538
	templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
856
07dc27d0503e (svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents: 851
diff changeset
   540
	x = r & MapMaxX();
927
28f45a22a564 (svn r1415) Move TILE_FROM_XY and TILE_XY to map.h and push TILE_[XY] bits from map.h into map.c.
tron
parents: 926
diff changeset
   541
	y = (r >> MapLogX()) & MapMaxY();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   544
	if (x < 2 || y < 2) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
2140
d708eb80ab8b (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2055
diff changeset
   546
	direction = GB(r, 22, 2);
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   547
	if (direction & 1) {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   548
		w = templ->height;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   549
		h = templ->width;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   550
	} else {
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   551
		w = templ->width;
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   552
		h = templ->height;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   553
	}
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   554
	p = templ->data;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   556
	if (flag & 4) {
1273
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   557
		uint xw = x * MapSizeY();
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   558
		uint yw = y * MapSizeX();
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   559
		uint bias = (MapSizeX() + MapSizeY()) * 16;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   560
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   561
		switch (flag & 3) {
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   562
			case 0:
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   563
				if (xw + yw > MapSize() - bias) return;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   564
				break;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   565
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   566
			case 1:
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   567
				if (yw < xw + bias) return;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   568
				break;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   569
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   570
			case 2:
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   571
				if (xw + yw < MapSize() + bias) return;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   572
				break;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   573
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   574
			case 3:
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   575
				if (xw < yw + bias) return;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   576
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   579
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   580
	if (x + w >= MapMaxX() - 1) return;
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   581
	if (y + h >= MapMaxY() - 1) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   583
	tile = &_m[TileXY(x, y)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   585
	switch (direction) {
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   586
		case 0:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   587
			do {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   588
				Tile* tile_cur = tile;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   589
				uint w_cur;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   590
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   591
				for (w_cur = w; w_cur != 0; --w_cur) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   592
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   593
					p++;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   594
					tile_cur++;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   595
				}
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   596
				tile += TileDiffXY(0, 1);
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   597
			} while (--h != 0);
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   598
			break;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   599
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   600
		case 1:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
			do {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   602
				Tile* tile_cur = tile;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   603
				uint h_cur;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   604
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   605
				for (h_cur = h; h_cur != 0; --h_cur) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   606
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   607
					p++;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   608
					tile_cur += TileDiffXY(0, 1);
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   609
				}
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   610
				tile++;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   611
			} while (--w != 0);
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   612
			break;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   613
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   614
		case 2:
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   615
			tile += TileDiffXY(w - 1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
			do {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   617
				Tile* tile_cur = tile;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   618
				uint w_cur;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   619
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   620
				for (w_cur = w; w_cur != 0; --w_cur) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   621
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   622
					p++;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   623
					tile_cur--;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   624
				}
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   625
				tile += TileDiffXY(0, 1);
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   626
			} while (--h != 0);
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   627
			break;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   628
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   629
		case 3:
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   630
			tile += TileDiffXY(0, h - 1);
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   631
			do {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   632
				Tile* tile_cur = tile;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   633
				uint h_cur;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   634
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   635
				for (h_cur = h; h_cur != 0; --h_cur) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   636
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   637
					p++;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   638
					tile_cur -= TileDiffXY(0, 1);
1278
1fbb6cf8d3f1 (svn r1782) Remove line which should've been removed in r1779 and caused map generation to hang infinitely
tron
parents: 1275
diff changeset
   639
				}
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   640
				tile++;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   641
			} while (--w != 0);
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   642
			break;
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   646
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
#include "table/genland.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6527
diff changeset
   649
static void CreateDesertOrRainForest()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
{
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   651
	TileIndex tile;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   652
	TileIndex update_freq = MapSize() / 4;
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   653
	const TileIndexDiffC *data;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   654
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   656
	for (tile = 0; tile != MapSize(); ++tile) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   657
		if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   658
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   659
		for (data = _make_desert_or_rainforest_data;
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   660
				data != endof(_make_desert_or_rainforest_data); ++data) {
1184
7f0ac9482dad (svn r1686) Fix (Work around?) crash when generating tropical maps
tron
parents: 1181
diff changeset
   661
			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
1044
9b73df700a7c (svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents: 1035
diff changeset
   662
			if (TileHeight(t) >= 4 || IsTileType(t, MP_WATER)) break;
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   663
		}
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   664
		if (data == endof(_make_desert_or_rainforest_data))
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3297
diff changeset
   665
			SetTropicZone(tile, TROPICZONE_DESERT);
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   666
	}
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   667
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   668
	for (i = 0; i != 256; i++) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   669
		if ((i % 64) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   670
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
		RunTileLoop();
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   672
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   673
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   674
	for (tile = 0; tile != MapSize(); ++tile) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   675
		if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   676
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   677
		for (data = _make_desert_or_rainforest_data;
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   678
				data != endof(_make_desert_or_rainforest_data); ++data) {
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   679
			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   680
			if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break;
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   681
		}
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   682
		if (data == endof(_make_desert_or_rainforest_data))
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3297
diff changeset
   683
			SetTropicZone(tile, TROPICZONE_RAINFOREST);
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   684
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   687
void GenerateLandscape(byte mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
{
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   689
	const int gwp_desert_amount = 4 + 8;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   690
	uint i;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   691
	uint flag;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
	uint32 r;
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   693
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   694
	if (mode == GW_HEIGHTMAP) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   695
		SetGeneratingWorldProgress(GWP_LANDSCAPE, (_opt.landscape == LT_TROPIC) ? 1 + gwp_desert_amount : 1);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   696
		LoadHeightmap(_file_to_saveload.name);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   697
		IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   698
	} else if (_patches.land_generator == LG_TERRAGENESIS) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   699
		SetGeneratingWorldProgress(GWP_LANDSCAPE, (_opt.landscape == LT_TROPIC) ? 3 + gwp_desert_amount : 3);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   700
		GenerateTerrainPerlin();
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   701
	} else {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   702
		switch (_opt.landscape) {
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   703
			case LT_ARCTIC:
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   704
				SetGeneratingWorldProgress(GWP_LANDSCAPE, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   706
				for (i = ScaleByMapSize((Random() & 0x7F) + 950); i != 0; --i) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   707
					GenerateTerrain(2, 0);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   708
				}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   709
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2955
diff changeset
   710
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   711
				r = Random();
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   712
				flag = GB(r, 0, 2) | 4;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   713
				for (i = ScaleByMapSize(GB(r, 16, 7) + 450); i != 0; --i) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   714
					GenerateTerrain(4, flag);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   715
				}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   716
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   717
				break;
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2955
diff changeset
   718
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   719
			case LT_TROPIC:
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   720
				SetGeneratingWorldProgress(GWP_LANDSCAPE, 3 + gwp_desert_amount);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   721
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   722
				for (i = ScaleByMapSize((Random() & 0x7F) + 170); i != 0; --i) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   723
					GenerateTerrain(0, 0);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   724
				}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   725
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   726
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   727
				r = Random();
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   728
				flag = GB(r, 0, 2) | 4;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   729
				for (i = ScaleByMapSize(GB(r, 16, 8) + 1700); i != 0; --i) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   730
					GenerateTerrain(0, flag);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   731
				}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   732
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   733
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   734
				flag ^= 2;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   735
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   736
				for (i = ScaleByMapSize((Random() & 0x7F) + 410); i != 0; --i) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   737
					GenerateTerrain(3, flag);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   738
				}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   739
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   740
				break;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   741
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   742
			default:
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   743
				SetGeneratingWorldProgress(GWP_LANDSCAPE, 1);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   744
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   745
				i = ScaleByMapSize((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes) * 256 + 100);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   746
				for (; i != 0; --i) {
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   747
					GenerateTerrain(_opt.diff.terrain_type, 0);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   748
				}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   749
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   750
				break;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   751
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
	ConvertGroundTilesIntoWaterTiles();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
9906
6f41b8713b65 (svn r9674) [gamebalance] -Sync: r9322:9420 from trunk
celestar
parents: 9895
diff changeset
   756
	if (_opt.landscape == LT_TROPIC) CreateDesertOrRainForest();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6527
diff changeset
   759
void OnTick_Town();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6527
diff changeset
   760
void OnTick_Trees();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6527
diff changeset
   761
void OnTick_Station();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6527
diff changeset
   762
void OnTick_Industry();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6527
diff changeset
   764
void OnTick_Players();
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6527
diff changeset
   765
void OnTick_Train();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
9895
7bd07f43b0e3 (svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents: 6527
diff changeset
   767
void CallLandscapeTick()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
	OnTick_Town();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
	OnTick_Trees();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
	OnTick_Station();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
	OnTick_Industry();
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
	OnTick_Players();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
	OnTick_Train();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
	int rn = rng;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
	uint32 r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   783
	return TILE_MASK(TileXY(
2150
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   784
		TileX(a) + (GB(r, 0, 8) * rn * 2 >> 8) - rn,
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   785
		TileY(a) + (GB(r, 8, 8) * rn * 2 >> 8) - rn
1174
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1140
diff changeset
   786
	));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   787
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
1589
58d173b56509 (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   789
bool IsValidTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
{
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: 925
diff changeset
   791
	return (tile < MapSizeX() * MapMaxY() && TileX(tile) != MapMaxX());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
}