src/landscape.cpp
author rubidium
Wed, 09 Jan 2008 09:57:48 +0000
changeset 8225 cd84a95b6630
parent 8151 4cefeef74c28
child 8230 64f28fe2d5c8
permissions -rw-r--r--
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
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"
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4990
diff changeset
     5
#include "bridge_map.h"
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
     6
#include "heightmap.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3111
diff changeset
     7
#include "clear_map.h"
2154
f86c59e73a16 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2150
diff changeset
     8
#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
     9
#include "spritecache.h"
1363
775a7ee52369 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1359
diff changeset
    10
#include "table/sprites.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include <stdarg.h>
8225
cd84a95b6630 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8151
diff changeset
    12
#include "viewport_func.h"
8116
8da76dcb3287 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8108
diff changeset
    13
#include "command_func.h"
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
    14
#include "landscape.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    15
#include "variables.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3111
diff changeset
    16
#include "void_map.h"
3111
750f37699a13 (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3078
diff changeset
    17
#include "water_map.h"
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
    18
#include "tgp.h"
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
    19
#include "genworld.h"
8119
52b48108425a (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8116
diff changeset
    20
#include "tile_cmd.h"
8130
d2eb7d04f6e1 (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8119
diff changeset
    21
#include "core/alloc_func.hpp"
8151
4cefeef74c28 (svn r11713) -Codechange: Move some declarations and definitions in a more logical disposition
belugas
parents: 8144
diff changeset
    22
#include "fios.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8130
diff changeset
    23
#include "window_func.h"
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8130
diff changeset
    24
#include "functions.h"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8139
diff changeset
    25
#include "date_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8140
diff changeset
    26
#include "vehicle_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
    28
extern const TileTypeProcs
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	_tile_type_clear_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
	_tile_type_rail_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	_tile_type_road_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	_tile_type_town_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	_tile_type_trees_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	_tile_type_station_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	_tile_type_water_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	_tile_type_dummy_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
	_tile_type_industry_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	_tile_type_tunnelbridge_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
	_tile_type_unmovable_procs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
const TileTypeProcs * const _tile_type_procs[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
	&_tile_type_clear_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
	&_tile_type_rail_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
	&_tile_type_road_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
	&_tile_type_town_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
	&_tile_type_trees_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
	&_tile_type_station_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
	&_tile_type_water_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
	&_tile_type_dummy_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	&_tile_type_industry_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
	&_tile_type_tunnelbridge_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	&_tile_type_unmovable_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
/* landscape slope => sprite */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
const byte _tileh_to_sprite[32] = {
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
    57
	0, 1, 2, 3, 4, 5, 6,  7, 8, 9, 10, 11, 12, 13, 14, 0,
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
    58
	0, 0, 0, 0, 0, 0, 0, 16, 0, 0,  0, 17,  0, 15, 18, 0,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    61
SnowLine *_snow_line = NULL;
1958
0266bb01a1e6 (svn r2464) Move definition of _inclined_tileh out of variables.h
tron
parents: 1902
diff changeset
    62
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    63
/**
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    64
 * Applys a foundation to a slope.
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    65
 *
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    66
 * @pre      Foundation and slope must be valid combined.
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    67
 * @param f  The #Foundation.
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    68
 * @param s  The #Slope to modify.
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    69
 * @return   Increment to the tile Z coordinate.
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    70
 */
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    71
uint ApplyFoundationToSlope(Foundation f, Slope *s)
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    72
{
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    73
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    74
	if (!IsFoundation(f)) return 0;
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    75
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    76
	if (IsLeveledFoundation(f)) {
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    77
		*s = SLOPE_FLAT;
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    78
		return TILE_HEIGHT;
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    79
	}
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    80
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
    81
	if (f != FOUNDATION_STEEP_BOTH && IsNonContinuousFoundation(f)) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
    82
		*s = HalftileSlope(*s, GetHalftileFoundationCorner(f));
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
    83
		return 0;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
    84
	}
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
    85
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
    86
	if (IsSpecialRailFoundation(f)) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
    87
		*s = SlopeWithThreeCornersRaised(OppositeCorner(GetRailFoundationCorner(f)));
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
    88
		return 0;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
    89
	}
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
    90
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    91
	uint dz = IsSteepSlope(*s) ? TILE_HEIGHT : 0;
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7335
diff changeset
    92
	Corner highest_corner = GetHighestSlopeCorner(*s);
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    93
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    94
	switch (f) {
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    95
		case FOUNDATION_INCLINED_X:
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7335
diff changeset
    96
			*s = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? SLOPE_SW : SLOPE_NE);
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    97
			break;
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    98
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
    99
		case FOUNDATION_INCLINED_Y:
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7335
diff changeset
   100
			*s = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? SLOPE_SE : SLOPE_NW);
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   101
			break;
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   102
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   103
		case FOUNDATION_STEEP_LOWER:
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7335
diff changeset
   104
			*s = SlopeWithOneCornerRaised(highest_corner);
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   105
			break;
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   106
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   107
		case FOUNDATION_STEEP_BOTH:
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   108
			*s = HalftileSlope(SlopeWithOneCornerRaised(highest_corner), highest_corner);
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   109
			break;
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   110
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   111
		default: NOT_REACHED();
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   112
	}
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   113
	return dz;
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   114
}
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   115
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   117
uint GetPartialZ(int x, int y, Slope corners)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
{
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   119
	if (IsHalftileSlope(corners)) {
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   120
		switch (GetHalftileSlopeCorner(corners)) {
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   121
			case CORNER_W:
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   122
				if (x - y >= 0) return GetSlopeMaxZ(corners);
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   123
				break;
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   124
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   125
			case CORNER_S:
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   126
				if (x - (y ^ 0xF) >= 0) return GetSlopeMaxZ(corners);
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   127
				break;
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   128
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   129
			case CORNER_E:
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   130
				if (y - x >= 0) return GetSlopeMaxZ(corners);
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   131
				break;
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   132
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   133
			case CORNER_N:
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   134
				if ((y ^ 0xF) - x >= 0) return GetSlopeMaxZ(corners);
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   135
				break;
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   136
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   137
			default: NOT_REACHED();
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   138
		}
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   139
	}
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   140
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
	int z = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   143
	switch (corners & ~SLOPE_HALFTILE_MASK) {
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   144
	case SLOPE_W:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
		if (x - y >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
			z = (x - y) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
		break;
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   148
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   149
	case SLOPE_S:
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   150
		y ^= 0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
		if ( (x - y) >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
			z = (x - y) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   155
	case SLOPE_SW:
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   156
		z = (x >> 1) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   159
	case SLOPE_E:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
		if (y - x >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
			z = (y - x) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   164
	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
   165
	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
   166
	case SLOPE_ELEVATED:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
		z = 4;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   170
	case SLOPE_SE:
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   171
		z = (y >> 1) + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   174
	case SLOPE_WSE:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
		z = 8;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   176
		y ^= 0xF;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
		if (x - y < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
			z += (x - y) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   181
	case SLOPE_N:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
		y ^= 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
		if (y - x >= 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
			z = (y - x) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   187
	case SLOPE_NW:
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   188
		z = (y ^ 0xF) >> 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   191
	case SLOPE_NWS:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
		z = 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
		if (x - y < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
			z += (x - y) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   197
	case SLOPE_NE:
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   198
		z = (x ^ 0xF) >> 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   201
	case SLOPE_ENW:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
		z = 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
		y ^= 0xF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
		if (y - x < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
			z += (y - x) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   208
	case SLOPE_SEN:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
		z = 8;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
		if (y - x < 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
			z += (y - x) >> 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   214
	case SLOPE_STEEP_S:
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   215
		z = 1 + ((x + y) >> 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   216
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   217
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   218
	case SLOPE_STEEP_W:
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   219
		z = 1 + ((x + (y ^ 0xF)) >> 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
		break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   222
	case SLOPE_STEEP_N:
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   223
		z = 1 + (((x ^ 0xF) + (y ^ 0xF)) >> 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
		break;
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   225
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   226
	case SLOPE_STEEP_E:
7304
173699789cc3 (svn r10656) -Fix [FS#1068]: GetPartialZ returned wrong value for SLOPE_STEEP_E (frosch)
truelight
parents: 7043
diff changeset
   227
		z = 1 + (((x ^ 0xF) + y) >> 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
		break;
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   229
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   230
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
	return z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   236
uint GetSlopeZ(int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
   238
	TileIndex tile = TileVirtXY(x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
   240
	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
   241
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
7728
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   243
/**
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   244
 * Determine the Z height of a corner relative to TileZ.
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   245
 *
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   246
 * @pre The slope must not be a halftile slope.
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   247
 *
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   248
 * @param tileh The slope.
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   249
 * @param corner The corner.
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   250
 * @return Z position of corner relative to TileZ.
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   251
 */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   252
int GetSlopeZInCorner(Slope tileh, Corner corner)
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   253
{
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   254
	assert(!IsHalftileSlope(tileh));
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   255
	static const int _corner_slopes[4][2] = {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   256
		{ SLOPE_W, SLOPE_STEEP_W }, { SLOPE_S, SLOPE_STEEP_S }, { SLOPE_E, SLOPE_STEEP_E }, { SLOPE_N, SLOPE_STEEP_N }
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   257
	};
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   258
	return ((tileh & _corner_slopes[corner][0]) != 0 ? TILE_HEIGHT : 0) + (tileh == _corner_slopes[corner][1] ? TILE_HEIGHT : 0);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   259
}
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   260
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   261
/**
7728
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   262
 * Determine the Z height of the corners of a specific tile edge
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   263
 *
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   264
 * @note If a tile has a non-continuous halftile foundation, a corner can have different heights wrt. it's edges.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   265
 *
7728
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   266
 * @pre z1 and z2 must be initialized (typ. with TileZ). The corner heights just get added.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   267
 *
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   268
 * @param tileh The slope of the tile.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   269
 * @param edge The edge of interest.
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   270
 * @param z1 Gets incremented by the height of the first corner of the edge. (near corner wrt. the camera)
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   271
 * @param z2 Gets incremented by the height of the second corner of the edge. (far corner wrt. the camera)
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   272
 */
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   273
void GetSlopeZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2)
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   274
{
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   275
	static const Slope corners[4][4] = {
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   276
		/*    corner     |          steep slope
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   277
		 *  z1      z2   |       z1             z2        */
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   278
		{SLOPE_E, SLOPE_N, SLOPE_STEEP_E, SLOPE_STEEP_N}, // DIAGDIR_NE, z1 = E, z2 = N
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   279
		{SLOPE_S, SLOPE_E, SLOPE_STEEP_S, SLOPE_STEEP_E}, // DIAGDIR_SE, z1 = S, z2 = E
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   280
		{SLOPE_S, SLOPE_W, SLOPE_STEEP_S, SLOPE_STEEP_W}, // DIAGDIR_SW, z1 = S, z2 = W
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   281
		{SLOPE_W, SLOPE_N, SLOPE_STEEP_W, SLOPE_STEEP_N}, // DIAGDIR_NW, z1 = W, z2 = N
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   282
	};
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   283
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   284
	int halftile_test = (IsHalftileSlope(tileh) ? SlopeWithOneCornerRaised(GetHalftileSlopeCorner(tileh)) : 0);
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   285
	if (halftile_test == corners[edge][0]) *z2 += TILE_HEIGHT; // The slope is non-continuous in z2. z2 is on the upper side.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   286
	if (halftile_test == corners[edge][1]) *z1 += TILE_HEIGHT; // The slope is non-continuous in z1. z1 is on the upper side.
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   287
7728
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   288
	if ((tileh & corners[edge][0]) != 0) *z1 += TILE_HEIGHT; // z1 is raised
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   289
	if ((tileh & corners[edge][1]) != 0) *z2 += TILE_HEIGHT; // z2 is raised
7764
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   290
	if ((tileh & ~SLOPE_HALFTILE_MASK) == corners[edge][2]) *z1 += TILE_HEIGHT; // z1 is highest corner of a steep slope
e594296e90f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 7728
diff changeset
   291
	if ((tileh & ~SLOPE_HALFTILE_MASK) == corners[edge][3]) *z2 += TILE_HEIGHT; // z2 is highest corner of a steep slope
7728
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   292
}
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
   293
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   294
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
   295
{
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
   296
	Slope tileh = GetTileSlope(tile, z);
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   297
	Foundation f = _tile_type_procs[GetTileType(tile)]->get_foundation_proc(tile, tileh);
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   298
	*z += ApplyFoundationToSlope(f, &tileh);
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   299
	return tileh;
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
   300
}
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 37
diff changeset
   301
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
   302
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   303
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
   304
{
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   305
	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
   306
7728
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   307
	int z_W_here = z_here;
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   308
	int z_N_here = z_here;
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   309
	GetSlopeZOnEdge(slope_here, DIAGDIR_NW, &z_W_here, &z_N_here);
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   310
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   311
	Slope slope = GetFoundationSlope(TILE_ADDXY(tile, 0, -1), &z);
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   312
	int z_W = z;
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   313
	int z_N = z;
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   314
	GetSlopeZOnEdge(slope, DIAGDIR_SE, &z_W, &z_N);
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   315
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   316
	return (z_N_here > z_N) || (z_W_here > z_W);
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
   317
}
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
   318
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
   319
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   320
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
   321
{
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   322
	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
   323
7728
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   324
	int z_E_here = z_here;
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   325
	int z_N_here = z_here;
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   326
	GetSlopeZOnEdge(slope_here, DIAGDIR_NE, &z_E_here, &z_N_here);
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   327
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   328
	Slope slope = GetFoundationSlope(TILE_ADDXY(tile, -1, 0), &z);
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   329
	int z_E = z;
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   330
	int z_N = z;
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   331
	GetSlopeZOnEdge(slope, DIAGDIR_SW, &z_E, &z_N);
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   332
68e794385dc9 (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 7678
diff changeset
   333
	return (z_N_here > z_N) || (z_E_here > z_E);
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
   334
}
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   335
b90ec503a589 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   336
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   337
void DrawFoundation(TileInfo *ti, Foundation f)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
{
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   339
	if (!IsFoundation(f)) return;
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   340
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   341
	/* Two part foundations must be drawn separately */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   342
	assert(f != FOUNDATION_STEEP_BOTH);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   343
7767
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   344
	uint sprite_block = 0;
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
   345
	uint z;
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   346
	Slope slope = GetFoundationSlope(ti->tile, &z);
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 37
diff changeset
   347
7767
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   348
	/* Select the needed block of foundations sprites
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   349
	 * Block 0: Walls at NW and NE edge
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   350
	 * Block 1: Wall  at        NE edge
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   351
	 * Block 2: Wall  at NW        edge
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   352
	 * Block 3: No walls at NW or NE edge
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   353
	 */
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   354
	if (!HasFoundationNW(ti->tile, slope, z)) sprite_block += 1;
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   355
	if (!HasFoundationNE(ti->tile, slope, z)) sprite_block += 2;
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   356
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   357
	/* Use the original slope sprites if NW and NE borders should be visible */
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   358
	SpriteID leveled_base = (sprite_block == 0 ? (int)SPR_FOUNDATION_BASE : (SPR_SLOPES_VIRTUAL_BASE + sprite_block * SPR_TRKFOUND_BLOCK_SIZE));
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   359
	SpriteID inclined_base = SPR_SLOPES_VIRTUAL_BASE + SPR_SLOPES_INCLINED_OFFSET + sprite_block * SPR_TRKFOUND_BLOCK_SIZE;
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   360
	SpriteID halftile_base = SPR_HALFTILE_FOUNDATION_BASE + sprite_block * SPR_HALFTILE_BLOCK_SIZE;
37
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
   361
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   362
	if (IsSteepSlope(ti->tileh)) {
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   363
		if (!IsNonContinuousFoundation(f)) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   364
			/* Lower part of foundation */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   365
			AddSortableSpriteToDraw(
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   366
				leveled_base + (ti->tileh & ~SLOPE_STEEP), PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   367
			);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   368
		}
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   369
7678
8917067dde87 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7335
diff changeset
   370
		Corner highest_corner = GetHighestSlopeCorner(ti->tileh);
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   371
		ti->z += ApplyFoundationToSlope(f, &ti->tileh);
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   372
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   373
		if (IsInclinedFoundation(f)) {
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   374
			/* inclined foundation */
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   375
			byte inclined = highest_corner * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   376
7767
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   377
			AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y, 16, 16, 1, ti->z);
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   378
			OffsetGroundSprite(31, 9);
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   379
		} else if (f == FOUNDATION_STEEP_LOWER) {
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6106
diff changeset
   380
			/* one corner raised */
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   381
			OffsetGroundSprite(31, 1);
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   382
		} else {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   383
			/* halftile foundation */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   384
			int x_bb = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? 8 : 0);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   385
			int y_bb = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? 8 : 0);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   386
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   387
			AddSortableSpriteToDraw(halftile_base + highest_corner, PAL_NONE, ti->x + x_bb, ti->y + y_bb, 8, 8, 7, ti->z + TILE_HEIGHT);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   388
			OffsetGroundSprite(31, 9);
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   389
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
	} else {
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   391
		if (IsLeveledFoundation(f)) {
7767
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   392
			/* leveled foundation */
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   393
			AddSortableSpriteToDraw(leveled_base + ti->tileh, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   394
			OffsetGroundSprite(31, 1);
7770
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   395
		} else if (IsNonContinuousFoundation(f)) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   396
			/* halftile foundation */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   397
			Corner halftile_corner = GetHalftileFoundationCorner(f);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   398
			int x_bb = (((halftile_corner == CORNER_W) || (halftile_corner == CORNER_S)) ? 8 : 0);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   399
			int y_bb = (((halftile_corner == CORNER_S) || (halftile_corner == CORNER_E)) ? 8 : 0);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   400
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   401
			AddSortableSpriteToDraw(halftile_base + halftile_corner, PAL_NONE, ti->x + x_bb, ti->y + y_bb, 8, 8, 7, ti->z);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   402
			OffsetGroundSprite(31, 9);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   403
		} else if (IsSpecialRailFoundation(f)) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   404
			/* anti-zig-zag foundation */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   405
			SpriteID spr;
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   406
			if (ti->tileh == SLOPE_NS || ti->tileh == SLOPE_EW) {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   407
				/* half of leveled foundation under track corner */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   408
				spr = leveled_base + SlopeWithThreeCornersRaised(GetRailFoundationCorner(f));
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   409
			} else {
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   410
				/* tile-slope = sloped along X/Y, foundation-slope = three corners raised */
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   411
				spr = inclined_base + 2 * GetRailFoundationCorner(f) + ((ti->tileh == SLOPE_SW || ti->tileh == SLOPE_NE) ? 1 : 0);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   412
			}
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   413
			AddSortableSpriteToDraw(spr, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
320d260ff1a1 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 7767
diff changeset
   414
			OffsetGroundSprite(31, 9);
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   415
		} else {
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6106
diff changeset
   416
			/* inclined foundation */
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   417
			byte inclined = GetHighestSlopeCorner(ti->tileh) * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   418
7767
9866e9700e62 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 7764
diff changeset
   419
			AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y, 16, 16, 1, ti->z);
4253
b468db807b66 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   420
			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
   421
		}
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7304
diff changeset
   422
		ti->z += ApplyFoundationToSlope(f, &ti->tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   426
void DoClearSquare(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
{
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   428
	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
   429
	MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6491
diff changeset
   432
uint32 GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   433
{
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6491
diff changeset
   434
	return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode, sub_mode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   437
void ChangeTileOwner(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   439
	_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
   440
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   442
void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
	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
   445
	_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
   446
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   448
void AnimateTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   450
	_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
   451
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   453
void ClickTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   455
	_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
   456
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   458
void GetTileDesc(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
{
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   460
	_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
   461
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   463
/**
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   464
 * Has a snow line table already been loaded.
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   465
 * @return true if the table has been loaded already.
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   466
 */
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   467
bool IsSnowLineSet(void)
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   468
{
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   469
	return _snow_line != NULL;
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   470
}
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   471
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   472
/**
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   473
 * Set a variable snow line, as loaded from a newgrf file.
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   474
 * @param table the 12 * 32 byte table containing the snowline for each day
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   475
 */
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   476
void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   477
{
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   478
	_snow_line = CallocT<SnowLine>(1);
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   479
	memcpy(_snow_line->table, table, sizeof(_snow_line->table));
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   480
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   481
	for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   482
		for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   483
			_snow_line->highest_value = max(_snow_line->highest_value, table[i][j]);
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   484
		}
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   485
	}
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   486
}
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   487
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   488
/**
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   489
 * Get the current snow line, either variable or static.
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   490
 * @return the snow line height.
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   491
 */
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   492
byte GetSnowLine(void)
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   493
{
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   494
	if (_snow_line == NULL) return _opt.snow_line;
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   495
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   496
	YearMonthDay ymd;
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   497
	ConvertDateToYMD(_date, &ymd);
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   498
	return _snow_line->table[ymd.month][ymd.day];
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   499
}
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   500
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   501
/**
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   502
 * Get the highest possible snow line height, either variable or static.
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   503
 * @return the highest snow line height.
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   504
 */
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   505
byte HighestSnowLine(void)
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   506
{
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   507
	return _snow_line == NULL ? _opt.snow_line : _snow_line->highest_value;
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   508
}
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   509
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   510
/**
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   511
 * Clear the variable snow line table and free the memory.
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   512
 */
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   513
void ClearSnowLine(void)
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   514
{
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   515
	free(_snow_line);
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   516
	_snow_line = NULL;
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   517
}
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6247
diff changeset
   518
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
   519
/** 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
   520
 * @param tile tile to clear
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6106
diff changeset
   521
 * @param flags of operation to conduct
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
   522
 * @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
   523
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6683
diff changeset
   525
CommandCost CmdLandscapeClear(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   527
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
1214
8262981ac274 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   529
	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
   530
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   532
/** 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
   533
 * @param tile end tile of area dragging
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   534
 * @param p1 start tile of area dragging
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6106
diff changeset
   535
 * @param flags of operation to conduct
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   536
 * @param p2 unused
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   537
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6683
diff changeset
   538
CommandCost CmdClearArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   539
{
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6683
diff changeset
   540
	CommandCost 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
   541
	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
   542
	int ey;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   543
	int sx, sy;
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   544
	int x, y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
	bool success = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
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
   547
	if (p1 >= MapSize()) return CMD_ERROR;
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   548
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
   549
	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
   550
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6106
diff changeset
   551
	/* 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
   552
	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
   553
	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
   554
	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
   555
	sy = TileY(p1);
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 5668
diff changeset
   556
	if (ex < sx) Swap(ex, sx);
2898cd9417fd (svn r8841) -Fix
tron
parents: 5668
diff changeset
   557
	if (ey < sy) Swap(ey, sy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   559
	money.AddCost(GetAvailableMoneyForCommand());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   560
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   561
	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
   562
		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
   563
			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
   564
			if (CmdFailed(ret)) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   565
			success = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   566
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   567
			if (flags & DC_EXEC) {
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   568
				money.AddCost(-ret.GetCost());
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   569
				if (ret.GetCost() > 0 && money.GetCost() < 0) {
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   570
					_additional_cash_required = ret.GetCost();
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   571
					return cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
				}
3493
c77bcf04294d (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   573
				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
   574
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6106
diff changeset
   575
				/* draw explosion animation... */
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   576
				if ((x == sx || x == ex) && (y == sy || y == ey)) {
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6106
diff changeset
   577
					/* 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
   578
					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
   579
						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
   580
					);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
			}
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   583
			cost.AddCost(ret);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
1793
b9a37c98b468 (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   587
	return (success) ? cost : CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
#define TILELOOP_BITS 4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
#define TILELOOP_SIZE (1 << TILELOOP_BITS)
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   593
#define TILELOOP_ASSERTMASK ((TILELOOP_SIZE - 1) + ((TILELOOP_SIZE - 1) << MapLogX()))
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
   594
#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
   595
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   596
void RunTileLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
{
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   598
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
	uint count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	tile = _cur_tileloop_tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
	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
   604
	count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
	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
   606
		_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
   607
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
   608
		if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
6201
bee01dc45e39 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6106
diff changeset
   609
			tile += TILELOOP_SIZE; // no overflow
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
		} else {
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   611
			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
   612
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
	} while (--count);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
	assert( (tile & ~TILELOOP_ASSERTMASK) == 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
	tile += 9;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
	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
   618
		tile = (tile + MapSizeX()) & TILELOOP_ASSERTMASK;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
	_cur_tileloop_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   622
void InitializeLandscape()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
{
3078
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   624
	uint maxx = MapMaxX();
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   625
	uint maxy = MapMaxY();
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   626
	uint sizex = MapSizeX();
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   627
	uint x;
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   628
	uint y;
1218
c6a624956ac6 (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1214
diff changeset
   629
3078
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   630
	for (y = 0; y < maxy; y++) {
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   631
		for (x = 0; x < maxx; x++) {
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   632
			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
   633
			SetTileHeight(sizex * y + x, 0);
5596
5bf7128140a0 (svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents: 5587
diff changeset
   634
			SetTropicZone(sizex * y + x, TROPICZONE_INVALID);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4990
diff changeset
   635
			ClearBridgeMiddle(sizex * y + x);
3078
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   636
		}
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   637
		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
   638
	}
3078
cfce0beffa16 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   639
	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
   640
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   642
void ConvertGroundTilesIntoWaterTiles()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
{
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
   644
	TileIndex tile;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   645
	uint z;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   646
	Slope slope;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   648
	for (tile = 0; tile < MapSize(); ++tile) {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   649
		slope = GetTileSlope(tile, &z);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   650
		if (IsTileType(tile, MP_CLEAR) && z == 0) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   651
			/* 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
   652
			 * 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
   653
			 * during the generation. */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   654
			switch (slope) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   655
				case SLOPE_FLAT:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   656
					MakeWater(tile);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   657
					break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   658
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   659
				case SLOPE_N:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   660
				case SLOPE_E:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   661
				case SLOPE_S:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   662
				case SLOPE_W:
7887
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   663
					MakeShore(tile);
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   664
					break;
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   665
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   666
				case SLOPE_NW:
7887
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   667
					if (GetTileSlope(TileAddByDiagDir(tile, DIAGDIR_SE), NULL) != SLOPE_SE) MakeShore(tile);
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   668
					break;
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   669
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   670
				case SLOPE_SW:
7887
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   671
					if (GetTileSlope(TileAddByDiagDir(tile, DIAGDIR_NE), NULL) != SLOPE_NE) MakeShore(tile);
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   672
					break;
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   673
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   674
				case SLOPE_SE:
7887
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   675
					if (GetTileSlope(TileAddByDiagDir(tile, DIAGDIR_NW), NULL) != SLOPE_NW) MakeShore(tile);
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   676
					break;
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   677
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   678
				case SLOPE_NE:
7887
b72ef3f45a38 (svn r11438) -Change: do not create shores in canyons. Based on a patch by LeviathNL.
rubidium
parents: 7770
diff changeset
   679
					if (GetTileSlope(TileAddByDiagDir(tile, DIAGDIR_SW), NULL) != SLOPE_SW) MakeShore(tile);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   680
					break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   681
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   682
				default:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   683
					break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   684
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   686
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   687
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
4344
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   689
static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4  };
7e123fec5b0b (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   690
static const byte _genterrain_tbl_2[5] = {  0,  0,  0,  0, 33 };
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   691
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   692
static void GenerateTerrain(int type, int flag)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   693
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   694
	uint32 r;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   695
	uint x;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   696
	uint y;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   697
	uint w;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   698
	uint h;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   699
	const Sprite* templ;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   700
	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
   701
	Tile* tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   702
	byte direction;
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
	r = Random();
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   705
	templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   706
856
918759cedca8 (svn r1337) Use MapMax[XY]() (or MapSize[XY]() if appropriate) instead of TILE_MAX_[XY]
tron
parents: 851
diff changeset
   707
	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
   708
	y = (r >> MapLogX()) & MapMaxY();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   710
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   711
	if (x < 2 || y < 2) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
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
   713
	direction = GB(r, 22, 2);
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   714
	if (direction & 1) {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   715
		w = templ->height;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   716
		h = templ->width;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   717
	} else {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   718
		w = templ->width;
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   719
		h = templ->height;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   720
	}
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   721
	p = templ->data;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
	if (flag & 4) {
1273
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   724
		uint xw = x * MapSizeY();
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   725
		uint yw = y * MapSizeX();
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   726
		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
   727
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   728
		switch (flag & 3) {
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   729
			case 0:
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   730
				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
   731
				break;
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   732
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   733
			case 1:
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   734
				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
   735
				break;
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   736
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   737
			case 2:
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   738
				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
   739
				break;
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   740
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   741
			case 3:
e4849a568647 (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   742
				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
   743
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   745
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   747
	if (x + w >= MapMaxX() - 1) return;
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   748
	if (y + h >= MapMaxY() - 1) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
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
   750
	tile = &_m[TileXY(x, y)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   752
	switch (direction) {
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   753
		case 0:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
			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
   755
				Tile* tile_cur = tile;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   756
				uint w_cur;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   757
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   758
				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
   759
					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
   760
					p++;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   761
					tile_cur++;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   762
				}
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   763
				tile += TileDiffXY(0, 1);
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   764
			} while (--h != 0);
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   765
			break;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   766
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   767
		case 1:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
			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
   769
				Tile* tile_cur = tile;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   770
				uint h_cur;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   771
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   772
				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
   773
					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
   774
					p++;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   775
					tile_cur += TileDiffXY(0, 1);
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   776
				}
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   777
				tile++;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   778
			} while (--w != 0);
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   779
			break;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   780
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   781
		case 2:
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   782
			tile += TileDiffXY(w - 1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
			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
   784
				Tile* tile_cur = tile;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   785
				uint w_cur;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   786
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   787
				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
   788
					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
   789
					p++;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   790
					tile_cur--;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   791
				}
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   792
				tile += TileDiffXY(0, 1);
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   793
			} while (--h != 0);
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   794
			break;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   795
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   796
		case 3:
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   797
			tile += TileDiffXY(0, h - 1);
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   798
			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
   799
				Tile* tile_cur = tile;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   800
				uint h_cur;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   801
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   802
				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
   803
					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
   804
					p++;
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   805
					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
   806
				}
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   807
				tile++;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   808
			} while (--w != 0);
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   809
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   810
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   811
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   812
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   814
#include "table/genland.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   815
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   816
static void CreateDesertOrRainForest()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
{
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   818
	TileIndex tile;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   819
	TileIndex update_freq = MapSize() / 4;
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   820
	const TileIndexDiffC *data;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   821
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   823
	for (tile = 0; tile != MapSize(); ++tile) {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   824
		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
   825
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   826
		for (data = _make_desert_or_rainforest_data;
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   827
				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
   828
			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
   829
			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
   830
		}
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   831
		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
   832
			SetTropicZone(tile, TROPICZONE_DESERT);
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   833
	}
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   834
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   835
	for (i = 0; i != 256; i++) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   836
		if ((i % 64) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   837
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   838
		RunTileLoop();
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   839
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   841
	for (tile = 0; tile != MapSize(); ++tile) {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   842
		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
   843
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   844
		for (data = _make_desert_or_rainforest_data;
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   845
				data != endof(_make_desert_or_rainforest_data); ++data) {
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   846
			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   847
			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
   848
		}
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   849
		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
   850
			SetTropicZone(tile, TROPICZONE_RAINFOREST);
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   851
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   854
void GenerateLandscape(byte mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   855
{
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   856
	const int gwp_desert_amount = 4 + 8;
1275
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   857
	uint i;
5d1b5fe31c78 (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   858
	uint flag;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   859
	uint32 r;
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   860
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   861
	if (mode == GW_HEIGHTMAP) {
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
   862
		SetGeneratingWorldProgress(GWP_LANDSCAPE, (_opt.landscape == LT_TROPIC) ? 1 + gwp_desert_amount : 1);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   863
		LoadHeightmap(_file_to_saveload.name);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   864
		IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   865
	} else if (_patches.land_generator == LG_TERRAGENESIS) {
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
   866
		SetGeneratingWorldProgress(GWP_LANDSCAPE, (_opt.landscape == LT_TROPIC) ? 3 + gwp_desert_amount : 3);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   867
		GenerateTerrainPerlin();
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   868
	} else {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   869
		switch (_opt.landscape) {
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
   870
			case LT_ARCTIC:
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   871
				SetGeneratingWorldProgress(GWP_LANDSCAPE, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   872
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   873
				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
   874
					GenerateTerrain(2, 0);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   875
				}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   876
				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
   877
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   878
				r = Random();
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   879
				flag = GB(r, 0, 2) | 4;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   880
				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
   881
					GenerateTerrain(4, flag);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   882
				}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   883
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   884
				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
   885
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
   886
			case LT_TROPIC:
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   887
				SetGeneratingWorldProgress(GWP_LANDSCAPE, 3 + gwp_desert_amount);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   888
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   889
				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
   890
					GenerateTerrain(0, 0);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   891
				}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   892
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   893
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   894
				r = Random();
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   895
				flag = GB(r, 0, 2) | 4;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   896
				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
   897
					GenerateTerrain(0, flag);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   898
				}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   899
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   900
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   901
				flag ^= 2;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   902
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   903
				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
   904
					GenerateTerrain(3, flag);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   905
				}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   906
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   907
				break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   908
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   909
			default:
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   910
				SetGeneratingWorldProgress(GWP_LANDSCAPE, 1);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   911
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   912
				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
   913
				for (; i != 0; --i) {
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   914
					GenerateTerrain(_opt.diff.terrain_type, 0);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   915
				}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   916
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   917
				break;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   918
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   920
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
	ConvertGroundTilesIntoWaterTiles();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
   923
	if (_opt.landscape == LT_TROPIC) CreateDesertOrRainForest();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   926
void OnTick_Town();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   927
void OnTick_Trees();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   928
void OnTick_Station();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   929
void OnTick_Industry();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   930
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   931
void OnTick_Players();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   932
void OnTick_Train();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6201
diff changeset
   934
void CallLandscapeTick()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   935
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   936
	OnTick_Town();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
	OnTick_Trees();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   938
	OnTick_Station();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	OnTick_Industry();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   941
	OnTick_Players();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   942
	OnTick_Train();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   943
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
	int rn = rng;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
	uint32 r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   950
	return TILE_MASK(TileXY(
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   951
		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
   952
		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
   953
	));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
1589
bac29165710f (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   956
bool IsValidTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   957
{
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
   958
	return (tile < MapSizeX() * MapMaxY() && TileX(tile) != MapMaxX());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
}