src/clear_cmd.cpp
author rubidium
Wed, 19 Dec 2007 23:26:02 +0000
changeset 8108 b42a0e5c67ef
parent 7977 4a4e11757be5
child 8116 8da76dcb3287
permissions -rw-r--r--
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
     3
/** @file clear_cmd.cpp */
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1878
diff changeset
     6
#include "openttd.h"
3144
33e42feae531 (svn r3763) Adapt to the new 'map accessors go in foo_map.h'-scheme
tron
parents: 2989
diff changeset
     7
#include "clear_map.h"
4041
72276cd8ee2b (svn r5309) Partially fix the rail header dependency fiasco: rail_map.h now depends on rail.h and not the other way round anymore
tron
parents: 4031
diff changeset
     8
#include "rail_map.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 473
diff changeset
     9
#include "table/strings.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2154
diff changeset
    10
#include "functions.h"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 507
diff changeset
    11
#include "map.h"
2154
f86c59e73a16 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2153
diff changeset
    12
#include "player.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "command.h"
3156
f4caf4197189 (svn r3779) Move CheckTunnelInWay() to a more appropriate place, invert its result and give it a less ambiguous name (IsTunnelInWay)
tron
parents: 3144
diff changeset
    15
#include "tunnel_map.h"
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4815
diff changeset
    16
#include "bridge_map.h"
6160
fa42299e967e (svn r8908) -Codechange: declaration of DrawBridgeMiddle does not belong in a map accessors header.
rubidium
parents: 6123
diff changeset
    17
#include "bridge.h"
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6248
diff changeset
    18
