landscape.c
author truelight
Sat, 19 Aug 2006 10:00:30 +0000
changeset 4300 c7e43c47a2b9
parent 4253 b468db807b66
child 4344 7e123fec5b0b
permissions -rw-r--r--
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1793
diff changeset
     4
#include "openttd.h"
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
     5
#include "heightmap.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3111
diff changeset
     6
#include "clear_map.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     7
#include "functions.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 473
diff changeset
     8
#include "map.h"
2154
f86c59e73a16 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2150
diff changeset
     9
#include "player.h"
1349
15979a2e9001 (svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents: 1335
diff changeset
    10
#include "spritecache.h"
1363
775a7ee52369 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1359
diff changeset
    11
#include "table/sprites.h"
1209
2e00193652b2 (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
    12
#include "tile.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include <stdarg.h>
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
#include "command.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
#include "vehicle.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    17
#include "variables.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3111
diff changeset
    18
#include "void_map.h"
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3078
diff changeset
    19
#include "water_map.h"
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
    20
#include "tgp.h"
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
    21
#include "genworld.h"
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
    22
#include "heightmap.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
    24
extern const TileTypeProcs
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
	_tile_type_clear_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
	_tile_type_rail_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	_tile_type_road_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	_tile_type_town_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	_tile_type_trees_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	_tile_type_station_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	_tile_type_water_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	_tile_type_dummy_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	_tile_type_industry_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	_tile_type_tunnelbridge_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	_tile_type_unmovable_procs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
const TileTypeProcs * const _tile_type_procs[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	&_tile_type_clear_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
	&_tile_type_rail_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
	&_tile_type_road_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
	&_tile_type_town_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
	&_tile_type_trees_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
	&_tile_type_station_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
	&_tile_type_water_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
	&_tile_type_dummy_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
	&_tile_type_industry_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
	&_tile_type_tunnelbridge_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
	&_tile_type_unmovable_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
/* landscape slope => sprite */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
const byte _tileh_to_sprite[32] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	0,0,0,0,0,0,0,16,0,0,0,17,0,15,18,0,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
1958
0266bb01a1e6 (svn r2464) Move definition of _inclined_tileh out of variables.h
tron
parents: 1902
diff changeset
    57
const byte _inclined_tileh[] = {
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
    58
	SLOPE_SW, SLOPE_NW, SLOPE_SW, SLOPE_SE, SLOPE_NE, SLOPE_SE, SLOPE_NE, SLOPE_NW,
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
    59
	SLOPE_E, SLOPE_N, SLOPE_W, SLOPE_S,
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
    60
	SLOPE_NWS, SLOPE_WSE, SLOPE_SEN, SLOPE_ENW
1958
0266bb01a1e6 (svn r2464) Move definition of _inclined_tileh out of variables.h
tron
parents: 1902
diff changeset
    61
};
0266bb01a1e6 (svn r2464) Move definition of _inclined_tileh out of variables.h
tron
parents: 1902
diff changeset
    62
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    64
uint GetPartialZ(int x, int y, Slope corners)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
	int z = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
    68
	switch (corners) {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    69
	case SLOPE_W:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
		if (x - y >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
			z = (x - y) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
		break;
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
    73
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    74
	case SLOPE_S:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
		y^=0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
		if ( (x - y) >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
			z = (x - y) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    80
	case SLOPE_SW:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
		z = (x>>1) + 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
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    84
	case SLOPE_E:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
		if (y - x >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
			z = (y - x) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    89
	case SLOPE_EW:
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    90
	case SLOPE_NS:
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    91
	case SLOPE_ELEVATED:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
		z = 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    93
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    95
	case SLOPE_SE:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
		z = (y>>1) + 1;
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
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
    99
	case SLOPE_WSE:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
		z = 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   101
		y^=0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
		if (x - y < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   103
			z += (x - y) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   106
	case SLOPE_N:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
		y ^= 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
		if (y - x >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
			z = (y - x) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   112
	case SLOPE_NW:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
		z = (y^0xF)>>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
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   116
	case SLOPE_NWS:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
		z = 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
		if (x - y < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
			z += (x - y) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   122
	case SLOPE_NE:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
		z = (x^0xF)>>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
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   126
	case SLOPE_ENW:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
		z = 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
		y ^= 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
		if (y - x < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
			z += (y - x) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   133
	case SLOPE_SEN:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
		z = 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
		if (y - x < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
			z += (y - x) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   139
	case SLOPE_STEEP_S:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
		z = 1 + ((x+y)>>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
a36cc46e754d (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_W:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
		z = 1 + ((x+(y^0xF))>>1);
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
a36cc46e754d (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_N:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
		z = 1 + (((x^0xF)+(y^0xF))>>1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
		break;
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   150
3636
a36cc46e754d (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_E:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
		z = 1 + (((x^0xF)+(y^0xF))>>1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
		break;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   154
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   155
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
	return z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   161
uint GetSlopeZ(int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
   163
	TileIndex tile = TileVirtXY(x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
   165
	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
   166
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
4061
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   168
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   169
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
   170
{
4061
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   171
	Slope tileh = GetTileSlope(tile, z);
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   172
	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
   173
4061
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   174
	// Flatter slope -> higher base height
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   175
	if (slope < tileh) *z += TILE_HEIGHT;
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   176
	return slope;
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   177
}
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 37
diff changeset
   178
4061
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   179
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   180
static bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   181
{
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   182
	uint z;
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   183
	Slope slope = GetFoundationSlope(TILE_ADDXY(tile, 0, -1), &z);
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   184
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   185
	return
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   186
		(z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) > z + (slope & SLOPE_E ? TILE_HEIGHT : 0)) ||
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   187
		(z_here + (slope_here & SLOPE_W ? TILE_HEIGHT : 0) > z + (slope & SLOPE_S ? TILE_HEIGHT : 0));
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
   188
}
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
   189
4061
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   190
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   191
static bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   192
{
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   193
	uint z;
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   194
	Slope slope = GetFoundationSlope(TILE_ADDXY(tile, -1, 0), &z);
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   195
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   196
	return
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   197
		(z_here + (slope_here & SLOPE_N ? TILE_HEIGHT : 0) > z + (slope & SLOPE_W ? TILE_HEIGHT : 0)) ||
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   198
		(z_here + (slope_here & SLOPE_E ? TILE_HEIGHT : 0) > z + (slope & SLOPE_S ? TILE_HEIGHT : 0));
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   199
}
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   200
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   201
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
void DrawFoundation(TileInfo *ti, uint f)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
{
4240
233b63317667 (svn r5810) Shuffle some constants for clarity and remove a case which cannot occur in DrawFoundation()
tron
parents: 4238
diff changeset
   204
	uint32 sprite_base = SPR_SLOPES_BASE - 15;
4061
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   205
	Slope slope;
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   206
	uint z;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 37
diff changeset
   207
4061
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   208
	slope = GetFoundationSlope(ti->tile, &z);
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   209
	if (!HasFoundationNW(ti->tile, slope, z)) sprite_base += 22;
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   210
	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
   211
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   212
	if (IsSteepSlope(ti->tileh)) {
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   213
		uint32 lower_base;
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
   214
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   215
		// Lower part of foundation
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   216
		lower_base = sprite_base;
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   217
		if (lower_base == SPR_SLOPES_BASE - 15) lower_base = SPR_FOUNDATION_BASE;
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   218
		AddSortableSpriteToDraw(
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   219
			lower_base + (ti->tileh & ~SLOPE_STEEP), ti->x, ti->y, 16, 16, 7, ti->z
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   220
		);
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   221
		ti->z += TILE_HEIGHT;
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   222
		ti->tileh = _inclined_tileh[f - 15];
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   223
		if (f < 15 + 8) {
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   224
			// inclined
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   225
			AddSortableSpriteToDraw(sprite_base + f, ti->x, ti->y, 16, 16, 1, ti->z);
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   226
			OffsetGroundSprite(31, 9);
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   227
		} else if (f >= 15 + 8 + 4) {
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   228
			// three corners raised
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   229
			uint32 upper = sprite_base + 15 + (f - 15 - 8 - 4) * 2;
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   230
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   231
			AddSortableSpriteToDraw(upper, ti->x, ti->y, 16, 16, 1, ti->z);
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   232
			AddChildSpriteScreen(upper + 1, 31, 9);
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   233
			OffsetGroundSprite(31, 9);
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   234
		} else {
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   235
			// one corner raised
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   236
			OffsetGroundSprite(31, 1);
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   237
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
	} else {
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   239
		if (f < 15) {
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   240
			// leveled foundation
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   241
			// Use the original slope sprites if NW and NE borders should be visible
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   242
			if (sprite_base  == SPR_SLOPES_BASE - 15) sprite_base = SPR_FOUNDATION_BASE;
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4240
diff changeset
   243
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   244
			AddSortableSpriteToDraw(sprite_base + f, ti->x, ti->y, 16, 16, 7, ti->z);
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4240
diff changeset
   245
			ti->z += TILE_HEIGHT;
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   246
			ti->tileh = SLOPE_FLAT;
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   247
			OffsetGroundSprite(31, 1);
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   248
		} else {
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   249
			// inclined foundation
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   250
			AddSortableSpriteToDraw(sprite_base + f, ti->x, ti->y, 16, 16, 1, ti->z);
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   251
			ti->tileh = _inclined_tileh[f - 15];
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   252
			OffsetGroundSprite(31, 9);
4246
6dcc0e44a367 (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4240
diff changeset
   253
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   257
void DoClearSquare(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
{
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   259
	MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0);
2955
24de69e236d2 (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
   260
	MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   263
uint32 GetTileTrackStatus(TileIndex tile, TransportType mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   265
	return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   268
void ChangeTileOwner(TileIndex tile, byte old_player, byte new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   270
	_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
   271
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   273
void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	memset(ac, 0, sizeof(AcceptedCargo));
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   276
	_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
   277
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   279
void AnimateTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   281
	_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
   282
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   284
void ClickTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   286
	_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
   287
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   289
void GetTileDesc(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   291
	_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
   292
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
1775
548dc04d50e2 (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
   294
/** Clear a piece of landscape
3491
35d747bb5e82 (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
   295
 * @param tile tile to clear
1775
548dc04d50e2 (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
   296
 * @param p1 unused
548dc04d50e2 (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
   297
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
 */
3491
35d747bb5e82 (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
   299
int32 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
   300
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   303
	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
   304
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   306
/** Clear a big piece of landscape
3491
35d747bb5e82 (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
   307
 * @param tile end tile of area dragging
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   308
 * @param p1 start tile of area dragging
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   309
 * @param p2 unused
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   310
 */
3491
35d747bb5e82 (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
   311
int32 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
   312
{
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   313
	int32 cost, ret, money;
3491
35d747bb5e82 (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
   314
	int ex;
35d747bb5e82 (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
   315
	int ey;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
	int sx,sy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
	int x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   318
	bool success = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
2934
3f29a7212713 (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
   320
	if (p1 >= MapSize()) return CMD_ERROR;
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   321
889
64d2f7d5f02b (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
   322
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
64d2f7d5f02b (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
   323
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
	// make sure sx,sy are smaller than ex,ey
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   325
	ex = TileX(tile);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   326
	ey = TileY(tile);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   327
	sx = TileX(p1);
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   328
	sy = TileY(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
	if (ex < sx) intswap(ex, sx);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
	if (ey < sy) intswap(ey, sy);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
	money = GetAvailableMoneyForCommand();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
	cost = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   335
	for (x = sx; x <= ex; ++x) {
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   336
		for (y = sy; y <= ey; ++y) {
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   337
			ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   338
			if (CmdFailed(ret)) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
			cost += ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
			success = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
			if (flags & DC_EXEC) {
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   343
				if (ret > 0 && (money -= ret) < 0) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
					_additional_cash_required = ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
					return cost - ret;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
				}
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   347
				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
   348
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
				// draw explosion animation...
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   350
				if ((x == sx || x == ex) && (y == sy || y == ey)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
					// big explosion in each corner, or small explosion for single tiles
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   352
					CreateEffectVehicleAbove(x * TILE_SIZE + TILE_SIZE / 2, y * TILE_SIZE + TILE_SIZE / 2, 2,
1359
52782e5cf7c9 (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
   353
						sy == ey && sx == ex ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
52782e5cf7c9 (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
   354
					);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   360
	return (success) ? cost : CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
#define TILELOOP_BITS 4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
#define TILELOOP_SIZE (1 << TILELOOP_BITS)
927
94fec9843fd3 (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
   366
#define TILELOOP_ASSERTMASK ((TILELOOP_SIZE-1) + ((TILELOOP_SIZE-1) << MapLogX()))
94fec9843fd3 (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
   367
#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
   368
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   369
void RunTileLoop(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
{
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   371
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   372
	uint count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
	tile = _cur_tileloop_tile;
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
	assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
863
6a1444534f62 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 857
diff changeset
   377
	count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
	do {
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   379
		_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
   380
926
a6d140a6a4de (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
   381
		if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
			tile += TILELOOP_SIZE; /* no overflow */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
		} else {
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   384
			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
   385
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
	} while (--count);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
	assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
	tile += 9;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	if (tile & TILELOOP_CHKMASK)
863
6a1444534f62 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 857
diff changeset
   391
		tile = (tile + MapSizeX()) & TILELOOP_ASSERTMASK;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
	_cur_tileloop_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
2055
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2051
diff changeset
   395
void InitializeLandscape(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
{
3078
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   397
	uint maxx = MapMaxX();
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   398
	uint maxy = MapMaxY();
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   399
	uint sizex = MapSizeX();
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   400
	uint x;
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   401
	uint y;
1218
c6a624956ac6 (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1214
diff changeset
   402
3078
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   403
	for (y = 0; y < maxy; y++) {
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   404
		for (x = 0; x < maxx; x++) {
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   405
			MakeClear(sizex * y + x, CLEAR_GRASS, 3);
3078
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   406
			SetTileHeight(sizex * y + x, 0);
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   407
		}
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   408
		MakeVoid(sizex * y + x);
2049
538e73c53f54 (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
   409
	}
3078
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   410
	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
   411
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   413
void ConvertGroundTilesIntoWaterTiles(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
{
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
   415
	TileIndex tile;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   416
	uint z;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   417
	Slope slope;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   419
	for (tile = 0; tile < MapSize(); ++tile) {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   420
		slope = GetTileSlope(tile, &z);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   421
		if (IsTileType(tile, MP_CLEAR) && z == 0) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   422
			/* Make both water for tiles at level 0
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   423
			 * and make shore, as that looks much better
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   424
			 * during the generation. */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   425
			switch (slope) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   426
				case SLOPE_FLAT:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   427
					MakeWater(tile);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   428
					break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   429
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   430
				case SLOPE_N:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   431
				case SLOPE_E:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   432
				case SLOPE_S:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   433
				case SLOPE_W:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   434
				case SLOPE_NW:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   435
				case SLOPE_SW:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   436
				case SLOPE_SE:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   437
				case SLOPE_NE:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   438
					MakeShore(tile);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   439
					break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   440
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   441
				default:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   442
					break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   443
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
}
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
static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4 };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
static const byte _genterrain_tbl_2[5] = { 0, 0, 0, 0, 33 };
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
static void GenerateTerrain(int type, int flag)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	uint32 r;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   454
	uint x;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   455
	uint y;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   456
	uint w;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   457
	uint h;
1384
17fe20da74ef (svn r1888) The landscape template sprites are ordinary sprites, treating them as non-sprites resulted in yet another endianess issue. This fixes the problem introduced in r1855
tron
parents: 1363
diff changeset
   458
	const Sprite* template;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   459
	const byte *p;
2049
538e73c53f54 (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
   460
	Tile* tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	byte direction;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
	r = Random();
1384
17fe20da74ef (svn r1888) The landscape template sprites are ordinary sprites, treating them as non-sprites resulted in yet another endianess issue. This fixes the problem introduced in r1855
tron
parents: 1363
diff changeset
   464
	template = 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
   465
856
918759cedca8 (svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents: 851
diff changeset
   466
	x = r & MapMaxX();
927
94fec9843fd3 (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
   467
	y = (r >> MapLogX()) & MapMaxY();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   470
	if (x < 2 || y < 2) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
2140
a04d0142ad65 (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
   472
	direction = GB(r, 22, 2);
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   473
	if (direction & 1) {
1384
17fe20da74ef (svn r1888) The landscape template sprites are ordinary sprites, treating them as non-sprites resulted in yet another endianess issue. This fixes the problem introduced in r1855
tron
parents: 1363
diff changeset
   474
		w = template->height;
17fe20da74ef (svn r1888) The landscape template sprites are ordinary sprites, treating them as non-sprites resulted in yet another endianess issue. This fixes the problem introduced in r1855
tron
parents: 1363
diff changeset
   475
		h = template->width;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   476
	} else {
1384
17fe20da74ef (svn r1888) The landscape template sprites are ordinary sprites, treating them as non-sprites resulted in yet another endianess issue. This fixes the problem introduced in r1855
tron
parents: 1363
diff changeset
   477
		w = template->width;
17fe20da74ef (svn r1888) The landscape template sprites are ordinary sprites, treating them as non-sprites resulted in yet another endianess issue. This fixes the problem introduced in r1855
tron
parents: 1363
diff changeset
   478
		h = template->height;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   479
	}
1384
17fe20da74ef (svn r1888) The landscape template sprites are ordinary sprites, treating them as non-sprites resulted in yet another endianess issue. This fixes the problem introduced in r1855
tron
parents: 1363
diff changeset
   480
	p = template->data;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
	if (flag & 4) {
1273
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   483
		uint xw = x * MapSizeY();
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   484
		uint yw = y * MapSizeX();
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   485
		uint bias = (MapSizeX() + MapSizeY()) * 16;
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   486
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   487
		switch (flag & 3) {
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   488
			case 0:
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   489
				if (xw + yw > MapSize() - bias) return;
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   490
				break;
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   491
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   492
			case 1:
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   493
				if (yw < xw + bias) return;
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   494
				break;
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   495
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   496
			case 2:
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   497
				if (xw + yw < MapSize() + bias) return;
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   498
				break;
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   499
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   500
			case 3:
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   501
				if (xw < yw + bias) return;
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   502
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   506
	if (x + w >= MapMaxX() - 1) return;
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   507
	if (y + h >= MapMaxY() - 1) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
2049
538e73c53f54 (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
   509
	tile = &_m[TileXY(x, y)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   510
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   511
	switch (direction) {
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   512
		case 0:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
			do {
2049
538e73c53f54 (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
   514
				Tile* tile_cur = tile;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   515
				uint w_cur;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   516
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   517
				for (w_cur = w; w_cur != 0; --w_cur) {
2049
538e73c53f54 (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
   518
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   519
					p++;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   520
					tile_cur++;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   521
				}
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   522
				tile += TileDiffXY(0, 1);
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   523
			} while (--h != 0);
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   524
			break;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   525
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   526
		case 1:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
			do {
2049
538e73c53f54 (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
   528
				Tile* tile_cur = tile;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   529
				uint h_cur;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   530
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   531
				for (h_cur = h; h_cur != 0; --h_cur) {
2049
538e73c53f54 (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
   532
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   533
					p++;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   534
					tile_cur += TileDiffXY(0, 1);
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   535
				}
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   536
				tile++;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   537
			} while (--w != 0);
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   538
			break;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   539
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   540
		case 2:
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   541
			tile += TileDiffXY(w - 1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
			do {
2049
538e73c53f54 (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
   543
				Tile* tile_cur = tile;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   544
				uint w_cur;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   545
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   546
				for (w_cur = w; w_cur != 0; --w_cur) {
2049
538e73c53f54 (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
   547
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   548
					p++;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   549
					tile_cur--;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   550
				}
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   551
				tile += TileDiffXY(0, 1);
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   552
			} while (--h != 0);
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   553
			break;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   554
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   555
		case 3:
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   556
			tile += TileDiffXY(0, h - 1);
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   557
			do {
2049
538e73c53f54 (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
   558
				Tile* tile_cur = tile;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   559
				uint h_cur;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   560
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   561
				for (h_cur = h; h_cur != 0; --h_cur) {
2049
538e73c53f54 (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
   562
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   563
					p++;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   564
					tile_cur -= TileDiffXY(0, 1);
1278
952095d83a1a (svn r1782) Remove line which should've been removed in r1779 and caused map generation to hang infinitely
tron
parents: 1275
diff changeset
   565
				}
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   566
				tile++;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   567
			} while (--w != 0);
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   568
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   569
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
#include "table/genland.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   574
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   575
static void CreateDesertOrRainForest(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
{
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   577
	TileIndex tile;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   578
	TileIndex update_freq = MapSize() / 4;
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   579
	const TileIndexDiffC *data;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   580
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   582
	for (tile = 0; tile != MapSize(); ++tile) {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   583
		if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   584
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   585
		for (data = _make_desert_or_rainforest_data;
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   586
				data != endof(_make_desert_or_rainforest_data); ++data) {
1184
9792417da988 (svn r1686) Fix (Work around?) crash when generating tropical maps
tron
parents: 1181
diff changeset
   587
			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
1044
63e0601a43cc (svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents: 1035
diff changeset
   588
			if (TileHeight(t) >= 4 || IsTileType(t, MP_WATER)) break;
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   589
		}
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   590
		if (data == endof(_make_desert_or_rainforest_data))
3379
50b253bb9819 (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
   591
			SetTropicZone(tile, TROPICZONE_DESERT);
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   592
	}
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   593
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   594
	for (i = 0; i != 256; i++) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   595
		if ((i % 64) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   596
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
		RunTileLoop();
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   598
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   600
	for (tile = 0; tile != MapSize(); ++tile) {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   601
		if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   602
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   603
		for (data = _make_desert_or_rainforest_data;
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   604
				data != endof(_make_desert_or_rainforest_data); ++data) {
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   605
			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   606
			if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break;
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   607
		}
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   608
		if (data == endof(_make_desert_or_rainforest_data))
3379
50b253bb9819 (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
   609
			SetTropicZone(tile, TROPICZONE_RAINFOREST);
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   610
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   613
void GenerateLandscape(byte mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
{
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   615
	const int gwp_desert_amount = 4 + 8;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   616
	uint i;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   617
	uint flag;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
	uint32 r;
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   619
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   620
	if (mode == GW_HEIGHTMAP) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   621
		SetGeneratingWorldProgress(GWP_LANDSCAPE, (_opt.landscape == LT_DESERT) ? 1 + gwp_desert_amount : 1);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   622
		LoadHeightmap(_file_to_saveload.name);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   623
		IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   624
	} else if (_patches.land_generator == LG_TERRAGENESIS) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   625
		SetGeneratingWorldProgress(GWP_LANDSCAPE, (_opt.landscape == LT_DESERT) ? 3 + gwp_desert_amount : 3);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   626
		GenerateTerrainPerlin();
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   627
	} else {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   628
		switch (_opt.landscape) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   629
			case LT_HILLY:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   630
				SetGeneratingWorldProgress(GWP_LANDSCAPE, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   632
				for (i = ScaleByMapSize((Random() & 0x7F) + 950); i != 0; --i) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   633
					GenerateTerrain(2, 0);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   634
				}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   635
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
3017
a75caf4efa2d (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
   636
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   637
				r = Random();
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   638
				flag = GB(r, 0, 2) | 4;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   639
				for (i = ScaleByMapSize(GB(r, 16, 7) + 450); i != 0; --i) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   640
					GenerateTerrain(4, flag);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   641
				}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   642
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   643
				break;
3017
a75caf4efa2d (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
   644
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   645
			case LT_DESERT:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   646
				SetGeneratingWorldProgress(GWP_LANDSCAPE, 3 + gwp_desert_amount);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   647
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   648
				for (i = ScaleByMapSize((Random() & 0x7F) + 170); i != 0; --i) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   649
					GenerateTerrain(0, 0);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   650
				}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   651
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   652
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   653
				r = Random();
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   654
				flag = GB(r, 0, 2) | 4;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   655
				for (i = ScaleByMapSize(GB(r, 16, 8) + 1700); i != 0; --i) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   656
					GenerateTerrain(0, flag);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   657
				}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   658
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   659
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   660
				flag ^= 2;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   661
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   662
				for (i = ScaleByMapSize((Random() & 0x7F) + 410); i != 0; --i) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   663
					GenerateTerrain(3, flag);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   664
				}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   665
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   666
				break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   667
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   668
			default:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   669
				SetGeneratingWorldProgress(GWP_LANDSCAPE, 1);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   670
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   671
				i = ScaleByMapSize((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes) * 256 + 100);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   672
				for (; i != 0; --i) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   673
					GenerateTerrain(_opt.diff.terrain_type, 0);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   674
				}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   675
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   676
				break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   677
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   679
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   680
	ConvertGroundTilesIntoWaterTiles();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   681
3017
a75caf4efa2d (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
   682
	if (_opt.landscape == LT_DESERT) CreateDesertOrRainForest();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   685
void OnTick_Town(void);
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   686
void OnTick_Trees(void);
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   687
void OnTick_Station(void);
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   688
void OnTick_Industry(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   689
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   690
void OnTick_Players(void);
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   691
void OnTick_Train(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   693
void CallLandscapeTick(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   695
	OnTick_Town();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   696
	OnTick_Trees();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   697
	OnTick_Station();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   698
	OnTick_Industry();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   699
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   700
	OnTick_Players();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   701
	OnTick_Train();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   703
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   704
TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   705
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
	int rn = rng;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   707
	uint32 r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   708
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   709
	return TILE_MASK(TileXY(
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   710
		TileX(a) + (GB(r, 0, 8) * rn * 2 >> 8) - rn,
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   711
		TileY(a) + (GB(r, 8, 8) * rn * 2 >> 8) - rn
1174
6a5e747f3ba6 (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
   712
	));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   715
bool IsValidTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
{
926
a6d140a6a4de (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
   717
	return (tile < MapSizeX() * MapMaxY() && TileX(tile) != MapMaxX());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   718
}