src/landscape.cpp
author frosch
Thu, 12 Jun 2008 21:36:56 +0000
changeset 10945 b53a857888b8
parent 10775 7061477bfbcf
permissions -rw-r--r--
(svn r13499) -Codechange: Allow drawing (ugly) leveled foundations on steep slopes, just in case someone needs them for fallback.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10429
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10272
diff changeset
     3
/** @file landscape.cpp Functions related to the landscape (slopes etc.). */
1b99254f9607 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 10272
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1793
diff changeset
     6
#include "openttd.h"
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4990
diff changeset
     7
#include "bridge_map.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
     8
#include "heightmap.h"
3144
426b825578f9 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 3111
diff changeset
     9
#include "clear_map.h"
1349
07514c2cc6d1 (svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents: 1335
diff changeset
    10
#include "spritecache.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include <stdarg.h>
8721
b7971ad9bdd9 (svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents: 8647
diff changeset
    12
#include "viewport_func.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8604
diff changeset
    13
#include "command_func.h"
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
    14
#include "landscape.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    15
#include "variables.h"
3144
426b825578f9 (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
1edf71aa942e (svn r3714) Add functions to turn tiles into water and shore tiles
tron
parents: 3078
diff changeset
    17
#include "water_map.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
    18
#include "tgp.h"
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
    19
#include "genworld.h"
8615
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8612
diff changeset
    20
#include "tile_cmd.h"
8626
440dfcd14c4a (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8615
diff changeset
    21
#include "core/alloc_func.hpp"
8647
0709611186e0 (svn r11713) -Codechange: Move some declarations and definitions in a more logical disposition
belugas
parents: 8640
diff changeset
    22
#include "fios.h"
8627
448ebf3a8291 (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: 8626
diff changeset
    23
#include "window_func.h"
448ebf3a8291 (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: 8626
diff changeset
    24
#include "functions.h"
8636
2b158acb649c (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8635
diff changeset
    25
#include "date_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8636
diff changeset
    26
#include "vehicle_func.h"
8766
c86cfa3a7580 (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8760
diff changeset
    27
#include "settings_type.h"
8876
a0b7938c6082 (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8766
diff changeset
    28
#include "water.h"
10272
2014f0bdc800 (svn r12804) -Codechange: move the effect vehicle handling out of vehicle.cpp
rubidium
parents: 10233
diff changeset
    29
#include "effectvehicle_func.h"
10444
3876060cdef7 (svn r12986) -Codechange: move the landscape and transport related types from openttd.h to their own headers.
rubidium
parents: 10429
diff changeset
    30
#include "landscape_type.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    32
#include "table/sprites.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8750
diff changeset
    33
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
    34
extern const TileTypeProcs
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	_tile_type_clear_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	_tile_type_rail_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
	_tile_type_road_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	_tile_type_town_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
	_tile_type_trees_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
	_tile_type_station_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
	_tile_type_water_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
	_tile_type_dummy_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
	_tile_type_industry_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
	_tile_type_tunnelbridge_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
	_tile_type_unmovable_procs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
const TileTypeProcs * const _tile_type_procs[16] = {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
	&_tile_type_clear_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
	&_tile_type_rail_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	&_tile_type_road_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
	&_tile_type_town_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	&_tile_type_trees_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	&_tile_type_station_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
	&_tile_type_water_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
	&_tile_type_dummy_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
	&_tile_type_industry_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    57
	&_tile_type_tunnelbridge_procs,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
	&_tile_type_unmovable_procs,
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
/* landscape slope => sprite */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    62
const byte _tileh_to_sprite[32] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
    63
	0, 1, 2, 3, 4, 5, 6,  7, 8, 9, 10, 11, 12, 13, 14, 0,
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
    64
	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
    65
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
7831
5dded9b03500 (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: 7800
diff changeset
    67
SnowLine *_snow_line = NULL;
1958
625d71cd6898 (svn r2464) Move definition of _inclined_tileh out of variables.h
tron
parents: 1902
diff changeset
    68
7831
5dded9b03500 (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: 7800
diff changeset
    69
/**
5dded9b03500 (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: 7800
diff changeset
    70
 * Applys a foundation to a slope.
5dded9b03500 (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: 7800
diff changeset
    71
 *
5dded9b03500 (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: 7800
diff changeset
    72
 * @pre      Foundation and slope must be valid combined.
5dded9b03500 (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: 7800
diff changeset
    73
 * @param f  The #Foundation.
5dded9b03500 (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: 7800
diff changeset
    74
 * @param s  The #Slope to modify.
5dded9b03500 (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: 7800
diff changeset
    75
 * @return   Increment to the tile Z coordinate.
5dded9b03500 (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: 7800
diff changeset
    76
 */
5dded9b03500 (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: 7800
diff changeset
    77
uint ApplyFoundationToSlope(Foundation f, Slope *s)
5dded9b03500 (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: 7800
diff changeset
    78
{
5dded9b03500 (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: 7800
diff changeset
    79
	if (!IsFoundation(f)) return 0;
5dded9b03500 (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: 7800
diff changeset
    80
5dded9b03500 (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: 7800
diff changeset
    81
	if (IsLeveledFoundation(f)) {
10945
b53a857888b8 (svn r13499) -Codechange: Allow drawing (ugly) leveled foundations on steep slopes, just in case someone needs them for fallback.
frosch
parents: 10775
diff changeset
    82
		uint dz = TILE_HEIGHT + (IsSteepSlope(*s) ? TILE_HEIGHT : 0);
7831
5dded9b03500 (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: 7800
diff changeset
    83
		*s = SLOPE_FLAT;
10945
b53a857888b8 (svn r13499) -Codechange: Allow drawing (ugly) leveled foundations on steep slopes, just in case someone needs them for fallback.
frosch
parents: 10775
diff changeset
    84
		return dz;
7831
5dded9b03500 (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: 7800
diff changeset
    85
	}
5dded9b03500 (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: 7800
diff changeset
    86
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
    87
	if (f != FOUNDATION_STEEP_BOTH && IsNonContinuousFoundation(f)) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
    88
		*s = HalftileSlope(*s, GetHalftileFoundationCorner(f));
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
    89
		return 0;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
    90
	}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
    91
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
    92
	if (IsSpecialRailFoundation(f)) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
    93
		*s = SlopeWithThreeCornersRaised(OppositeCorner(GetRailFoundationCorner(f)));
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
    94
		return 0;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
    95
	}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
    96
7831
5dded9b03500 (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: 7800
diff changeset
    97
	uint dz = IsSteepSlope(*s) ? TILE_HEIGHT : 0;
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7831
diff changeset
    98
	Corner highest_corner = GetHighestSlopeCorner(*s);
7831
5dded9b03500 (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: 7800
diff changeset
    99
5dded9b03500 (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: 7800
diff changeset
   100
	switch (f) {
5dded9b03500 (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: 7800
diff changeset
   101
		case FOUNDATION_INCLINED_X:
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7831
diff changeset
   102
			*s = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? SLOPE_SW : SLOPE_NE);
7831
5dded9b03500 (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: 7800
diff changeset
   103
			break;
5dded9b03500 (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: 7800
diff changeset
   104
5dded9b03500 (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: 7800
diff changeset
   105
		case FOUNDATION_INCLINED_Y:
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7831
diff changeset
   106
			*s = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? SLOPE_SE : SLOPE_NW);
7831
5dded9b03500 (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: 7800
diff changeset
   107
			break;
5dded9b03500 (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: 7800
diff changeset
   108
5dded9b03500 (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: 7800
diff changeset
   109
		case FOUNDATION_STEEP_LOWER:
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7831
diff changeset
   110
			*s = SlopeWithOneCornerRaised(highest_corner);
7831
5dded9b03500 (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: 7800
diff changeset
   111
			break;
5dded9b03500 (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: 7800
diff changeset
   112
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   113
		case FOUNDATION_STEEP_BOTH:
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   114
			*s = HalftileSlope(SlopeWithOneCornerRaised(highest_corner), highest_corner);
7831
5dded9b03500 (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: 7800
diff changeset
   115
			break;
5dded9b03500 (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: 7800
diff changeset
   116
5dded9b03500 (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: 7800
diff changeset
   117
		default: NOT_REACHED();
5dded9b03500 (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: 7800
diff changeset
   118
	}
5dded9b03500 (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: 7800
diff changeset
   119
	return dz;
5dded9b03500 (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: 7800
diff changeset
   120
}
5dded9b03500 (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: 7800
diff changeset
   121
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   123
/**
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   124
 * Determines height at given coordinate of a slope
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   125
 * @param x x coordinate
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   126
 * @param y y coordinate
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   127
 * @param corners slope to examine
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   128
 * @return height of given point of given slope
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   129
 */
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   130
uint GetPartialZ(int x, int y, Slope corners)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
{
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   132
	if (IsHalftileSlope(corners)) {
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   133
		switch (GetHalftileSlopeCorner(corners)) {
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   134
			case CORNER_W:
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   135
				if (x - y >= 0) return GetSlopeMaxZ(corners);
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   136
				break;
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   137
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   138
			case CORNER_S:
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   139
				if (x - (y ^ 0xF) >= 0) return GetSlopeMaxZ(corners);
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   140
				break;
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   141
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   142
			case CORNER_E:
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   143
				if (y - x >= 0) return GetSlopeMaxZ(corners);
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   144
				break;
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   145
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   146
			case CORNER_N:
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   147
				if ((y ^ 0xF) - x >= 0) return GetSlopeMaxZ(corners);
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   148
				break;
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   149
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   150
			default: NOT_REACHED();
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   151
		}
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   152
	}
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   153
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
	int z = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8876
diff changeset
   156
	switch (RemoveHalftileSlope(corners)) {
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   157
		case SLOPE_W:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   158
			if (x - y >= 0) {
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   159
				z = (x - y) >> 1;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   160
			}
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   161
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   163
		case SLOPE_S:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   164
			y ^= 0xF;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   165
			if ((x - y) >= 0) {
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   166
				z = (x - y) >> 1;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   167
			}
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   168
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   170
		case SLOPE_SW:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   171
			z = (x >> 1) + 1;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   172
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   174
		case SLOPE_E:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   175
			if (y - x >= 0) {
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   176
				z = (y - x) >> 1;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   177
			}
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   178
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   180
		case SLOPE_EW:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   181
		case SLOPE_NS:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   182
		case SLOPE_ELEVATED:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   183
			z = 4;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   184
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   185
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   186
		case SLOPE_SE:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   187
			z = (y >> 1) + 1;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   188
			break;
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   189
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   190
		case SLOPE_WSE:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   191
			z = 8;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   192
			y ^= 0xF;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   193
			if (x - y < 0) {
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   194
				z += (x - y) >> 1;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   195
			}
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   196
			break;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   197
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   198
		case SLOPE_N:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   199
			y ^= 0xF;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   200
			if (y - x >= 0) {
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   201
				z = (y - x) >> 1;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   202
			}
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   203
			break;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   204
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   205
		case SLOPE_NW:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   206
			z = (y ^ 0xF) >> 1;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   207
			break;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   208
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   209
		case SLOPE_NWS:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   210
			z = 8;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   211
			if (x - y < 0) {
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   212
				z += (x - y) >> 1;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   213
			}
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   214
			break;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   215
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   216
		case SLOPE_NE:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   217
			z = (x ^ 0xF) >> 1;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   218
			break;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   219
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   220
		case SLOPE_ENW:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   221
			z = 8;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   222
			y ^= 0xF;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   223
			if (y - x < 0) {
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   224
				z += (y - x) >> 1;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   225
			}
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   226
			break;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   227
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   228
		case SLOPE_SEN:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   229
			z = 8;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   230
			if (y - x < 0) {
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   231
				z += (y - x) >> 1;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   232
			}
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   233
			break;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   234
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   235
		case SLOPE_STEEP_S:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   236
			z = 1 + ((x + y) >> 1);
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   237
			break;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   238
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   239
		case SLOPE_STEEP_W:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   240
			z = 1 + ((x + (y ^ 0xF)) >> 1);
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   241
			break;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   242
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   243
		case SLOPE_STEEP_N:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   244
			z = 1 + (((x ^ 0xF) + (y ^ 0xF)) >> 1);
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   245
			break;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   246
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   247
		case SLOPE_STEEP_E:
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   248
			z = 1 + (((x ^ 0xF) + y) >> 1);
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   249
			break;
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   250
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3529
diff changeset
   251
		default: break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
	return z;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   257
uint GetSlopeZ(int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
   259
	TileIndex tile = TileVirtXY(x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4191
diff changeset
   261
	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
   262
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
8224
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   264
/**
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   265
 * Determine the Z height of a corner relative to TileZ.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   266
 *
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   267
 * @pre The slope must not be a halftile slope.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   268
 *
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   269
 * @param tileh The slope.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   270
 * @param corner The corner.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   271
 * @return Z position of corner relative to TileZ.
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   272
 */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   273
int GetSlopeZInCorner(Slope tileh, Corner corner)
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   274
{
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   275
	assert(!IsHalftileSlope(tileh));
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8876
diff changeset
   276
	return ((tileh & SlopeWithOneCornerRaised(corner)) != 0 ? TILE_HEIGHT : 0) + (tileh == SteepSlope(corner) ? TILE_HEIGHT : 0);
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   277
}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   278
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   279
/**
8224
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   280
 * Determine the Z height of the corners of a specific tile edge
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   281
 *
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   282
 * @note If a tile has a non-continuous halftile foundation, a corner can have different heights wrt. it's edges.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   283
 *
8224
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   284
 * @pre z1 and z2 must be initialized (typ. with TileZ). The corner heights just get added.
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   285
 *
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   286
 * @param tileh The slope of the tile.
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   287
 * @param edge The edge of interest.
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   288
 * @param z1 Gets incremented by the height of the first corner of the edge. (near corner wrt. the camera)
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   289
 * @param z2 Gets incremented by the height of the second corner of the edge. (far corner wrt. the camera)
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   290
 */
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   291
void GetSlopeZOnEdge(Slope tileh, DiagDirection edge, int *z1, int *z2)
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   292
{
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   293
	static const Slope corners[4][4] = {
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   294
		/*    corner     |          steep slope
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   295
		 *  z1      z2   |       z1             z2        */
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   296
		{SLOPE_E, SLOPE_N, SLOPE_STEEP_E, SLOPE_STEEP_N}, // DIAGDIR_NE, z1 = E, z2 = N
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   297
		{SLOPE_S, SLOPE_E, SLOPE_STEEP_S, SLOPE_STEEP_E}, // DIAGDIR_SE, z1 = S, z2 = E
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   298
		{SLOPE_S, SLOPE_W, SLOPE_STEEP_S, SLOPE_STEEP_W}, // DIAGDIR_SW, z1 = S, z2 = W
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   299
		{SLOPE_W, SLOPE_N, SLOPE_STEEP_W, SLOPE_STEEP_N}, // DIAGDIR_NW, z1 = W, z2 = N
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   300
	};
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   301
8260
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   302
	int halftile_test = (IsHalftileSlope(tileh) ? SlopeWithOneCornerRaised(GetHalftileSlopeCorner(tileh)) : 0);
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   303
	if (halftile_test == corners[edge][0]) *z2 += TILE_HEIGHT; // The slope is non-continuous in z2. z2 is on the upper side.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   304
	if (halftile_test == corners[edge][1]) *z1 += TILE_HEIGHT; // The slope is non-continuous in z1. z1 is on the upper side.
c7d75cebe3f6 (svn r11313) -Codechange: prepare several pieces of code so the can handle some new slopes. Patch by frosch.
rubidium
parents: 8224
diff changeset
   305
8224
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   306
	if ((tileh & corners[edge][0]) != 0) *z1 += TILE_HEIGHT; // z1 is raised
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   307
	if ((tileh & corners[edge][1]) != 0) *z2 += TILE_HEIGHT; // z2 is raised
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8876
diff changeset
   308
	if (RemoveHalftileSlope(tileh) == corners[edge][2]) *z1 += TILE_HEIGHT; // z1 is highest corner of a steep slope
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8876
diff changeset
   309
	if (RemoveHalftileSlope(tileh) == corners[edge][3]) *z2 += TILE_HEIGHT; // z2 is highest corner of a steep slope
8224
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   310
}
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   311
8909
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8876
diff changeset
   312
/**
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8876
diff changeset
   313
 * Get slope of a tile on top of a (possible) foundation
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8876
diff changeset
   314
 * If a tile does not have a foundation, the function returns the same as GetTileSlope.
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8876
diff changeset
   315
 *
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8876
diff changeset
   316
 * @param tile The tile of interest.
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8876
diff changeset
   317
 * @param z returns the z of the foundation slope. (Can be NULL, if not needed)
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8876
diff changeset
   318
 * @return The slope on top of the foundation.
fa15e9afad2f (svn r11983) -Codechange: Add some helper functions for slopes and use them.
frosch
parents: 8876
diff changeset
   319
 */
8876
a0b7938c6082 (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8766
diff changeset
   320
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
   321
{
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   322
	Slope tileh = GetTileSlope(tile, z);
7831
5dded9b03500 (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: 7800
diff changeset
   323
	Foundation f = _tile_type_procs[GetTileType(tile)]->get_foundation_proc(tile, tileh);
8876
a0b7938c6082 (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8766
diff changeset
   324
	uint z_inc = ApplyFoundationToSlope(f, &tileh);
a0b7938c6082 (svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents: 8766
diff changeset
   325
	if (z != NULL) *z += z_inc;
7831
5dded9b03500 (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: 7800
diff changeset
   326
	return tileh;
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   327
}
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 37
diff changeset
   328
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   329
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   330
static bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   331
{
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   332
	uint z;
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   333
8224
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   334
	int z_W_here = z_here;
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   335
	int z_N_here = z_here;
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   336
	GetSlopeZOnEdge(slope_here, DIAGDIR_NW, &z_W_here, &z_N_here);
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   337
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   338
	Slope slope = GetFoundationSlope(TILE_ADDXY(tile, 0, -1), &z);
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   339
	int z_W = z;
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   340
	int z_N = z;
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   341
	GetSlopeZOnEdge(slope, DIAGDIR_SE, &z_W, &z_N);
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   342
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   343
	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
   344
}
61bf1df68d82 (svn r38) Preliminary slopes graphics fix. Neighboring tile check not done yet
dominik
parents: 0
diff changeset
   345
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   346
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   347
static bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   348
{
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   349
	uint z;
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   350
8224
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   351
	int z_E_here = z_here;
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   352
	int z_N_here = z_here;
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   353
	GetSlopeZOnEdge(slope_here, DIAGDIR_NE, &z_E_here, &z_N_here);
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   354
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   355
	Slope slope = GetFoundationSlope(TILE_ADDXY(tile, -1, 0), &z);
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   356
	int z_E = z;
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   357
	int z_N = z;
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   358
	GetSlopeZOnEdge(slope, DIAGDIR_SW, &z_E, &z_N);
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   359
6260e98d1c6a (svn r11263) -Codechange: Reduce code duplication between DrawBridgePillars and HasFoundation{NW|NE}. Patch by frosch.
rubidium
parents: 8174
diff changeset
   360
	return (z_N_here > z_N) || (z_E_here > z_E);
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   361
}
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   362
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   363
7831
5dded9b03500 (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: 7800
diff changeset
   364
void DrawFoundation(TileInfo *ti, Foundation f)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
{
7831
5dded9b03500 (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: 7800
diff changeset
   366
	if (!IsFoundation(f)) return;
5dded9b03500 (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: 7800
diff changeset
   367
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   368
	/* Two part foundations must be drawn separately */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   369
	assert(f != FOUNDATION_STEEP_BOTH);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   370
8263
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   371
	uint sprite_block = 0;
4061
219f9d065a28 (svn r5351) -Fix: Several graphical glitches at adjacent tiles with foundations. Some borders were missing, some were superfluous
tron
parents: 4000
diff changeset
   372
	uint z;
7831
5dded9b03500 (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: 7800
diff changeset
   373
	Slope slope = GetFoundationSlope(ti->tile, &z);
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 37
diff changeset
   374
8263
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   375
	/* Select the needed block of foundations sprites
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   376
	 * Block 0: Walls at NW and NE edge
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   377
	 * Block 1: Wall  at        NE edge
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   378
	 * Block 2: Wall  at NW        edge
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   379
	 * Block 3: No walls at NW or NE edge
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   380
	 */
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   381
	if (!HasFoundationNW(ti->tile, slope, z)) sprite_block += 1;
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   382
	if (!HasFoundationNE(ti->tile, slope, z)) sprite_block += 2;
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   383
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   384
	/* Use the original slope sprites if NW and NE borders should be visible */
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   385
	SpriteID leveled_base = (sprite_block == 0 ? (int)SPR_FOUNDATION_BASE : (SPR_SLOPES_VIRTUAL_BASE + sprite_block * SPR_TRKFOUND_BLOCK_SIZE));
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   386
	SpriteID inclined_base = SPR_SLOPES_VIRTUAL_BASE + SPR_SLOPES_INCLINED_OFFSET + sprite_block * SPR_TRKFOUND_BLOCK_SIZE;
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   387
	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
   388
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   389
	if (IsSteepSlope(ti->tileh)) {
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   390
		if (!IsNonContinuousFoundation(f)) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   391
			/* Lower part of foundation */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   392
			AddSortableSpriteToDraw(
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   393
				leveled_base + (ti->tileh & ~SLOPE_STEEP), PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   394
			);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   395
		}
7831
5dded9b03500 (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: 7800
diff changeset
   396
8174
5343705d60f5 (svn r11209) -Codechange: remove some magic numbers and bit magic with appropriate enums and functions. Patch by frosch.
rubidium
parents: 7831
diff changeset
   397
		Corner highest_corner = GetHighestSlopeCorner(ti->tileh);
7831
5dded9b03500 (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: 7800
diff changeset
   398
		ti->z += ApplyFoundationToSlope(f, &ti->tileh);
5dded9b03500 (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: 7800
diff changeset
   399
5dded9b03500 (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: 7800
diff changeset
   400
		if (IsInclinedFoundation(f)) {
5dded9b03500 (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: 7800
diff changeset
   401
			/* inclined foundation */
5dded9b03500 (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: 7800
diff changeset
   402
			byte inclined = highest_corner * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
5dded9b03500 (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: 7800
diff changeset
   403
8263
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   404
			AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y, 16, 16, 1, ti->z);
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   405
			OffsetGroundSprite(31, 9);
10945
b53a857888b8 (svn r13499) -Codechange: Allow drawing (ugly) leveled foundations on steep slopes, just in case someone needs them for fallback.
frosch
parents: 10775
diff changeset
   406
		} else if (IsLeveledFoundation(f)) {
b53a857888b8 (svn r13499) -Codechange: Allow drawing (ugly) leveled foundations on steep slopes, just in case someone needs them for fallback.
frosch
parents: 10775
diff changeset
   407
			AddSortableSpriteToDraw(leveled_base + SlopeWithOneCornerRaised(highest_corner), PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z - TILE_HEIGHT);
b53a857888b8 (svn r13499) -Codechange: Allow drawing (ugly) leveled foundations on steep slopes, just in case someone needs them for fallback.
frosch
parents: 10775
diff changeset
   408
			OffsetGroundSprite(31, 1);
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   409
		} else if (f == FOUNDATION_STEEP_LOWER) {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   410
			/* one corner raised */
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   411
			OffsetGroundSprite(31, 1);
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   412
		} else {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   413
			/* halftile foundation */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   414
			int x_bb = (((highest_corner == CORNER_W) || (highest_corner == CORNER_S)) ? 8 : 0);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   415
			int y_bb = (((highest_corner == CORNER_S) || (highest_corner == CORNER_E)) ? 8 : 0);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   416
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   417
			AddSortableSpriteToDraw(halftile_base + highest_corner, PAL_NONE, ti->x + x_bb, ti->y + y_bb, 8, 8, 7, ti->z + TILE_HEIGHT);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   418
			OffsetGroundSprite(31, 9);
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   419
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
	} else {
7831
5dded9b03500 (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: 7800
diff changeset
   421
		if (IsLeveledFoundation(f)) {
8263
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   422
			/* leveled foundation */
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   423
			AddSortableSpriteToDraw(leveled_base + ti->tileh, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   424
			OffsetGroundSprite(31, 1);
8266
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   425
		} else if (IsNonContinuousFoundation(f)) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   426
			/* halftile foundation */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   427
			Corner halftile_corner = GetHalftileFoundationCorner(f);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   428
			int x_bb = (((halftile_corner == CORNER_W) || (halftile_corner == CORNER_S)) ? 8 : 0);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   429
			int y_bb = (((halftile_corner == CORNER_S) || (halftile_corner == CORNER_E)) ? 8 : 0);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   430
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   431
			AddSortableSpriteToDraw(halftile_base + halftile_corner, PAL_NONE, ti->x + x_bb, ti->y + y_bb, 8, 8, 7, ti->z);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   432
			OffsetGroundSprite(31, 9);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   433
		} else if (IsSpecialRailFoundation(f)) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   434
			/* anti-zig-zag foundation */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   435
			SpriteID spr;
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   436
			if (ti->tileh == SLOPE_NS || ti->tileh == SLOPE_EW) {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   437
				/* half of leveled foundation under track corner */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   438
				spr = leveled_base + SlopeWithThreeCornersRaised(GetRailFoundationCorner(f));
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   439
			} else {
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   440
				/* tile-slope = sloped along X/Y, foundation-slope = three corners raised */
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   441
				spr = inclined_base + 2 * GetRailFoundationCorner(f) + ((ti->tileh == SLOPE_SW || ti->tileh == SLOPE_NE) ? 1 : 0);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   442
			}
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   443
			AddSortableSpriteToDraw(spr, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
48fa6a084b98 (svn r11319) -Add: halftile- and anti-zig-zag-foundations. Patch by frosch.
rubidium
parents: 8263
diff changeset
   444
			OffsetGroundSprite(31, 9);
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   445
		} else {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   446
			/* inclined foundation */
7831
5dded9b03500 (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: 7800
diff changeset
   447
			byte inclined = GetHighestSlopeCorner(ti->tileh) * 2 + (f == FOUNDATION_INCLINED_Y ? 1 : 0);
5dded9b03500 (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: 7800
diff changeset
   448
8263
cf890c002a88 (svn r11316) -Codechange: add support for the half-tile (selection) graphics.
rubidium
parents: 8260
diff changeset
   449
			AddSortableSpriteToDraw(inclined_base + inclined, PAL_NONE, ti->x, ti->y, 16, 16, 1, ti->z);
4253
6fadea8a8043 (svn r5864) -Feature: Also allow horizontal and vertical rails on steep slopes
tron
parents: 4246
diff changeset
   450
			OffsetGroundSprite(31, 9);
4246
14a8849c32df (svn r5833) -Feature: Allow building of (certain) rails, roads and bridge ramps on steep sloped tiles
tron
parents: 4240
diff changeset
   451
		}
7831
5dded9b03500 (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: 7800
diff changeset
   452
		ti->z += ApplyFoundationToSlope(f, &ti->tileh);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   454
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   455
1589
58d173b56509 (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   456
void DoClearSquare(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
{
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   458
	MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   459
	MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9092
diff changeset
   462
/** Returns information about trackdirs and signal states.
9092
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8946
diff changeset
   463
 * If there is any trackbit at 'side', return all trackdirbits.
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9092
diff changeset
   464
 * For TRANSPORT_ROAD, return no trackbits if there is no roadbit (of given subtype) at given side.
9092
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8946
diff changeset
   465
 * @param tile tile to get info about
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8946
diff changeset
   466
 * @param mode transport type
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8946
diff changeset
   467
 * @param sub_mode for TRANSPORT_ROAD, roadtypes to check
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8946
diff changeset
   468
 * @param side side we are entering from, INVALID_DIAGDIR to return all trackbits
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8946
diff changeset
   469
 * @return trackdirbits and other info depending on 'mode'
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8946
diff changeset
   470
 */
9112
ec6800eaa340 (svn r12199) -Codechange: Remove magic around the results of GetTileTrackStatus().
frosch
parents: 9092
diff changeset
   471
TrackStatus GetTileTrackStatus(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
{
9092
383a632de666 (svn r12177) -Codechange: use 'side' parameter in GetTileTrackStatus so there can be less checks in pathfinders for depots/stations/tunnels/bridges
smatz
parents: 8946
diff changeset
   473
	return _tile_type_procs[GetTileType(tile)]->get_tile_track_status_proc(tile, mode, sub_mode, side);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   476
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
   477
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   478
	_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
   479
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
1589
58d173b56509 (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   481
void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
	memset(ac, 0, sizeof(AcceptedCargo));
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   484
	_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
   485
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
1589
58d173b56509 (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   487
void AnimateTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   489
	_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
   490
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
1589
58d173b56509 (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   492
void ClickTile(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   494
	_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
   495
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
1589
58d173b56509 (svn r2093) uint -> TileIndex, remove commented out code and a local variable, which was only used once
tron
parents: 1384
diff changeset
   497
void GetTileDesc(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   499
	_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
   500
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   502
/**
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   503
 * Has a snow line table already been loaded.
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   504
 * @return true if the table has been loaded already.
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   505
 */
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   506
bool IsSnowLineSet(void)
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   507
{
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   508
	return _snow_line != NULL;
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   509
}
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   510
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   511
/**
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   512
 * Set a variable snow line, as loaded from a newgrf file.
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   513
 * @param table the 12 * 32 byte table containing the snowline for each day
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   514
 */
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   515
void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   516
{
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   517
	_snow_line = CallocT<SnowLine>(1);
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   518
	memcpy(_snow_line->table, table, sizeof(_snow_line->table));
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   519
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   520
	for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   521
		for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   522
			_snow_line->highest_value = max(_snow_line->highest_value, table[i][j]);
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   523
		}
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   524
	}
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   525
}
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   526
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   527
/**
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   528
 * Get the current snow line, either variable or static.
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   529
 * @return the snow line height.
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   530
 */
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   531
byte GetSnowLine(void)
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   532
{
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   533
	if (_snow_line == NULL) return _settings_game.game_creation.snow_line;
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   534
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   535
	YearMonthDay ymd;
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   536
	ConvertDateToYMD(_date, &ymd);
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   537
	return _snow_line->table[ymd.month][ymd.day];
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   538
}
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   539
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   540
/**
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   541
 * Get the highest possible snow line height, either variable or static.
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   542
 * @return the highest snow line height.
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   543
 */
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   544
byte HighestSnowLine(void)
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   545
{
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   546
	return _snow_line == NULL ? _settings_game.game_creation.snow_line : _snow_line->highest_value;
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   547
}
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   548
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   549
/**
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   550
 * Clear the variable snow line table and free the memory.
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   551
 */
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   552
void ClearSnowLine(void)
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   553
{
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   554
	free(_snow_line);
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   555
	_snow_line = NULL;
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   556
}
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6573
diff changeset
   557
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1589
diff changeset
   558
/** Clear a piece of landscape
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   559
 * @param tile tile to clear
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   560
 * @param flags of operation to conduct
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1589
diff changeset
   561
 * @param p1 unused
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1589
diff changeset
   562
 * @param p2 unused
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7179
diff changeset
   564
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
   565
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   566
	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
   567
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   568
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   569
/** Clear a big piece of landscape
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   570
 * @param tile end tile of area dragging
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   571
 * @param p1 start tile of area dragging
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   572
 * @param flags of operation to conduct
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   573
 * @param p2 unused
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   574
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7179
diff changeset
   575
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
   576
{
2934
3b7eef9871f8 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2639
diff changeset
   577
	if (p1 >= MapSize()) return CMD_ERROR;
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   578
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   579
	/* make sure sx,sy are smaller than ex,ey */
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   580
	int ex = TileX(tile);
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   581
	int ey = TileY(tile);
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   582
	int sx = TileX(p1);
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   583
	int sy = TileY(p1);
6432
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 5919
diff changeset
   584
	if (ex < sx) Swap(ex, sx);
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 5919
diff changeset
   585
	if (ey < sy) Swap(ey, sy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   587
	Money money = GetAvailableMoneyForCommand();
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   588
	CommandCost cost(EXPENSES_CONSTRUCTION);
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   589
	bool success = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   591
	for (int x = sx; x <= ex; ++x) {
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   592
		for (int y = sy; y <= ey; ++y) {
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   593
			CommandCost ret = DoCommand(TileXY(x, y), 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR);
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   594
			if (CmdFailed(ret)) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
			success = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
			if (flags & DC_EXEC) {
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   598
				money -= ret.GetCost();
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   599
				if (ret.GetCost() > 0 && money < 0) {
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   600
					_additional_cash_required = ret.GetCost();
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   601
					return cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
				}
3493
4d5830846ec2 (svn r4344) Use tile coordinates or even TileIndices instead of virtual tile coordinates where it suffices.
tron
parents: 3491
diff changeset
   603
				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
   604
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   605
				/* draw explosion animation... */
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   606
				if ((x == sx || x == ex) && (y == sy || y == ey)) {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   607
					/* big explosion in each corner, or small explosion for single tiles */
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   608
					CreateEffectVehicleAbove(x * TILE_SIZE + TILE_SIZE / 2, y * TILE_SIZE + TILE_SIZE / 2, 2,
1359
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1350
diff changeset
   609
						sy == ey && sx == ex ? EV_EXPLOSION_SMALL : EV_EXPLOSION_LARGE
8ba976aed634 (svn r1863) Give the effect vehicle type enums more descriptive names and use the enum as parameter type for CreateEffectVehicle*()
tron
parents: 1350
diff changeset
   610
					);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   611
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
			}
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   613
			cost.AddCost(ret);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
1793
8ac8a8c9ec0f (svn r2297) - CodeChange: server-check the next batch of commands.
Darkvater
parents: 1775
diff changeset
   617
	return (success) ? cost : CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
10233
c08376c16fb2 (svn r12765) -Codechange: move some stuff out of variables.h that required including other headers in variables.h.
rubidium
parents: 9313
diff changeset
   621
TileIndex _cur_tileloop_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
#define TILELOOP_BITS 4
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
#define TILELOOP_SIZE (1 << TILELOOP_BITS)
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6683
diff changeset
   624
#define TILELOOP_ASSERTMASK ((TILELOOP_SIZE - 1) + ((TILELOOP_SIZE - 1) << MapLogX()))
927
28f45a22a564 (svn r1415) Move TILE_FROM_XY and TILE_XY to map.h and push TILE_[XY] bits from map.h into map.c.
tron
parents: 926
diff changeset
   625
#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
   626
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   627
void RunTileLoop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
{
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   629
	TileIndex tile = _cur_tileloop_tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   631
	assert((tile & ~TILELOOP_ASSERTMASK) == 0);
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   632
	uint count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
	do {
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   634
		_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
   635
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 925
diff changeset
   636
		if (TileX(tile) < MapSizeX() - TILELOOP_SIZE) {
6527
f584ab6d87f8 (svn r8987) -Cleanup: doxygen changes. Again. Mostly (still) @files missing tags and (more than just) a few comments style.
belugas
parents: 6432
diff changeset
   637
			tile += TILELOOP_SIZE; // no overflow
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   638
		} else {
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   639
			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
   640
		}
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   641
	} while (--count != 0);
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   642
	assert((tile & ~TILELOOP_ASSERTMASK) == 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   644
	tile += 9;
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   645
	if (tile & TILELOOP_CHKMASK) {
863
8d09f9331a80 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 857
diff changeset
   646
		tile = (tile + MapSizeX()) & TILELOOP_ASSERTMASK;
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   647
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
	_cur_tileloop_tile = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   651
void InitializeLandscape()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   652
{
3078
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   653
	uint maxx = MapMaxX();
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   654
	uint maxy = MapMaxY();
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   655
	uint sizex = MapSizeX();
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   656
3078
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   657
	uint y;
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   658
	for (y = 0; y < maxy; y++) {
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   659
		uint x;
3078
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   660
		for (x = 0; x < maxx; x++) {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   661
			MakeClear(sizex * y + x, CLEAR_GRASS, 3);
3078
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   662
			SetTileHeight(sizex * y + x, 0);
8946
85eff1ad8cda (svn r12020) -Documentation: Correct description of TropicZone.
frosch
parents: 8909
diff changeset
   663
			SetTropicZone(sizex * y + x, TROPICZONE_NORMAL);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4990
diff changeset
   664
			ClearBridgeMiddle(sizex * y + x);
3078
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   665
		}
ae74442bd058 (svn r3667) Fix the cause of an assertion I triggered in r3665
tron
parents: 3076
diff changeset
   666
		MakeVoid(sizex * y + x);
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   667
	}
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   668
	for (uint 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
   669
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   670
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   671
static const byte _genterrain_tbl_1[5] = { 10, 22, 33, 37, 4  };
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4300
diff changeset
   672
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
   673
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   674
static void GenerateTerrain(int type, uint flag)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   675
{
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   676
	uint32 r = Random();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   678
	const Sprite *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
   679
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   680
	uint x = r & MapMaxX();
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   681
	uint y = (r >> MapLogX()) & MapMaxY();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   682
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   683
	if (x < 2 || y < 2) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   685
	DiagDirection direction = (DiagDirection)GB(r, 22, 2);
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   686
	uint w = templ->width;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   687
	uint h = templ->height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   688
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   689
	if (DiagDirToAxis(direction) == AXIS_Y) Swap(w, h);
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   690
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   691
	const byte *p = templ->data;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   692
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   693
	if ((flag & 4) != 0) {
1273
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   694
		uint xw = x * MapSizeY();
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   695
		uint yw = y * MapSizeX();
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   696
		uint bias = (MapSizeX() + MapSizeY()) * 16;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   697
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   698
		switch (flag & 3) {
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   699
			default: NOT_REACHED();
1273
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   700
			case 0:
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   701
				if (xw + yw > MapSize() - bias) return;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   702
				break;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   703
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   704
			case 1:
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   705
				if (yw < xw + bias) return;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   706
				break;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   707
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   708
			case 2:
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   709
				if (xw + yw < MapSize() + bias) return;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   710
				break;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   711
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   712
			case 3:
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   713
				if (xw < yw + bias) return;
240fa6848fbc (svn r1777) Fix map generation for tropical and arctic landscape on larger/smaller maps
tron
parents: 1247
diff changeset
   714
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   716
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   718
	if (x + w >= MapMaxX() - 1) return;
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   719
	if (y + h >= MapMaxY() - 1) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   721
	Tile *tile = &_m[TileXY(x, y)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   723
	switch (direction) {
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   724
		default: NOT_REACHED();
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   725
		case DIAGDIR_NE:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   726
			do {
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   727
				Tile *tile_cur = tile;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   728
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   729
				for (uint w_cur = w; w_cur != 0; --w_cur) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   730
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   731
					p++;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   732
					tile_cur++;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   733
				}
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   734
				tile += TileDiffXY(0, 1);
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   735
			} while (--h != 0);
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   736
			break;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   737
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   738
		case DIAGDIR_SE:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   739
			do {
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   740
				Tile *tile_cur = tile;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   741
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   742
				for (uint h_cur = h; h_cur != 0; --h_cur) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   743
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   744
					p++;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   745
					tile_cur += TileDiffXY(0, 1);
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   746
				}
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   747
				tile += TileDiffXY(1, 0);
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   748
			} while (--w != 0);
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   749
			break;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   750
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   751
		case DIAGDIR_SW:
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   752
			tile += TileDiffXY(w - 1, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
			do {
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   754
				Tile *tile_cur = tile;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   755
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   756
				for (uint w_cur = w; w_cur != 0; --w_cur) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   757
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   758
					p++;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   759
					tile_cur--;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   760
				}
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   761
				tile += TileDiffXY(0, 1);
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   762
			} while (--h != 0);
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   763
			break;
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   764
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   765
		case DIAGDIR_NW:
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   766
			tile += TileDiffXY(0, h - 1);
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   767
			do {
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   768
				Tile *tile_cur = tile;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   769
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   770
				for (uint h_cur = h; h_cur != 0; --h_cur) {
2049
ad0d49c916d4 (svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents: 1999
diff changeset
   771
					if (*p >= tile_cur->type_height) tile_cur->type_height = *p;
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   772
					p++;
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   773
					tile_cur -= TileDiffXY(0, 1);
1278
1fbb6cf8d3f1 (svn r1782) Remove line which should've been removed in r1779 and caused map generation to hang infinitely
tron
parents: 1275
diff changeset
   774
				}
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   775
				tile += TileDiffXY(1, 0);
1275
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   776
			} while (--w != 0);
10f4edfafb5a (svn r1779) Make the map generation code slightly more readable
tron
parents: 1273
diff changeset
   777
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   782
#include "table/genland.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   784
static void CreateDesertOrRainForest()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
{
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   786
	TileIndex update_freq = MapSize() / 4;
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   787
	const TileIndexDiffC *data;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   789
	for (TileIndex tile = 0; tile != MapSize(); ++tile) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   790
		if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   791
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   792
		for (data = _make_desert_or_rainforest_data;
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   793
				data != endof(_make_desert_or_rainforest_data); ++data) {
1184
7f0ac9482dad (svn r1686) Fix (Work around?) crash when generating tropical maps
tron
parents: 1181
diff changeset
   794
			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
1044
9b73df700a7c (svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents: 1035
diff changeset
   795
			if (TileHeight(t) >= 4 || IsTileType(t, MP_WATER)) break;
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   796
		}
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   797
		if (data == endof(_make_desert_or_rainforest_data))
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3297
diff changeset
   798
			SetTropicZone(tile, TROPICZONE_DESERT);
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   799
	}
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   800
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   801
	for (uint i = 0; i != 256; i++) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   802
		if ((i % 64) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   803
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
		RunTileLoop();
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   805
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   807
	for (TileIndex tile = 0; tile != MapSize(); ++tile) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   808
		if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   809
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   810
		for (data = _make_desert_or_rainforest_data;
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   811
				data != endof(_make_desert_or_rainforest_data); ++data) {
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   812
			TileIndex t = TILE_MASK(tile + ToTileIndexDiff(*data));
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   813
			if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_DESERT)) break;
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   814
		}
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   815
		if (data == endof(_make_desert_or_rainforest_data))
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3297
diff changeset
   816
			SetTropicZone(tile, TROPICZONE_RAINFOREST);
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 889
diff changeset
   817
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   818
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   819
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   820
void GenerateLandscape(byte mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   821
{
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   822
	static const int gwp_desert_amount = 4 + 8;
183
ec2b02ea4c88 (svn r184) -Fix: starting a new game in DesertLandscape crashed the game
truelight
parents: 159
diff changeset
   823
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   824
	if (mode == GW_HEIGHTMAP) {
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   825
		SetGeneratingWorldProgress(GWP_LANDSCAPE, (_settings_game.game_creation.landscape == LT_TROPIC) ? 1 + gwp_desert_amount : 1);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   826
		LoadHeightmap(_file_to_saveload.name);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   827
		IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   828
	} else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) {
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   829
		SetGeneratingWorldProgress(GWP_LANDSCAPE, (_settings_game.game_creation.landscape == LT_TROPIC) ? 3 + gwp_desert_amount : 3);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   830
		GenerateTerrainPerlin();
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   831
	} else {
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   832
		switch (_settings_game.game_creation.landscape) {
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   833
			case LT_ARCTIC: {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   834
				SetGeneratingWorldProgress(GWP_LANDSCAPE, 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   835
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   836
				uint32 r = Random();
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   837
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   838
				for (uint i = ScaleByMapSize(GB(r, 0, 7) + 950); i != 0; --i) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   839
					GenerateTerrain(2, 0);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   840
				}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   841
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2955
diff changeset
   842
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   843
				uint flag = GB(r, 7, 2) | 4;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   844
				for (uint i = ScaleByMapSize(GB(r, 9, 7) + 450); i != 0; --i) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   845
					GenerateTerrain(4, flag);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   846
				}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   847
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   848
			} break;
3017
915fae59d5e0 (svn r3597) Miscellaneous (I like that word) changes: Fix some indentation, add consts, reduce indentation level by short-circuit logic, convert if cascades to switch, whitespace, bracing, plus some minor stuff
tron
parents: 2955
diff changeset
   849
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   850
			case LT_TROPIC: {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   851
				SetGeneratingWorldProgress(GWP_LANDSCAPE, 3 + gwp_desert_amount);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   852
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   853
				uint32 r = Random();
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   854
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   855
				for (uint i = ScaleByMapSize(GB(r, 0, 7) + 170); i != 0; --i) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   856
					GenerateTerrain(0, 0);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   857
				}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   858
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   859
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   860
				uint flag = GB(r, 7, 2) | 4;
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   861
				for (uint i = ScaleByMapSize(GB(r, 9, 8) + 1700); i != 0; --i) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   862
					GenerateTerrain(0, flag);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   863
				}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   864
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   865
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   866
				flag ^= 2;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   867
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   868
				for (uint i = ScaleByMapSize(GB(r, 17, 7) + 410); i != 0; --i) {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   869
					GenerateTerrain(3, flag);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   870
				}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   871
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   872
			} break;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   873
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   874
			default: {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   875
				SetGeneratingWorldProgress(GWP_LANDSCAPE, 1);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   876
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   877
				uint32 r = Random();
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   878
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   879
				uint i = ScaleByMapSize(GB(r, 0, 7) + (3 - _settings_game.difficulty.quantity_sea_lakes) * 256 + 100);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   880
				for (; i != 0; --i) {
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   881
					GenerateTerrain(_settings_game.difficulty.terrain_type, 0);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   882
				}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   883
				IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
9313
5593ea43406b (svn r12563) -Cleanup: variable scope and a bit of coding style in landscape.cpp
smatz
parents: 9147
diff changeset
   884
			} break;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4253
diff changeset
   885
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
	ConvertGroundTilesIntoWaterTiles();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
10775
7061477bfbcf (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 10707
diff changeset
   890
	if (_settings_game.game_creation.landscape == LT_TROPIC) CreateDesertOrRainForest();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   891
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   892
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   893
void OnTick_Town();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   894
void OnTick_Trees();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   895
void OnTick_Station();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   896
void OnTick_Industry();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   898
void OnTick_Players();
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   899
void OnTick_Train();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   900
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6527
diff changeset
   901
void CallLandscapeTick()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   902
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   903
	OnTick_Town();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
	OnTick_Trees();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   905
	OnTick_Station();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   906
	OnTick_Industry();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   907
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   908
	OnTick_Players();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
	OnTick_Train();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   910
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   911
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   912
TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   913
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   914
	int rn = rng;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   915
	uint32 r = Random();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   917
	return TILE_MASK(TileXY(
2150
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   918
		TileX(a) + (GB(r, 0, 8) * rn * 2 >> 8) - rn,
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   919
		TileY(a) + (GB(r, 8, 8) * rn * 2 >> 8) - rn
1174
27e386195965 (svn r1676) Increase the size of TileIndex and TileIndexDiff to 32bits and adapt the save/load data and some other parts of the code to that change
tron
parents: 1140
diff changeset
   920
	));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   921
}