#include "landscape.h"
2153
ecfc674410b4 (svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents: 2150
diff changeset
    19
#include "variables.h"
2517
6e3832ddd0f6 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2436
diff changeset
    20
#include "table/sprites.h"
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3279
diff changeset
    21
#include "unmovable_map.h"
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    22
#include "genworld.h"
4328
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4300
diff changeset
    23
#include "industry.h"
6974
952d742f6dee (svn r10230) -Fix [FS#594]: terraforming wipes out canals. Now you always have to remove the canal before terraforming, instead of "just" removing the canal.
rubidium
parents: 6972
diff changeset
    24
#include "water_map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    26
/*
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    27
 * In one terraforming command all four corners of a initial tile can be raised/lowered (though this is not available to the player).
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    28
 * The maximal amount of height modifications is archieved when raising a complete flat land from sea level to MAX_TILE_HEIGHT or vice versa.
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    29
 * This affects all corners with a manhatten distance smaller than MAX_TILE_HEIGHT to one of the initial 4 corners.
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    30
 * Their maximal amount is computed to 4 * \sum_{i=1}^{h_max} i  =  2 * h_max * (h_max + 1).
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    31
 */
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    32
static const int TERRAFORMER_MODHEIGHT_SIZE = 2 * MAX_TILE_HEIGHT * (MAX_TILE_HEIGHT + 1);
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    33
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    34
/*
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    35
 * The maximal amount of affected tiles (i.e. the tiles that incident with one of the corners above, is computed similiar to
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    36
 * 1 + 4 * \sum_{i=1}^{h_max} (i+1)  =  1 + 2 * h_max + (h_max + 3).
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    37
 */
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    38
static const int TERRAFORMER_TILE_TABLE_SIZE = 1 + 2 * MAX_TILE_HEIGHT * (MAX_TILE_HEIGHT + 3);
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    39
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    40
struct TerraformerHeightMod {
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    41
	TileIndex tile;   ///< Referenced tile.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    42
	byte height;      ///< New TileHeight (height of north corner) of the tile.
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    43
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    45
struct TerraformerState {
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    46
	int modheight_count;                                         ///< amount of entries in "modheight".
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    47
	int tile_table_count;                                        ///< amount of entries in "tile_table".
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
    48
7545
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7517
diff changeset
    49
	/**
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7517
diff changeset
    50
	 * Dirty tiles, i.e.\ at least one corner changed.
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7517
diff changeset
    51
	 *
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7517
diff changeset
    52
	 * This array contains the tiles which are or will be marked as dirty.
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7517
diff changeset
    53
	 *
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7517
diff changeset
    54
	 * @ingroup dirty
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7517
diff changeset
    55
	 */
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7517
diff changeset
    56
	TileIndex tile_table[TERRAFORMER_TILE_TABLE_SIZE];
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    57
	TerraformerHeightMod modheight[TERRAFORMER_MODHEIGHT_SIZE];  ///< Height modifications.
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    58
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    59
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    60
/**
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    61
 * Gets the TileHeight (height of north corner) of a tile as of current terraforming progress.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    62
 *
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    63
 * @param ts TerraformerState.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    64
 * @param tile Tile.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    65
 * @return TileHeight.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    66
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    67
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    68
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
	TerraformerHeightMod *mod = ts->modheight;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
	int count;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
    71
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    72
	for (count = ts->modheight_count; count != 0; count--, mod++) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    73
		if (mod->tile == tile) return mod->height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    74
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    75
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    76
	/* TileHeight unchanged so far, read value from map. */
1044
63e0601a43cc (svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents: 1035
diff changeset
    77
	return TileHeight(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    78
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    79
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
    80
/**
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    81
 * Stores the TileHeight (height of north corner) of a tile in a TerraformerState.
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    82
 *
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    83
 * @param ts TerraformerState.
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    84
 * @param tile Tile.
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    85
 * @param height New TileHeight.
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    86
 */
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    87
static void TerraformSetHeightOfTile(TerraformerState *ts, TileIndex tile, int height)
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    88
{
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    89
	/* Find tile in the "modheight" table.
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    90
	 * Note: In a normal user-terraform command the tile will not be found in the "modheight" table.
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    91
	 *       But during house- or industry-construction multiple corners can be terraformed at once. */
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    92
	TerraformerHeightMod *mod = ts->modheight;
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    93
	int count = ts->modheight_count;
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    94
	while ((count > 0) && (mod->tile != tile)) {
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    95
		mod++;
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    96
		count--;
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    97
	}
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    98
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
    99
	/* New entry? */
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   100
	if (count == 0) {
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   101
		assert(ts->modheight_count < TERRAFORMER_MODHEIGHT_SIZE);
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   102
		ts->modheight_count++;
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   103
	}
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   104
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   105
	/* Finally store the new value */
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   106
	mod->tile = tile;
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   107
	mod->height = (byte)height;
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   108
}
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   109
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   110
/**
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   111
 * Adds a tile to the "tile_table" in a TerraformerState.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   112
 *
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   113
 * @param ts TerraformerState.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   114
 * @param tile Tile.
7545
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7517
diff changeset
   115
 * @ingroup dirty
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   116
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
	int count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
	TileIndex *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
	count = ts->tile_table_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   124
	for (t = ts->tile_table; count != 0; count--, t++) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   125
		if (*t == tile) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   128
	assert(ts->tile_table_count < TERRAFORMER_TILE_TABLE_SIZE);
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   129
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   130
	ts->tile_table[ts->tile_table_count++] = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   133
/**
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   134
 * Adds all tiles that incident with the north corner of a specific tile to the "tile_table" in a TerraformerState.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   135
 *
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   136
 * @param ts TerraformerState.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   137
 * @param tile Tile.
7545
d44e19c5671e (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 7517
diff changeset
   138
 * @ingroup dirty
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   139
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   140
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
{
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   142
	TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1));
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   143
	TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1));
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   144
	TerraformAddDirtyTile(ts, tile + TileDiffXY(-1,  0));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
	TerraformAddDirtyTile(ts, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   148
/**
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   149
 * Terraform the north corner of a tile to a specific height.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   150
 *
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   151
 * @param ts TerraformerState.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   152
 * @param tile Tile.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   153
 * @param height Aimed height.
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   154
 * @param return Error code or cost.
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   155
 */
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   156
static CommandCost TerraformTileHeight(TerraformerState *ts, TileIndex tile, int height)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
{
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   158
	CommandCost total_cost = CommandCost();
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   159
863
6a1444534f62 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 856
diff changeset
   160
	assert(tile < MapSize());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   162
	/* Check range of destination height */
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   163
	if (height < 0) return_cmd_error(STR_1003_ALREADY_AT_SEA_LEVEL);
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   164
	if (height > MAX_TILE_HEIGHT) return_cmd_error(STR_1004_TOO_HIGH);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   165
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   166
	/*
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   167
	 * Check if the terraforming has any effect.
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   168
	 * This can only be true, if multiple corners of the start-tile are terraformed (i.e. the terraforming is done by towns/industries etc.).
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   169
	 * In this case the terraforming should fail. (Don't know why.)
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   170
	 */
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   171
	if (height == TerraformGetHeightOfTile(ts, tile)) return CMD_ERROR;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   172
7487
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   173
	/* Check "too close to edge of map" */
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   174
	uint x = TileX(tile);
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   175
	uint y = TileY(tile);
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   176
	if ((x <= 1) || (y <= 1) || (x >= MapMaxX() - 1) || (y >= MapMaxY() - 1)) {
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   177
		/*
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   178
		 * Determine a sensible error tile
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   179
		 * Note: If x and y are both zero this will disable the error tile. (Tile 0 cannot be highlighted :( )
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   180
		 */
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   181
		if ((x == 1) && (y != 0)) x = 0;
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   182
		if ((y == 1) && (x != 0)) y = 0;
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   183
		_terraform_err_tile = TileXY(x, y);
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   184
		return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
7487
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   185
	}
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   186
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   187
	/* Mark incident tiles, that are involved in the terraforming */
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   188
	TerraformAddDirtyTileAround(ts, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   190
	/* Store the height modification */
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   191
	TerraformSetHeightOfTile(ts, tile, height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   193
	/* Increment cost */
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   194
	total_cost.AddCost(_price.terraform);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   196
	/* Recurse to neighboured corners if height difference is larger than 1 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
	{
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   198
		const TileIndexDiffC *ttm;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   200
		static const TileIndexDiffC _terraform_tilepos[] = {
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   201
			{ 1,  0}, // move to tile in SE
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   202
			{-2,  0}, // undo last move, and move to tile in NW
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   203
			{ 1,  1}, // undo last move, and move to tile in SW
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   204
			{ 0, -2}  // undo last move, and move to tile in NE
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   205
		};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   207
		for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) {
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   208
			tile += ToTileIndexDiff(*ttm);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   210
			/* Get TileHeight of neighboured tile as of current terraform progress */
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   211
			int r = TerraformGetHeightOfTile(ts, tile);
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   212
			int height_diff = height - r;
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   213
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   214
			/* Is the height difference to the neighboured corner greater than 1? */
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   215
			if (abs(height_diff) > 1) {
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   216
				/* Terraform the neighboured corner. The resulting height difference should be 1. */
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   217
				height_diff += (height_diff < 0 ? 1 : -1);
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   218
				CommandCost cost = TerraformTileHeight(ts, tile, r + height_diff);
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   219
				if (CmdFailed(cost)) return cost;
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   220
				total_cost.AddCost(cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   225
	return total_cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1571
diff changeset
   228
/** Terraform land
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   229
 * @param tile tile to terraform
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   230
 * @param flags for this command type
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   231
 * @param p1 corners to terraform (SLOPE_xxx)
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   232
 * @param p2 direction; eg up (non-zero) or down (zero)
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   233
 * @return error or cost of terraforming
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6718
diff changeset
   235
CommandCost CmdTerraformLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
	TerraformerState ts;
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   238
	CommandCost total_cost = CommandCost();
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   239
	int direction = (p2 != 0 ? 1 : -1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
	_terraform_err_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	ts.modheight_count = ts.tile_table_count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
1878
980fabc7d8a5 (svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents: 1796
diff changeset
   247
	/* Make an extra check for map-bounds cause we add tiles to the originating tile */
2934
3f29a7212713 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2705
diff changeset
   248
	if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR;
1878
980fabc7d8a5 (svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents: 1796
diff changeset
   249
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   250
	/* Compute the costs and the terraforming result in a model of the landscape */
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   251
	if ((p1 & SLOPE_W) != 0) {
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   252
		TileIndex t = tile + TileDiffXY(1, 0);
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   253
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   254
		if (CmdFailed(cost)) return cost;
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   255
		total_cost.AddCost(cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   258
	if ((p1 & SLOPE_S) != 0) {
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   259
		TileIndex t = tile + TileDiffXY(1, 1);
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   260
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   261
		if (CmdFailed(cost)) return cost;
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   262
		total_cost.AddCost(cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   265
	if ((p1 & SLOPE_E) != 0) {
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   266
		TileIndex t = tile + TileDiffXY(0, 1);
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   267
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   268
		if (CmdFailed(cost)) return cost;
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   269
		total_cost.AddCost(cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   272
	if ((p1 & SLOPE_N) != 0) {
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   273
		TileIndex t = tile + TileDiffXY(0, 0);
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   274
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   275
		if (CmdFailed(cost)) return cost;
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   276
		total_cost.AddCost(cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
7487
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   279
	/* Check if the terraforming is valid wrt. tunnels, bridges and objects on the surface */
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4815
diff changeset
   280
	{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
		int count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
		TileIndex *ti = ts.tile_table;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   283
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1571
diff changeset
   284
		for (count = ts.tile_table_count; count != 0; count--, ti++) {
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   285
			TileIndex tile = *ti;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
7487
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   287
			/* Find new heights of tile corners */
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   288
			uint z_N = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0));
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   289
			uint z_W = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0));
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   290
			uint z_S = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1));
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   291
			uint z_E = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1));
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   292
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   293
			/* Find min and max height of tile */
7487
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   294
			uint z_min = min(min(z_N, z_W), min(z_S, z_E));
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   295
			uint z_max = max(max(z_N, z_W), max(z_S, z_E));
6718
ac9a2ab07d64 (svn r9950) -Feature(tte): allow terraforming under bridges.
rubidium
parents: 6683
diff changeset
   296
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   297
			/* Compute tile slope */
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   298
			uint tileh = (z_max > z_min + 1 ? SLOPE_STEEP : SLOPE_FLAT);
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   299
			if (z_W > z_min) tileh += SLOPE_W;
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   300
			if (z_S > z_min) tileh += SLOPE_S;
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   301
			if (z_E > z_min) tileh += SLOPE_E;
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   302
			if (z_N > z_min) tileh += SLOPE_N;
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   303
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   304
			/* Check if bridge would take damage */
6718
ac9a2ab07d64 (svn r9950) -Feature(tte): allow terraforming under bridges.
rubidium
parents: 6683
diff changeset
   305
			if (direction == 1 && MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) &&
ac9a2ab07d64 (svn r9950) -Feature(tte): allow terraforming under bridges.
rubidium
parents: 6683
diff changeset
   306
					GetBridgeHeight(GetSouthernBridgeEnd(tile)) <= z_max * TILE_HEIGHT) {
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   307
				_terraform_err_tile = tile; // highlight the tile under the bridge
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4815
diff changeset
   308
				return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4815
diff changeset
   309
			}
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   310
			/* Check if tunnel would take damage */
6718
ac9a2ab07d64 (svn r9950) -Feature(tte): allow terraforming under bridges.
rubidium
parents: 6683
diff changeset
   311
			if (direction == -1 && IsTunnelInWay(tile, z_min * TILE_HEIGHT)) {
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   312
				_terraform_err_tile = tile; // highlight the tile above the tunnel
6718
ac9a2ab07d64 (svn r9950) -Feature(tte): allow terraforming under bridges.
rubidium
parents: 6683
diff changeset
   313
				return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   314
			}
7487
0a3ff8c6ed75 (svn r10998) -Codechange: refactor of the "core" of the terraforming code to make it possible to push the tile type specific terraforming requirements out of the generic part of the terraforming code. Patch by frosch. For more information take a look at FS#1147.
rubidium
parents: 7480
diff changeset
   315
			/* Check tiletype-specific things, and add extra-cost */
7637
43e2956af72e (svn r11168) -Fix [FS#1256]: assert on terraforming of industries. Patch by frosch.
rubidium
parents: 7545
diff changeset
   316
			CommandCost cost = _tile_type_procs[GetTileType(tile)]->terraform_tile_proc(tile, flags | DC_AUTO, z_min * TILE_HEIGHT, (Slope) tileh);
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   317
			if (CmdFailed(cost)) {
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   318
				_terraform_err_tile = tile;
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   319
				return cost;
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   320
			}
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   321
			total_cost.AddCost(cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
		/* change the height */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
			int count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
			TerraformerHeightMod *mod;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
			mod = ts.modheight;
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1571
diff changeset
   332
			for (count = ts.modheight_count; count != 0; count--, mod++) {
1979
82d8bcc16ce2 (svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents: 1977
diff changeset
   333
				TileIndex til = mod->tile;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   334
1059
fe97d81a1b4f (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1044
diff changeset
   335
				SetTileHeight(til, mod->height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
		/* finally mark the dirty tiles dirty */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   340
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
			int count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
			TileIndex *ti = ts.tile_table;
1775
548dc04d50e2 (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1571
diff changeset
   343
			for (count = ts.tile_table_count; count != 0; count--, ti++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
				MarkTileDirtyByTile(*ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   346
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
	}
7517
c02f7d09b1bc (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 7509
diff changeset
   348
	return total_cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   352
/** Levels a selected (rectangle) area of land
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   353
 * @param tile end tile of area-drag
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   354
 * @param flags for this command type
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   355
 * @param p1 start tile of area drag
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   356
 * @param p2 unused
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   357
 * @return  error or cost of terraforming
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6718
diff changeset
   359
CommandCost CmdLevelLand(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
	int size_x, size_y;
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   362
	int ex;
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   363
	int ey;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
	int sx, sy;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
	uint h, curh;
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   366
	CommandCost money;
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6718
diff changeset
   367
	CommandCost ret;
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6718
diff changeset
   368
	CommandCost cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
2934
3f29a7212713 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2705
diff changeset
   370
	if (p1 >= MapSize()) return CMD_ERROR;
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   371
889
64d2f7d5f02b (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 863
diff changeset
   372
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
64d2f7d5f02b (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 863
diff changeset
   373
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   374
	/* remember level height */
1044
63e0601a43cc (svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents: 1035
diff changeset
   375
	h = TileHeight(p1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   377
	/* make sure sx,sy are smaller than ex,ey */
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   378
	ex = TileX(tile);
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   379
	ey = TileY(tile);
926
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
   380
	sx = TileX(p1);
a6d140a6a4de (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
   381
	sy = TileY(p1);
6106
2898cd9417fd (svn r8841) -Fix
tron
parents: 5668
diff changeset
   382
	if (ex < sx) Swap(ex, sx);
2898cd9417fd (svn r8841) -Fix
tron
parents: 5668
diff changeset
   383
	if (ey < sy) Swap(ey, sy);
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   384
	tile = TileXY(sx, sy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   386
	size_x = ex - sx + 1;
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6357
diff changeset
   387
	size_y = ey - sy + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   389
	money.AddCost(GetAvailableMoneyForCommand());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   391
	BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
1044
63e0601a43cc (svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents: 1035
diff changeset
   392
		curh = TileHeight(tile2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
		while (curh != h) {
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   394
			ret = DoCommand(tile2, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   395
			if (CmdFailed(ret)) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
			if (flags & DC_EXEC) {
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   398
				money.AddCost(-ret.GetCost());
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   399
				if (money.GetCost() < 0) {
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   400
					_additional_cash_required = ret.GetCost();
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   401
					return cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
				}
7480
1ae973d5f341 (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7335
diff changeset
   403
				DoCommand(tile2, SLOPE_N, (curh > h) ? 0 : 1, flags, CMD_TERRAFORM_LAND);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   406
			cost.AddCost(ret);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   407
			curh += (curh > h) ? -1 : 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
		}
1796
614d996f6be7 (svn r2300) - CodeChange: check the last number of commands, now only the refit ones remain, and some server-only commands.
Darkvater
parents: 1782
diff changeset
   409
	} END_TILE_LOOP(tile2, size_x, size_y, tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   411
	return (cost.GetCost() == 0) ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   414
/** Purchase a land area. Actually you only purchase one tile, so
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   415
 * the name is a bit confusing ;p
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   416
 * @param tile the tile the player is purchasing
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   417
 * @param flags for this command type
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   418
 * @param p1 unused
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   419
 * @param p2 unused
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   420
 * @return error of cost of operation
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6718
diff changeset
   422
CommandCost CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
{
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6718
diff changeset
   424
	CommandCost cost;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   425
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   427
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3279
diff changeset
   428
	if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
		return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3279
diff changeset
   430
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   432
	cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   433
	if (CmdFailed(cost)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
	if (flags & DC_EXEC) {
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3279
diff changeset
   436
		MakeOwnedLand(tile, _current_player);
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3279
diff changeset
   437
		MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
7977
4a4e11757be5 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 7727
diff changeset
   440
	return cost.AddCost(_price.clear_roughland * 10);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   441
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   442
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6718
diff changeset
   444
static CommandCost ClearTile_Clear(TileIndex tile, byte flags)
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   445
{
6953
230d1e3ac86c (svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium
parents: 6950
diff changeset
   446
	static const Money* clear_price_table[] = {
7977
4a4e11757be5 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 7727
diff changeset
   447
		&_price.clear_grass,
4a4e11757be5 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 7727
diff changeset
   448
		&_price.clear_roughland,
4a4e11757be5 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 7727
diff changeset
   449
		&_price.clear_rocks,
4a4e11757be5 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 7727
diff changeset
   450
		&_price.clear_fields,
4a4e11757be5 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 7727
diff changeset
   451
		&_price.clear_roughland,
4a4e11757be5 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 7727
diff changeset
   452
		&_price.clear_roughland,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
	};
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6718
diff changeset
   454
	CommandCost price;
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   455
6950
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   456
	if (!IsClearGround(tile, CLEAR_GRASS) || GetClearDensity(tile) != 0) {
14ecb0acdfb4 (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 6943
diff changeset
   457
		price.AddCost(*clear_price_table[GetClearGround(tile)]);
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   458
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
2220
cacd492f3c1c (svn r2738) Small bit fiddling cleanup
tron
parents: 2186
diff changeset
   460
	if (flags & DC_EXEC) DoClearSquare(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   462
	return price;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   465
/** Sell a land area. Actually you only sell one tile, so
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   466
 * the name is a bit confusing ;p
3491
35d747bb5e82 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   467
 * @param tile the tile the player is selling
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   468
 * @param flags for this command type
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   469
 * @param p1 unused
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   470
 * @param p2 unused
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   471
 * @return error or cost of operation
1782
48749e4c2dc6 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   472
 */
6943
1914f26aee04 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 6718
diff changeset
   473
CommandCost CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
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
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
3310
a19f247b75b6 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3279
diff changeset
   477
	if (!IsOwnedLandTile(tile)) return CMD_ERROR;
1878
980fabc7d8a5 (svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents: 1796
diff changeset
   478
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
980fabc7d8a5 (svn r2384) - Fix: Check selling land and setting player colour. Also an extra map-bounds check for terraforming; inspired by the monkey (and Tron :) )
Darkvater
parents: 1796
diff changeset
   479
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
7727
5aaf86199444 (svn r11262) -Fix [FS#1330]: do not check for vehicles that are not on the ground when removing owned land, furthermore do not check for shadows (of aircraft).
rubidium
parents: 7637
diff changeset
   481
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
4000
4009d092b306 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
   483
	if (flags & DC_EXEC) DoClearSquare(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
7977
4a4e11757be5 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 7727
diff changeset
   485
	return CommandCost(- _price.clear_roughland * 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   486
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   489
#include "table/clear_land.h"
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
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2221
diff changeset
   492
void DrawClearLandTile(const TileInfo *ti, byte set)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
{
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   494
	DrawGroundSprite(SPR_FLAT_BARE_LAND + _tileh_to_sprite[ti->tileh] + set * 19, PAL_NONE);
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
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2221
diff changeset
   497
void DrawHillyLandTile(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
{
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   499
	if (ti->tileh != SLOPE_FLAT) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   500
		DrawGroundSprite(SPR_FLAT_ROUGH_LAND + _tileh_to_sprite[ti->tileh], PAL_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
	} else {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   502
		DrawGroundSprite(_landscape_clear_sprites[GB(ti->x ^ ti->y, 4, 3)], PAL_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
2220
cacd492f3c1c (svn r2738) Small bit fiddling cleanup
tron
parents: 2186
diff changeset
   506
void DrawClearLandFence(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   507
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
	byte z = ti->z;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   509
3636
a36cc46e754d (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   510
	if (ti->tileh & SLOPE_S) {
3645
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   511
		z += TILE_HEIGHT;
7f950533d510 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   512
		if (ti->tileh == SLOPE_STEEP_S) z += TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   514
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   515
	if (GetFenceSW(ti->tile) != 0) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   516
		DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSW(ti->tile) - 1] + _fence_mod_by_tileh[ti->tileh], PAL_NONE, ti->x, ti->y, z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   517
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   518
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   519
	if (GetFenceSE(ti->tile) != 0) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   520
		DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSE(ti->tile) - 1] + _fence_mod_by_tileh_2[ti->tileh], PAL_NONE, ti->x, ti->y, z);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   521
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   523
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
static void DrawTile_Clear(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   525
{
3166
91e9fc028c95 (svn r3794) Use already available accessor functions instead of GB()
tron
parents: 3156
diff changeset
   526
	switch (GetClearGround(ti->tile)) {
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   527
		case CLEAR_GRASS:
3166
91e9fc028c95 (svn r3794) Use already available accessor functions instead of GB()
tron
parents: 3156
diff changeset
   528
			DrawClearLandTile(ti, GetClearDensity(ti->tile));
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   529
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   531
		case CLEAR_ROUGH:
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   532
			DrawHillyLandTile(ti);
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   533
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   534
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   535
		case CLEAR_ROCKS:
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   536
			DrawGroundSprite(SPR_FLAT_ROCKY_LAND_1 + _tileh_to_sprite[ti->tileh], PAL_NONE);
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   537
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   539
		case CLEAR_FIELDS:
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   540
			DrawGroundSprite(_clear_land_sprites_1[GetFieldType(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE);
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   541
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   543
		case CLEAR_SNOW:
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   544
			DrawGroundSprite(_clear_land_sprites_2[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE);
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   545
			break;
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   546
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   547
		case CLEAR_DESERT:
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   548
			DrawGroundSprite(_clear_land_sprites_3[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE);
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   549
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   551
2220
cacd492f3c1c (svn r2738) Small bit fiddling cleanup
tron
parents: 2186
diff changeset
   552
	DrawClearLandFence(ti);
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4815
diff changeset
   553
	DrawBridgeMiddle(ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   555
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   556
static uint GetSlopeZ_Clear(TileIndex tile, uint x, uint y)
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   557
{
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   558
	uint z;
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   559
	Slope tileh = GetTileSlope(tile, &z);
4231
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   560
2823b3643862 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   561
	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   562
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7317
diff changeset
   564
static Foundation GetFoundation_Clear(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   565
{
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7317
diff changeset
   566
	return FOUNDATION_NONE;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   567
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   568
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   569
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   570
{
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   571
	/* unused */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   572
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   573
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   574
static void AnimateTile_Clear(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   575
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   576
	/* unused */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   577
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
1293
be96e2bf9b3c (svn r1797) Clean up TileLoopClearHelper() a bit:
tron
parents: 1209
diff changeset
   579
void TileLoopClearHelper(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
{
2221
de4a862fa8e2 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   581
	byte self;
de4a862fa8e2 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   582
	byte neighbour;
1293
be96e2bf9b3c (svn r1797) Clean up TileLoopClearHelper() a bit:
tron
parents: 1209
diff changeset
   583
	TileIndex dirty = INVALID_TILE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   585
	self = (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   587
	neighbour = (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CLEAR_FIELDS));
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   588
	if (GetFenceSW(tile) == 0) {
2221
de4a862fa8e2 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   589
		if (self != neighbour) {
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   590
			SetFenceSW(tile, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
			dirty = tile;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   592
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
	} else {
2221
de4a862fa8e2 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   594
		if (self == 0 && neighbour == 0) {
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   595
			SetFenceSW(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
			dirty = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   597
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   598
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   600
	neighbour = (IsTileType(TILE_ADDXY(tile, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 0, 1), CLEAR_FIELDS));
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   601
	if (GetFenceSE(tile) == 0) {
2221
de4a862fa8e2 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   602
		if (self != neighbour) {
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   603
			SetFenceSE(tile, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
			dirty = tile;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   605
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
	} else {
2221
de4a862fa8e2 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   607
		if (self == 0 && neighbour == 0) {
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   608
			SetFenceSE(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
			dirty = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   610
		}
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
2221
de4a862fa8e2 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   613
	if (dirty != INVALID_TILE) MarkTileDirtyByTile(dirty);
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
/* convert into snowy tiles */
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   618
static void TileLoopClearAlps(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
{
6343
76d17f784c13 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6248
diff changeset
   620
	int k = GetTileZ(tile) - GetSnowLine() + TILE_HEIGHT;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   621
4157
8d0051fdde68 (svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents: 4069
diff changeset
   622
	if (k < 0) { // well below the snow line
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   623
		if (!IsClearGround(tile, CLEAR_SNOW)) return;
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   624
		if (GetClearDensity(tile) == 0) SetClearGroundDensity(tile, CLEAR_GRASS, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
	} else {
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   626
		if (!IsClearGround(tile, CLEAR_SNOW)) {
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   627
			SetClearGroundDensity(tile, CLEAR_SNOW, 0);
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   628
		} else {
4157
8d0051fdde68 (svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents: 4069
diff changeset
   629
			uint density = min((uint)k / TILE_HEIGHT, 3);
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   630
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   631
			if (GetClearDensity(tile) < density) {
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   632
				AddClearDensity(tile, 1);
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   633
			} else if (GetClearDensity(tile) > density) {
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   634
				AddClearDensity(tile, -1);
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   635
			} else {
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   636
				return;
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   637
			}
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   638
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   639
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   641
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   642
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   643
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   644
static void TileLoopClearDesert(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   645
{
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   646
	if (IsClearGround(tile, CLEAR_DESERT)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
3379
50b253bb9819 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3310
diff changeset
   648
	if (GetTropicZone(tile) == TROPICZONE_DESERT) {
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   649
		SetClearGroundDensity(tile, CLEAR_DESERT, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
	} else {
3379
50b253bb9819 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3310
diff changeset
   651
		if (GetTropicZone(tile + TileDiffXY( 1,  0)) != TROPICZONE_DESERT &&
50b253bb9819 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3310
diff changeset
   652
				GetTropicZone(tile + TileDiffXY(-1,  0)) != TROPICZONE_DESERT &&
50b253bb9819 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3310
diff changeset
   653
				GetTropicZone(tile + TileDiffXY( 0,  1)) != TROPICZONE_DESERT &&
50b253bb9819 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3310
diff changeset
   654
				GetTropicZone(tile + TileDiffXY( 0, -1)) != TROPICZONE_DESERT)
1981
3c9c682f1212 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   655
			return;
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   656
		SetClearGroundDensity(tile, CLEAR_DESERT, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   657
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   659
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   660
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   661
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   662
static void TileLoop_Clear(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   663
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   664
	TileLoopClearHelper(tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   665
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2979
diff changeset
   666
	switch (_opt.landscape) {
6357
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
   667
		case LT_TROPIC: TileLoopClearDesert(tile); break;
f0f5e7d1713c (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6343
diff changeset
   668
		case LT_ARCTIC: TileLoopClearAlps(tile);   break;
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
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   671
	switch (GetClearGround(tile)) {
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   672
		case CLEAR_GRASS:
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   673
			if (GetClearDensity(tile) == 3) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   674
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   675
			if (_game_mode != GM_EDITOR) {
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   676
				if (GetClearCounter(tile) < 7) {
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   677
					AddClearCounter(tile, 1);
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   678
					return;
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   679
				} else {
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   680
					SetClearCounter(tile, 0);
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   681
					AddClearDensity(tile, 1);
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   682
				}
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   683
			} else {
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   684
				SetClearGroundDensity(tile, GB(Random(), 0, 8) > 21 ? CLEAR_GRASS : CLEAR_ROUGH, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   685
			}
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   686
			break;
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   687
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   688
		case CLEAR_FIELDS: {
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   689
			uint field_type;
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   690
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   691
			if (_game_mode == GM_EDITOR) return;
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   692
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   693
			if (GetClearCounter(tile) < 7) {
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   694
				AddClearCounter(tile, 1);
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   695
				return;
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   696
			} else {
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   697
				SetClearCounter(tile, 0);
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   698
			}
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   699
4333
050e8ea8f3bb (svn r6032) -Fix: when a farm is gone, remove the fields when it is full grown and should be harvest (not before that)
truelight
parents: 4328
diff changeset
   700
			if (GetIndustryIndexOfField(tile) == INVALID_INDUSTRY && GetFieldType(tile) >= 7) {
4328
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4300
diff changeset
   701
				/* This farmfield is no longer farmfield, so make it grass again */
4815
d702c4027451 (svn r6739) -Fix (r6001): Crash on removing farmland belonging to a farm. The search would loop
Darkvater
parents: 4560
diff changeset
   702
				MakeClear(tile, CLEAR_GRASS, 2);
4328
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4300
diff changeset
   703
			} else {
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4300
diff changeset
   704
				field_type = GetFieldType(tile);
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4300
diff changeset
   705
				field_type = (field_type < 8) ? field_type + 1 : 0;
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4300
diff changeset
   706
				SetFieldType(tile, field_type);
1b3940c35724 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 4300
diff changeset
   707
			}
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   708
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   709
		}
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   710
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   711
		default:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   712
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   713
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   714
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
	MarkTileDirtyByTile(tile);
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
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6160
diff changeset
   718
void GenerateClearTile()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   719
{
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   720
	uint i, gi;
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   721
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   723
	/* add rough tiles */
2635
7ed07303448d (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2537
diff changeset
   724
	i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   725
	gi = ScaleByMapSize(GB(Random(), 0, 7) + 0x80);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   726
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   727
	SetGeneratingWorldProgress(GWP_ROUGH_ROCKY, gi + i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   728
	do {
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   729
		IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY);
2051
e369160ce2f3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
   730
		tile = RandomTile();
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   731
		if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) SetClearGroundDensity(tile, CLEAR_ROUGH, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   732
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   733
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   734
	/* add rocky tiles */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   735
	i = gi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
	do {
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   737
		uint32 r = Random();
2051
e369160ce2f3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
   738
		tile = RandomTileSeed(r);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   739
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   740
		IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   741
		if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) {
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   742
			uint j = GB(r, 16, 4) + 5;
2951
2de6d3a59743 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   743
			for (;;) {
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   744
				TileIndex tile_new;
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   745
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   746
				SetClearGroundDensity(tile, CLEAR_ROCKS, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   747
				do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
					if (--j == 0) goto get_out;
7317
e61af9d8a2b3 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 7313
diff changeset
   749
					tile_new = tile + TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2));
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   750
				} while (!IsTileType(tile_new, MP_CLEAR) || IsClearGround(tile_new, CLEAR_DESERT));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   751
				tile = tile_new;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   752
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
get_out:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   754
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   758
static void ClickTile_Clear(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
6683
b88ae30866ce (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6491
diff changeset
   763
static uint32 GetTileTrackStatus_Clear(TileIndex tile, TransportType mode, uint sub_mode)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   765
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   766
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
2220
cacd492f3c1c (svn r2738) Small bit fiddling cleanup
tron
parents: 2186
diff changeset
   768
static const StringID _clear_land_str[] = {
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   769
	STR_080D_GRASS,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
	STR_080B_ROUGH_LAND,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   771
	STR_080A_ROCKS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
	STR_080E_FIELDS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
	STR_080F_SNOW_COVERED_LAND,
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   774
	STR_0810_DESERT
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
1977
37bbebf94434 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   777
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
{
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   779
	if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) == 0) {
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   780
		td->str = STR_080C_BARE_LAND;
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   781
	} else {
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   782
		td->str = _clear_land_str[GetClearGround(tile)];
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   783
	}
1901
03bf9bf99319 (svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents: 1891
diff changeset
   784
	td->owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   785
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2221
diff changeset
   787
static void ChangeTileOwner_Clear(TileIndex tile, PlayerID old_player, PlayerID new_player)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   788
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
	return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6160
diff changeset
   792
void InitializeClearLand()
1093
4fdc46eaf423 (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   793
{
3422
a6eba3443452 (svn r4249) -Codechange: Replace more occurences of 16 by TILE_SIZE and of 8 by TILE_HEIGHT. Reverted one change from the previous commit because it was faulty
celestar
parents: 3418
diff changeset
   794
	_opt.snow_line = _patches.snow_line_height * TILE_HEIGHT;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   795
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   796
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   797
static CommandCost TerraformTile_Clear(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   798
{
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   799
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   800
}
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   801
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   802
extern const TileTypeProcs _tile_type_clear_procs = {
6123
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   803
	DrawTile_Clear,           ///< draw_tile_proc
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   804
	GetSlopeZ_Clear,          ///< get_slope_z_proc
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   805
	ClearTile_Clear,          ///< clear_tile_proc
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   806
	GetAcceptedCargo_Clear,   ///< get_accepted_cargo_proc
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   807
	GetTileDesc_Clear,        ///< get_tile_desc_proc
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   808
	GetTileTrackStatus_Clear, ///< get_tile_track_status_proc
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   809
	ClickTile_Clear,          ///< click_tile_proc
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   810
	AnimateTile_Clear,        ///< animate_tile_proc
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   811
	TileLoop_Clear,           ///< tile_loop_clear
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   812
	ChangeTileOwner_Clear,    ///< change_tile_owner_clear
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   813
	NULL,                     ///< get_produced_cargo_proc
04eb770ec17e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6106
diff changeset
   814
	NULL,                     ///< vehicle_enter_tile_proc
7335
141c6b86ec1f (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7317
diff changeset
   815
	GetFoundation_Clear,      ///< get_foundation_proc
7494
ab05bad37410 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7487
diff changeset
   816
	TerraformTile_Clear,      ///< terraform_tile_proc
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   817
};