src/clear_cmd.cpp
author rubidium
Mon, 07 Jan 2008 00:19:09 +0000
changeset 8704 2857ec554839
parent 8692 5408c091b204
child 8706 e76561c3dd66
permissions -rw-r--r--
(svn r11771) -Codechange: split settings.h into better separated headers.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
     3
/** @file clear_cmd.cpp */
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1878
diff changeset
     6
#include "openttd.h"
3144
426b825578f9 (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
caf4fcb4e05b (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
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 473
diff changeset
     9
#include "table/strings.h"
2154
63a6b880b4c0 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2153
diff changeset
    10
#include "player.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "viewport.h"
8612
6414fc21c2f3 (svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents: 8604
diff changeset
    12
#include "command_func.h"
3156
028b6756b279 (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
    13
#include "tunnel_map.h"
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4815
diff changeset
    14
#include "bridge_map.h"
6486
4f8af35b11eb (svn r8908) -Codechange: declaration of DrawBridgeMiddle does not belong in a map accessors header.
rubidium
parents: 6449
diff changeset
    15
#include "bridge.h"
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6574
diff changeset
    16
#include "landscape.h"
2153
91e89aa8c299 (svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents: 2150
diff changeset
    17
#include "variables.h"
2517
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2436
diff changeset
    18
#include "table/sprites.h"
3310
7339b2b1e957 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3279
diff changeset
    19
#include "unmovable_map.h"
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
    20
#include "genworld.h"
4328
23dd79414386 (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
    21
#include "industry.h"
7470
73cfc62015c9 (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: 7468
diff changeset
    22
#include "water_map.h"
8615
6b91ca653bad (svn r11680) -Codechange: refactor more out of openttd.h and functions.h.
rubidium
parents: 8612
diff changeset
    23
#include "tile_cmd.h"
8627
448ebf3a8291 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8615
diff changeset
    24
#include "functions.h"
8634
5ffca02f9115 (svn r11700) -Codechange: reduce the amount of unnecessary includes.
rubidium
parents: 8627
diff changeset
    25
#include "economy_func.h"
8640
1e93b81e96d2 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8635
diff changeset
    26
#include "vehicle_func.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    28
/*
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    29
 * In one terraforming command all four corners of a initial tile can be raised/lowered (though this is not available to the player).
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    30
 * The maximal amount of height modifications is archieved when raising a complete flat land from sea level to MAX_TILE_HEIGHT or vice versa.
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    31
 * This affects all corners with a manhatten distance smaller than MAX_TILE_HEIGHT to one of the initial 4 corners.
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    32
 * Their maximal amount is computed to 4 * \sum_{i=1}^{h_max} i  =  2 * h_max * (h_max + 1).
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    33
 */
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    34
static const int TERRAFORMER_MODHEIGHT_SIZE = 2 * MAX_TILE_HEIGHT * (MAX_TILE_HEIGHT + 1);
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    35
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    36
/*
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    37
 * The maximal amount of affected tiles (i.e. the tiles that incident with one of the corners above, is computed similiar to
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    38
 * 1 + 4 * \sum_{i=1}^{h_max} (i+1)  =  1 + 2 * h_max + (h_max + 3).
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    39
 */
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    40
static const int TERRAFORMER_TILE_TABLE_SIZE = 1 + 2 * MAX_TILE_HEIGHT * (MAX_TILE_HEIGHT + 3);
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    41
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    42
struct TerraformerHeightMod {
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    43
	TileIndex tile;   ///< Referenced tile.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    44
	byte height;      ///< New TileHeight (height of north corner) of the tile.
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    45
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    47
struct TerraformerState {
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    48
	int modheight_count;                                         ///< amount of entries in "modheight".
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    49
	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
    50
8041
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8013
diff changeset
    51
	/**
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8013
diff changeset
    52
	 * Dirty tiles, i.e.\ at least one corner changed.
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8013
diff changeset
    53
	 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8013
diff changeset
    54
	 * This array contains the tiles which are or will be marked as dirty.
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8013
diff changeset
    55
	 *
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8013
diff changeset
    56
	 * @ingroup dirty
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8013
diff changeset
    57
	 */
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8013
diff changeset
    58
	TileIndex tile_table[TERRAFORMER_TILE_TABLE_SIZE];
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    59
	TerraformerHeightMod modheight[TERRAFORMER_MODHEIGHT_SIZE];  ///< Height modifications.
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6573
diff changeset
    60
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    61
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    62
/**
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    63
 * Gets the TileHeight (height of north corner) of a tile as of current terraforming progress.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    64
 *
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    65
 * @param ts TerraformerState.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    66
 * @param tile Tile.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    67
 * @return TileHeight.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    68
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    69
static int TerraformGetHeightOfTile(TerraformerState *ts, TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    70
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    71
	TerraformerHeightMod *mod = ts->modheight;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    72
	int count;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
    73
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    74
	for (count = ts->modheight_count; count != 0; count--, mod++) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
    75
		if (mod->tile == tile) return mod->height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    76
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    77
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    78
	/* TileHeight unchanged so far, read value from map. */
1044
9b73df700a7c (svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents: 1035
diff changeset
    79
	return TileHeight(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    80
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    81
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
    82
/**
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    83
 * Stores the TileHeight (height of north corner) of a tile in a TerraformerState.
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    84
 *
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    85
 * @param ts TerraformerState.
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    86
 * @param tile Tile.
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    87
 * @param height New TileHeight.
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    88
 */
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    89
static void TerraformSetHeightOfTile(TerraformerState *ts, TileIndex tile, int height)
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    90
{
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    91
	/* Find tile in the "modheight" table.
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    92
	 * Note: In a normal user-terraform command the tile will not be found in the "modheight" table.
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    93
	 *       But during house- or industry-construction multiple corners can be terraformed at once. */
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    94
	TerraformerHeightMod *mod = ts->modheight;
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    95
	int count = ts->modheight_count;
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    96
	while ((count > 0) && (mod->tile != tile)) {
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    97
		mod++;
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    98
		count--;
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
    99
	}
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   100
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   101
	/* New entry? */
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   102
	if (count == 0) {
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   103
		assert(ts->modheight_count < TERRAFORMER_MODHEIGHT_SIZE);
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   104
		ts->modheight_count++;
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   105
	}
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   106
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   107
	/* Finally store the new value */
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   108
	mod->tile = tile;
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   109
	mod->height = (byte)height;
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   110
}
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   111
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   112
/**
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   113
 * Adds a tile to the "tile_table" in a TerraformerState.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   114
 *
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   115
 * @param ts TerraformerState.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   116
 * @param tile Tile.
8041
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8013
diff changeset
   117
 * @ingroup dirty
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   118
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
static void TerraformAddDirtyTile(TerraformerState *ts, TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
	int count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
	TileIndex *t;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	count = ts->tile_table_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6683
diff changeset
   126
	for (t = ts->tile_table; count != 0; count--, t++) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   127
		if (*t == tile) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   130
	assert(ts->tile_table_count < TERRAFORMER_TILE_TABLE_SIZE);
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   131
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
	ts->tile_table[ts->tile_table_count++] = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   135
/**
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   136
 * Adds all tiles that incident with the north corner of a specific tile to the "tile_table" in a TerraformerState.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   137
 *
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   138
 * @param ts TerraformerState.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   139
 * @param tile Tile.
8041
63e760418a15 (svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents: 8013
diff changeset
   140
 * @ingroup dirty
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   141
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
static void TerraformAddDirtyTileAround(TerraformerState *ts, TileIndex tile)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
{
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   144
	TerraformAddDirtyTile(ts, tile + TileDiffXY( 0, -1));
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   145
	TerraformAddDirtyTile(ts, tile + TileDiffXY(-1, -1));
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   146
	TerraformAddDirtyTile(ts, tile + TileDiffXY(-1,  0));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
	TerraformAddDirtyTile(ts, tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   150
/**
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   151
 * Terraform the north corner of a tile to a specific height.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   152
 *
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   153
 * @param ts TerraformerState.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   154
 * @param tile Tile.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   155
 * @param height Aimed height.
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   156
 * @param return Error code or cost.
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   157
 */
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   158
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
   159
{
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   160
	CommandCost total_cost = CommandCost();
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   161
863
8d09f9331a80 (svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents: 856
diff changeset
   162
	assert(tile < MapSize());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   164
	/* Check range of destination height */
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   165
	if (height < 0) return_cmd_error(STR_1003_ALREADY_AT_SEA_LEVEL);
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   166
	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
   167
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   168
	/*
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   169
	 * Check if the terraforming has any effect.
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   170
	 * This can only be true, if multiple corners of the start-tile are terraformed (i.e. the terraforming is done by towns/industries etc.).
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   171
	 * In this case the terraforming should fail. (Don't know why.)
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   172
	 */
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   173
	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
   174
7983
06d272a9618b (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: 7976
diff changeset
   175
	/* Check "too close to edge of map" */
06d272a9618b (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: 7976
diff changeset
   176
	uint x = TileX(tile);
06d272a9618b (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: 7976
diff changeset
   177
	uint y = TileY(tile);
06d272a9618b (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: 7976
diff changeset
   178
	if ((x <= 1) || (y <= 1) || (x >= MapMaxX() - 1) || (y >= MapMaxY() - 1)) {
06d272a9618b (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: 7976
diff changeset
   179
		/*
06d272a9618b (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: 7976
diff changeset
   180
		 * Determine a sensible error tile
06d272a9618b (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: 7976
diff changeset
   181
		 * Note: If x and y are both zero this will disable the error tile. (Tile 0 cannot be highlighted :( )
06d272a9618b (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: 7976
diff changeset
   182
		 */
06d272a9618b (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: 7976
diff changeset
   183
		if ((x == 1) && (y != 0)) x = 0;
06d272a9618b (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: 7976
diff changeset
   184
		if ((y == 1) && (x != 0)) y = 0;
06d272a9618b (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: 7976
diff changeset
   185
		_terraform_err_tile = TileXY(x, y);
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   186
		return_cmd_error(STR_0002_TOO_CLOSE_TO_EDGE_OF_MAP);
7983
06d272a9618b (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: 7976
diff changeset
   187
	}
06d272a9618b (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: 7976
diff changeset
   188
06d272a9618b (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: 7976
diff changeset
   189
	/* Mark incident tiles, that are involved in the terraforming */
06d272a9618b (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: 7976
diff changeset
   190
	TerraformAddDirtyTileAround(ts, tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   192
	/* Store the height modification */
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   193
	TerraformSetHeightOfTile(ts, tile, height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   195
	/* Increment cost */
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   196
	total_cost.AddCost(_price.terraform);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   197
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   198
	/* 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
   199
	{
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   200
		const TileIndexDiffC *ttm;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   202
		static const TileIndexDiffC _terraform_tilepos[] = {
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   203
			{ 1,  0}, // move to tile in SE
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   204
			{-2,  0}, // undo last move, and move to tile in NW
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   205
			{ 1,  1}, // undo last move, and move to tile in SW
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   206
			{ 0, -2}  // undo last move, and move to tile in NE
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   207
		};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   209
		for (ttm = _terraform_tilepos; ttm != endof(_terraform_tilepos); ttm++) {
909
81bc9ef93f50 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
   210
			tile += ToTileIndexDiff(*ttm);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   212
			/* Get TileHeight of neighboured tile as of current terraform progress */
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   213
			int r = TerraformGetHeightOfTile(ts, tile);
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   214
			int height_diff = height - r;
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   215
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   216
			/* Is the height difference to the neighboured corner greater than 1? */
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   217
			if (abs(height_diff) > 1) {
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   218
				/* Terraform the neighboured corner. The resulting height difference should be 1. */
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   219
				height_diff += (height_diff < 0 ? 1 : -1);
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   220
				CommandCost cost = TerraformTileHeight(ts, tile, r + height_diff);
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   221
				if (CmdFailed(cost)) return cost;
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   222
				total_cost.AddCost(cost);
0
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
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   227
	return total_cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1571
diff changeset
   230
/** Terraform land
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   231
 * @param tile tile to terraform
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   232
 * @param flags for this command type
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   233
 * @param p1 corners to terraform (SLOPE_xxx)
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   234
 * @param p2 direction; eg up (non-zero) or down (zero)
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   235
 * @return error or cost of terraforming
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7214
diff changeset
   237
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
   238
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
	TerraformerState ts;
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   240
	CommandCost total_cost = CommandCost();
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   241
	int direction = (p2 != 0 ? 1 : -1);
0
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
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
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
	_terraform_err_tile = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
	ts.modheight_count = ts.tile_table_count = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
1878
622765748231 (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
	/* Make an extra check for map-bounds cause we add tiles to the originating tile */
2934
3b7eef9871f8 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2705
diff changeset
   250
	if (tile + TileDiffXY(1, 1) >= MapSize()) return CMD_ERROR;
1878
622765748231 (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
   251
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   252
	/* Compute the costs and the terraforming result in a model of the landscape */
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   253
	if ((p1 & SLOPE_W) != 0) {
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   254
		TileIndex t = tile + TileDiffXY(1, 0);
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   255
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   256
		if (CmdFailed(cost)) return cost;
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   257
		total_cost.AddCost(cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   260
	if ((p1 & SLOPE_S) != 0) {
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   261
		TileIndex t = tile + TileDiffXY(1, 1);
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   262
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   263
		if (CmdFailed(cost)) return cost;
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   264
		total_cost.AddCost(cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   267
	if ((p1 & SLOPE_E) != 0) {
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   268
		TileIndex t = tile + TileDiffXY(0, 1);
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   269
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   270
		if (CmdFailed(cost)) return cost;
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   271
		total_cost.AddCost(cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   274
	if ((p1 & SLOPE_N) != 0) {
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   275
		TileIndex t = tile + TileDiffXY(0, 0);
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   276
		CommandCost cost = TerraformTileHeight(&ts, t, TileHeight(t) + direction);
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   277
		if (CmdFailed(cost)) return cost;
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   278
		total_cost.AddCost(cost);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
7983
06d272a9618b (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: 7976
diff changeset
   281
	/* Check if the terraforming is valid wrt. tunnels, bridges and objects on the surface */
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4815
diff changeset
   282
	{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
		int count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
		TileIndex *ti = ts.tile_table;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   285
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1571
diff changeset
   286
		for (count = ts.tile_table_count; count != 0; count--, ti++) {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   287
			TileIndex tile = *ti;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
7983
06d272a9618b (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: 7976
diff changeset
   289
			/* Find new heights of tile corners */
06d272a9618b (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: 7976
diff changeset
   290
			uint z_N = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 0));
06d272a9618b (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: 7976
diff changeset
   291
			uint z_W = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 0));
06d272a9618b (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: 7976
diff changeset
   292
			uint z_S = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(1, 1));
06d272a9618b (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: 7976
diff changeset
   293
			uint z_E = TerraformGetHeightOfTile(&ts, tile + TileDiffXY(0, 1));
06d272a9618b (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: 7976
diff changeset
   294
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   295
			/* Find min and max height of tile */
7983
06d272a9618b (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: 7976
diff changeset
   296
			uint z_min = min(min(z_N, z_W), min(z_S, z_E));
06d272a9618b (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: 7976
diff changeset
   297
			uint z_max = max(max(z_N, z_W), max(z_S, z_E));
7214
ae8dcfa02ec8 (svn r9950) -Feature(tte): allow terraforming under bridges.
rubidium
parents: 7179
diff changeset
   298
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   299
			/* Compute tile slope */
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   300
			uint tileh = (z_max > z_min + 1 ? SLOPE_STEEP : SLOPE_FLAT);
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   301
			if (z_W > z_min) tileh += SLOPE_W;
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   302
			if (z_S > z_min) tileh += SLOPE_S;
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   303
			if (z_E > z_min) tileh += SLOPE_E;
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   304
			if (z_N > z_min) tileh += SLOPE_N;
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   305
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   306
			/* Check if bridge would take damage */
7214
ae8dcfa02ec8 (svn r9950) -Feature(tte): allow terraforming under bridges.
rubidium
parents: 7179
diff changeset
   307
			if (direction == 1 && MayHaveBridgeAbove(tile) && IsBridgeAbove(tile) &&
ae8dcfa02ec8 (svn r9950) -Feature(tte): allow terraforming under bridges.
rubidium
parents: 7179
diff changeset
   308
					GetBridgeHeight(GetSouthernBridgeEnd(tile)) <= z_max * TILE_HEIGHT) {
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   309
				_terraform_err_tile = tile; // highlight the tile under the bridge
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4815
diff changeset
   310
				return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4815
diff changeset
   311
			}
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   312
			/* Check if tunnel would take damage */
7214
ae8dcfa02ec8 (svn r9950) -Feature(tte): allow terraforming under bridges.
rubidium
parents: 7179
diff changeset
   313
			if (direction == -1 && IsTunnelInWay(tile, z_min * TILE_HEIGHT)) {
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   314
				_terraform_err_tile = tile; // highlight the tile above the tunnel
7214
ae8dcfa02ec8 (svn r9950) -Feature(tte): allow terraforming under bridges.
rubidium
parents: 7179
diff changeset
   315
				return_cmd_error(STR_1002_EXCAVATION_WOULD_DAMAGE);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   316
			}
7983
06d272a9618b (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: 7976
diff changeset
   317
			/* Check tiletype-specific things, and add extra-cost */
8133
597f682ff48d (svn r11168) -Fix [FS#1256]: assert on terraforming of industries. Patch by frosch.
rubidium
parents: 8041
diff changeset
   318
			CommandCost cost = _tile_type_procs[GetTileType(tile)]->terraform_tile_proc(tile, flags | DC_AUTO, z_min * TILE_HEIGHT, (Slope) tileh);
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   319
			if (CmdFailed(cost)) {
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   320
				_terraform_err_tile = tile;
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   321
				return cost;
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   322
			}
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   323
			total_cost.AddCost(cost);
0
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
	if (flags & DC_EXEC) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
		/* change the height */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
			int count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
			TerraformerHeightMod *mod;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
			mod = ts.modheight;
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1571
diff changeset
   334
			for (count = ts.modheight_count; count != 0; count--, mod++) {
1979
f4462d4e8e62 (svn r2485) Missed two uint -> TileIndex, thanks _Luca_
tron
parents: 1977
diff changeset
   335
				TileIndex til = mod->tile;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   336
1059
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1044
diff changeset
   337
				SetTileHeight(til, mod->height);
0
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
		}
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
		/* finally mark the dirty tiles dirty */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   342
		{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   343
			int count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   344
			TileIndex *ti = ts.tile_table;
1775
08ff0f12ccdc (svn r2279) - Fix: Check the parameters of the first 10 Commands. While there also add proper comments for the functions and fix up CmdFailed()
Darkvater
parents: 1571
diff changeset
   345
			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
   346
				MarkTileDirtyByTile(*ti);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   348
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	}
8013
67c6bcc81914 (svn r11032) -Codechange: unmagicify some table sizes and removal of some unnecessary variables. Patch by frosch.
rubidium
parents: 8005
diff changeset
   350
	return total_cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
1796
cae31916ae54 (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
   354
/** Levels a selected (rectangle) area of land
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   355
 * @param tile end tile of area-drag
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   356
 * @param flags for this command type
1796
cae31916ae54 (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
   357
 * @param p1 start tile of area drag
8692
5408c091b204 (svn r11759) -Feature: Add drag-n-drop support to the raise/lower land tools. Land is raised/lowered at the start and the rest of the area levelled to match. Patch by Roujin.
peter1138
parents: 8640
diff changeset
   358
 * @param p2 height difference; eg raise (+1), lower (-1) or level (0)
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   359
 * @return  error or cost of terraforming
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7214
diff changeset
   361
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
   362
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
	int size_x, size_y;
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   364
	int ex;
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   365
	int ey;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
	int sx, sy;
8692
5408c091b204 (svn r11759) -Feature: Add drag-n-drop support to the raise/lower land tools. Land is raised/lowered at the start and the rest of the area levelled to match. Patch by Roujin.
peter1138
parents: 8640
diff changeset
   367
	uint h, oldh, curh;
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   368
	CommandCost money;
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7214
diff changeset
   369
	CommandCost ret;
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7214
diff changeset
   370
	CommandCost cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
2934
3b7eef9871f8 (svn r3490) -Fix: A bunch (10) of off-by-one errors when checking if a TileIndex points to a tile on the map
tron
parents: 2705
diff changeset
   372
	if (p1 >= MapSize()) return CMD_ERROR;
1796
cae31916ae54 (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
   373
889
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 863
diff changeset
   374
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
7f8630bfea41 (svn r1375) -Fix: [1050990] Buying trains sometimes accounted for incorrectly. Was the result of the cost getting reset in a recursive call of docommand. That is fixed. In addition all cost-commands are typed explicitely. Please do not forget to do so or your costs will be credited to construction if you are unlucky.
darkvater
parents: 863
diff changeset
   375
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   376
	/* remember level height */
8692
5408c091b204 (svn r11759) -Feature: Add drag-n-drop support to the raise/lower land tools. Land is raised/lowered at the start and the rest of the area levelled to match. Patch by Roujin.
peter1138
parents: 8640
diff changeset
   377
	oldh = TileHeight(p1);
5408c091b204 (svn r11759) -Feature: Add drag-n-drop support to the raise/lower land tools. Land is raised/lowered at the start and the rest of the area levelled to match. Patch by Roujin.
peter1138
parents: 8640
diff changeset
   378
5408c091b204 (svn r11759) -Feature: Add drag-n-drop support to the raise/lower land tools. Land is raised/lowered at the start and the rest of the area levelled to match. Patch by Roujin.
peter1138
parents: 8640
diff changeset
   379
	/* compute new height */
5408c091b204 (svn r11759) -Feature: Add drag-n-drop support to the raise/lower land tools. Land is raised/lowered at the start and the rest of the area levelled to match. Patch by Roujin.
peter1138
parents: 8640
diff changeset
   380
	h = oldh + p2;
5408c091b204 (svn r11759) -Feature: Add drag-n-drop support to the raise/lower land tools. Land is raised/lowered at the start and the rest of the area levelled to match. Patch by Roujin.
peter1138
parents: 8640
diff changeset
   381
5408c091b204 (svn r11759) -Feature: Add drag-n-drop support to the raise/lower land tools. Land is raised/lowered at the start and the rest of the area levelled to match. Patch by Roujin.
peter1138
parents: 8640
diff changeset
   382
	/* Check range of destination height */
5408c091b204 (svn r11759) -Feature: Add drag-n-drop support to the raise/lower land tools. Land is raised/lowered at the start and the rest of the area levelled to match. Patch by Roujin.
peter1138
parents: 8640
diff changeset
   383
	if (h > MAX_TILE_HEIGHT) return_cmd_error((oldh == 0) ? STR_1003_ALREADY_AT_SEA_LEVEL : STR_1004_TOO_HIGH);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   385
	/* make sure sx,sy are smaller than ex,ey */
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   386
	ex = TileX(tile);
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   387
	ey = TileY(tile);
926
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
   388
	sx = TileX(p1);
bd4312619522 (svn r1414) Move TileIndex, TILE_MASK and GET_TILE_[XY] to map.h and turn the latter into inline functions names Tile[XY]
tron
parents: 909
diff changeset
   389
	sy = TileY(p1);
6432
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 5919
diff changeset
   390
	if (ex < sx) Swap(ex, sx);
8fb778a7f2d7 (svn r8841) -Fix
tron
parents: 5919
diff changeset
   391
	if (ey < sy) Swap(ey, sy);
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   392
	tile = TileXY(sx, sy);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   393
6987
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6683
diff changeset
   394
	size_x = ex - sx + 1;
b0f13039bda2 (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6683
diff changeset
   395
	size_y = ey - sy + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   397
	money.AddCost(GetAvailableMoneyForCommand());
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
1796
cae31916ae54 (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
   399
	BEGIN_TILE_LOOP(tile2, size_x, size_y, tile) {
1044
9b73df700a7c (svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents: 1035
diff changeset
   400
		curh = TileHeight(tile2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
		while (curh != h) {
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   402
			ret = DoCommand(tile2, SLOPE_N, (curh > h) ? 0 : 1, flags & ~DC_EXEC, CMD_TERRAFORM_LAND);
1796
cae31916ae54 (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
   403
			if (CmdFailed(ret)) break;
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
			if (flags & DC_EXEC) {
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   406
				money.AddCost(-ret.GetCost());
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   407
				if (money.GetCost() < 0) {
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   408
					_additional_cash_required = ret.GetCost();
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   409
					return cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
				}
7976
5d93386b748b (svn r10991) -Codechange: add documentation, enumification and some code simplifications to the terraforming code. Patch by frosch.
rubidium
parents: 7831
diff changeset
   411
				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
   412
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   414
			cost.AddCost(ret);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
			curh += (curh > h) ? -1 : 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
		}
1796
cae31916ae54 (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
   417
	} 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
   418
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   419
	return (cost.GetCost() == 0) ? CMD_ERROR : cost;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   422
/** Purchase a land area. Actually you only purchase one tile, so
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   423
 * the name is a bit confusing ;p
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   424
 * @param tile the tile the player is purchasing
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   425
 * @param flags for this command type
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   426
 * @param p1 unused
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   427
 * @param p2 unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   428
 * @return error of cost of operation
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7214
diff changeset
   430
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
   431
{
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7214
diff changeset
   432
	CommandCost cost;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   433
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   434
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   435
3310
7339b2b1e957 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3279
diff changeset
   436
	if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   437
		return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT);
3310
7339b2b1e957 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3279
diff changeset
   438
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   439
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   440
	cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   441
	if (CmdFailed(cost)) return CMD_ERROR;
0
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
	if (flags & DC_EXEC) {
3310
7339b2b1e957 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3279
diff changeset
   444
		MakeOwnedLand(tile, _current_player);
7339b2b1e957 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3279
diff changeset
   445
		MarkTileDirtyByTile(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   447
8473
773b817b64d0 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 8223
diff changeset
   448
	return cost.AddCost(_price.clear_roughland * 10);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   449
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   450
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   451
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7214
diff changeset
   452
static CommandCost ClearTile_Clear(TileIndex tile, byte flags)
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   453
{
7449
5cedaf2c861c (svn r10208) -Codechange: replace int32 with Money where appropriate.
rubidium
parents: 7446
diff changeset
   454
	static const Money* clear_price_table[] = {
8473
773b817b64d0 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 8223
diff changeset
   455
		&_price.clear_grass,
773b817b64d0 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 8223
diff changeset
   456
		&_price.clear_roughland,
773b817b64d0 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 8223
diff changeset
   457
		&_price.clear_rocks,
773b817b64d0 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 8223
diff changeset
   458
		&_price.clear_fields,
773b817b64d0 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 8223
diff changeset
   459
		&_price.clear_roughland,
773b817b64d0 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 8223
diff changeset
   460
		&_price.clear_roughland,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	};
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7214
diff changeset
   462
	CommandCost price;
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   463
7446
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   464
	if (!IsClearGround(tile, CLEAR_GRASS) || GetClearDensity(tile) != 0) {
1c4d469f986e (svn r10205) -Codechange: refactor returning of cost, so it can be more easily modified.
rubidium
parents: 7439
diff changeset
   465
		price.AddCost(*clear_price_table[GetClearGround(tile)]);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   466
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
2220
6c186dad8188 (svn r2738) Small bit fiddling cleanup
tron
parents: 2186
diff changeset
   468
	if (flags & DC_EXEC) DoClearSquare(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   470
	return price;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   473
/** Sell a land area. Actually you only sell one tile, so
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   474
 * the name is a bit confusing ;p
3491
4c8427796c64 (svn r4342) Change the first two parameters of commands - virtual pixel coordinates of the tile to operate on - to a TileIndex
tron
parents: 3447
diff changeset
   475
 * @param tile the tile the player is selling
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   476
 * @param flags for this command type
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   477
 * @param p1 unused
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   478
 * @param p2 unused
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   479
 * @return error or cost of operation
1782
0ac16ff36293 (svn r2286) - CodeChange: paramcheck the next batch of commands.
Darkvater
parents: 1775
diff changeset
   480
 */
7439
0c0e2945c890 (svn r10197) -Codechange: replace int32 with CommandCost where appropriate.
rubidium
parents: 7214
diff changeset
   481
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
   482
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
3310
7339b2b1e957 (svn r4073) Add functions to make and test for (most) unmovable tiles
tron
parents: 3279
diff changeset
   485
	if (!IsOwnedLandTile(tile)) return CMD_ERROR;
1878
622765748231 (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
   486
	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR;
622765748231 (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
   487
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   488
8223
6a034093dc1d (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: 8133
diff changeset
   489
	if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
4000
bab1ebc37da0 (svn r5210) Many small changes which piled up: const, unsigned, variable scope, CSE for readability, DeMorgan, if cascades -> switch, whitespace, parentheses, bracing, misc.
tron
parents: 3977
diff changeset
   491
	if (flags & DC_EXEC) DoClearSquare(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   492
8473
773b817b64d0 (svn r11533) -Codechange: Rename some unclear clear_x prices member names.
belugas
parents: 8223
diff changeset
   493
	return CommandCost(- _price.clear_roughland * 2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
}
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
#include "table/clear_land.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   498
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2221
diff changeset
   500
void DrawClearLandTile(const TileInfo *ti, byte set)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   501
{
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   502
	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
   503
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2221
diff changeset
   505
void DrawHillyLandTile(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
{
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   507
	if (ti->tileh != SLOPE_FLAT) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   508
		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
   509
	} else {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   510
		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
   511
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   512
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   513
2220
6c186dad8188 (svn r2738) Small bit fiddling cleanup
tron
parents: 2186
diff changeset
   514
void DrawClearLandFence(const TileInfo *ti)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   515
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   516
	byte z = ti->z;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   517
3636
d87b21df2944 (svn r4541) Add a type for slopes and replace many magic numbers by the appropriate enums
tron
parents: 3491
diff changeset
   518
	if (ti->tileh & SLOPE_S) {
3645
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   519
		z += TILE_HEIGHT;
86af43f87885 (svn r4554) Replace magic numbers by TILE_{HEIGHT,SIZE}
tron
parents: 3636
diff changeset
   520
		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
   521
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   522
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   523
	if (GetFenceSW(ti->tile) != 0) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   524
		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
   525
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   526
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   527
	if (GetFenceSE(ti->tile) != 0) {
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   528
		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
   529
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   530
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   531
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   532
static void DrawTile_Clear(TileInfo *ti)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   533
{
3166
747e74d236f0 (svn r3794) Use already available accessor functions instead of GB()
tron
parents: 3156
diff changeset
   534
	switch (GetClearGround(ti->tile)) {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   535
		case CLEAR_GRASS:
3166
747e74d236f0 (svn r3794) Use already available accessor functions instead of GB()
tron
parents: 3156
diff changeset
   536
			DrawClearLandTile(ti, GetClearDensity(ti->tile));
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   537
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   538
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   539
		case CLEAR_ROUGH:
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   540
			DrawHillyLandTile(ti);
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   541
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   543
		case CLEAR_ROCKS:
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   544
			DrawGroundSprite(SPR_FLAT_ROCKY_LAND_1 + _tileh_to_sprite[ti->tileh], PAL_NONE);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   545
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   547
		case CLEAR_FIELDS:
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   548
			DrawGroundSprite(_clear_land_sprites_1[GetFieldType(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   549
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   551
		case CLEAR_SNOW:
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   552
			DrawGroundSprite(_clear_land_sprites_2[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   553
			break;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   554
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   555
		case CLEAR_DESERT:
5919
2b58160d667d (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5838
diff changeset
   556
			DrawGroundSprite(_clear_land_sprites_3[GetClearDensity(ti->tile)] + _tileh_to_sprite[ti->tileh], PAL_NONE);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   557
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   558
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   559
2220
6c186dad8188 (svn r2738) Small bit fiddling cleanup
tron
parents: 2186
diff changeset
   560
	DrawClearLandFence(ti);
5573
afa6f92a71fd (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 4815
diff changeset
   561
	DrawBridgeMiddle(ti);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   562
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   563
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   564
static uint GetSlopeZ_Clear(TileIndex tile, uint x, uint y)
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   565
{
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   566
	uint z;
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   567
	Slope tileh = GetTileSlope(tile, &z);
4231
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   568
dea6a63dd058 (svn r5794) Pass the TileIndex plus x and y coordinates into GetSlopeZ_* instead of a TileInfo
tron
parents: 4157
diff changeset
   569
	return z + GetPartialZ(x & 0xF, y & 0xF, tileh);
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   570
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   571
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7813
diff changeset
   572
static Foundation GetFoundation_Clear(TileIndex tile, Slope tileh)
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   573
{
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7813
diff changeset
   574
	return FOUNDATION_NONE;
39
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   575
}
d177340ed556 (svn r40) Final slope graphics fix
dominik
parents: 0
diff changeset
   576
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   577
static void GetAcceptedCargo_Clear(TileIndex tile, AcceptedCargo ac)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
{
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   579
	/* unused */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   582
static void AnimateTile_Clear(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
	/* unused */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
1293
a09e03073113 (svn r1797) Clean up TileLoopClearHelper() a bit:
tron
parents: 1209
diff changeset
   587
void TileLoopClearHelper(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
{
2221
a25240840b32 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   589
	byte self;
a25240840b32 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   590
	byte neighbour;
1293
a09e03073113 (svn r1797) Clean up TileLoopClearHelper() a bit:
tron
parents: 1209
diff changeset
   591
	TileIndex dirty = INVALID_TILE;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   593
	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
   594
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   595
	neighbour = (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CLEAR_FIELDS));
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   596
	if (GetFenceSW(tile) == 0) {
2221
a25240840b32 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   597
		if (self != neighbour) {
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   598
			SetFenceSW(tile, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
			dirty = tile;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   600
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	} else {
2221
a25240840b32 (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 == 0 && neighbour == 0) {
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   603
			SetFenceSW(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   604
			dirty = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   606
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   607
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   608
	neighbour = (IsTileType(TILE_ADDXY(tile, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 0, 1), CLEAR_FIELDS));
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   609
	if (GetFenceSE(tile) == 0) {
2221
a25240840b32 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   610
		if (self != neighbour) {
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   611
			SetFenceSE(tile, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   612
			dirty = tile;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   613
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
	} else {
2221
a25240840b32 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   615
		if (self == 0 && neighbour == 0) {
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2956
diff changeset
   616
			SetFenceSE(tile, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
			dirty = tile;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   618
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   620
2221
a25240840b32 (svn r2739) -Fix(?): Change the fence algorithm so it removes fences when no farm tile is adjacent
tron
parents: 2220
diff changeset
   621
	if (dirty != INVALID_TILE) MarkTileDirtyByTile(dirty);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   625
/* convert into snowy tiles */
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   626
static void TileLoopClearAlps(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
{
6669
487ac09b95c4 (svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
maedhros
parents: 6574
diff changeset
   628
	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
   629
4157
0c3210247472 (svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents: 4069
diff changeset
   630
	if (k < 0) { // well below the snow line
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   631
		if (!IsClearGround(tile, CLEAR_SNOW)) return;
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   632
		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
   633
	} else {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   634
		if (!IsClearGround(tile, CLEAR_SNOW)) {
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   635
			SetClearGroundDensity(tile, CLEAR_SNOW, 0);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   636
		} else {
4157
0c3210247472 (svn r5581) Slightly alter some snow line related calculations to make them a bit clearer
tron
parents: 4069
diff changeset
   637
			uint density = min((uint)k / TILE_HEIGHT, 3);
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   638
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   639
			if (GetClearDensity(tile) < density) {
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   640
				AddClearDensity(tile, 1);
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   641
			} else if (GetClearDensity(tile) > density) {
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   642
				AddClearDensity(tile, -1);
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   643
			} else {
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   644
				return;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   645
			}
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   646
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   647
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   648
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   649
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   650
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   651
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   652
static void TileLoopClearDesert(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   653
{
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   654
	if (IsClearGround(tile, CLEAR_DESERT)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   655
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3310
diff changeset
   656
	if (GetTropicZone(tile) == TROPICZONE_DESERT) {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   657
		SetClearGroundDensity(tile, CLEAR_DESERT, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   658
	} else {
3379
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3310
diff changeset
   659
		if (GetTropicZone(tile + TileDiffXY( 1,  0)) != TROPICZONE_DESERT &&
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3310
diff changeset
   660
				GetTropicZone(tile + TileDiffXY(-1,  0)) != TROPICZONE_DESERT &&
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3310
diff changeset
   661
				GetTropicZone(tile + TileDiffXY( 0,  1)) != TROPICZONE_DESERT &&
ea8aa9e71328 (svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents: 3310
diff changeset
   662
				GetTropicZone(tile + TileDiffXY( 0, -1)) != TROPICZONE_DESERT)
1981
de031d2aed47 (svn r2487) Replace TILE_XY by TileXY/TileDiffXY
tron
parents: 1980
diff changeset
   663
			return;
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   664
		SetClearGroundDensity(tile, CLEAR_DESERT, 1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   666
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   667
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   668
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   670
static void TileLoop_Clear(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   671
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   672
	TileLoopClearHelper(tile);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   673
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2979
diff changeset
   674
	switch (_opt.landscape) {
6683
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   675
		case LT_TROPIC: TileLoopClearDesert(tile); break;
7ec558346172 (svn r9400) -Codechange: Use some more representative enum names for landscape types.
belugas
parents: 6669
diff changeset
   676
		case LT_ARCTIC: TileLoopClearAlps(tile);   break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   678
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   679
	switch (GetClearGround(tile)) {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   680
		case CLEAR_GRASS:
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   681
			if (GetClearDensity(tile) == 3) return;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 159
diff changeset
   682
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   683
			if (_game_mode != GM_EDITOR) {
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   684
				if (GetClearCounter(tile) < 7) {
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   685
					AddClearCounter(tile, 1);
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   686
					return;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   687
				} else {
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   688
					SetClearCounter(tile, 0);
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   689
					AddClearDensity(tile, 1);
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   690
				}
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   691
			} else {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   692
				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
   693
			}
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   694
			break;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   695
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   696
		case CLEAR_FIELDS: {
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   697
			uint field_type;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   698
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   699
			if (_game_mode == GM_EDITOR) return;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   700
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   701
			if (GetClearCounter(tile) < 7) {
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   702
				AddClearCounter(tile, 1);
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   703
				return;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   704
			} else {
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   705
				SetClearCounter(tile, 0);
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   706
			}
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   707
4333
2ff83c9c81fa (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
   708
			if (GetIndustryIndexOfField(tile) == INVALID_INDUSTRY && GetFieldType(tile) >= 7) {
4328
23dd79414386 (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
   709
				/* This farmfield is no longer farmfield, so make it grass again */
4815
c2a54b213fde (svn r6739) -Fix (r6001): Crash on removing farmland belonging to a farm. The search would loop
Darkvater
parents: 4560
diff changeset
   710
				MakeClear(tile, CLEAR_GRASS, 2);
4328
23dd79414386 (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
   711
			} else {
23dd79414386 (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
   712
				field_type = GetFieldType(tile);
23dd79414386 (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
   713
				field_type = (field_type < 8) ? field_type + 1 : 0;
23dd79414386 (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
   714
				SetFieldType(tile, field_type);
23dd79414386 (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
   715
			}
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   716
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   717
		}
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   718
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   719
		default:
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
	MarkTileDirtyByTile(tile);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   725
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6486
diff changeset
   726
void GenerateClearTile()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   727
{
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   728
	uint i, gi;
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   729
	TileIndex tile;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   730
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   731
	/* add rough tiles */
2635
88b8b74c01ac (svn r3177) GB, CLRBIT, HASBIT, TOGGLEBIT
tron
parents: 2537
diff changeset
   732
	i = ScaleByMapSize(GB(Random(), 0, 10) + 0x400);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   733
	gi = ScaleByMapSize(GB(Random(), 0, 7) + 0x80);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   734
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   735
	SetGeneratingWorldProgress(GWP_ROUGH_ROCKY, gi + i);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   736
	do {
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   737
		IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY);
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
   738
		tile = RandomTile();
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   739
		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
   740
	} while (--i);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   741
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   742
	/* add rocky tiles */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   743
	i = gi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
	do {
2150
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   745
		uint32 r = Random();
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2049
diff changeset
   746
		tile = RandomTileSeed(r);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   747
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   748
		IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY);
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   749
		if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) {
2150
010d923a81a9 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
   750
			uint j = GB(r, 16, 4) + 5;
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2934
diff changeset
   751
			for (;;) {
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   752
				TileIndex tile_new;
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   753
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   754
				SetClearGroundDensity(tile, CLEAR_ROCKS, 3);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   755
				do {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
					if (--j == 0) goto get_out;
7813
49fbe41f8a04 (svn r10672) -Codechange: typify some parameters/variables.
rubidium
parents: 7809
diff changeset
   757
					tile_new = tile + TileOffsByDiagDir((DiagDirection)GB(Random(), 0, 2));
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4231
diff changeset
   758
				} 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
   759
				tile = tile_new;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   760
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   761
get_out:;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   762
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   763
	} while (--i);
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
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   766
static void ClickTile_Clear(TileIndex tile)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   768
	/* not used */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   769
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   770
7179
3e123c2b7c93 (svn r9914) -Codechange: prepare GTTS and the pathfinders to handle multiple road types on a single tile.
rubidium
parents: 6987
diff changeset
   771
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
   772
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   773
	return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   774
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
2220
6c186dad8188 (svn r2738) Small bit fiddling cleanup
tron
parents: 2186
diff changeset
   776
static const StringID _clear_land_str[] = {
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   777
	STR_080D_GRASS,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   778
	STR_080B_ROUGH_LAND,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   779
	STR_080A_ROCKS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   780
	STR_080E_FIELDS,
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
	STR_080F_SNOW_COVERED_LAND,
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   782
	STR_0810_DESERT
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   783
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   784
1977
4392ae3d8e31 (svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents: 1901
diff changeset
   785
static void GetTileDesc_Clear(TileIndex tile, TileDesc *td)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
{
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3422
diff changeset
   787
	if (IsClearGround(tile, CLEAR_GRASS) && GetClearDensity(tile) == 0) {
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   788
		td->str = STR_080C_BARE_LAND;
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   789
	} else {
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   790
		td->str = _clear_land_str[GetClearGround(tile)];
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents: 2952
diff changeset
   791
	}
1901
fb05044cf5c3 (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
   792
	td->owner = GetTileOwner(tile);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   793
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   794
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2221
diff changeset
   795
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
   796
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
	return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   798
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   799
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6486
diff changeset
   800
void InitializeClearLand()
1093
e8d26c7dc42f (svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents: 1059
diff changeset
   801
{
3422
12cdb13ddb56 (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
   802
	_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
   803
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   804
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   805
static CommandCost TerraformTile_Clear(TileIndex tile, uint32 flags, uint z_new, Slope tileh_new)
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   806
{
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   807
	return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   808
}
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   809
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   810
extern const TileTypeProcs _tile_type_clear_procs = {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   811
	DrawTile_Clear,           ///< draw_tile_proc
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   812
	GetSlopeZ_Clear,          ///< get_slope_z_proc
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   813
	ClearTile_Clear,          ///< clear_tile_proc
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   814
	GetAcceptedCargo_Clear,   ///< get_accepted_cargo_proc
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   815
	GetTileDesc_Clear,        ///< get_tile_desc_proc
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   816
	GetTileTrackStatus_Clear, ///< get_tile_track_status_proc
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   817
	ClickTile_Clear,          ///< click_tile_proc
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   818
	AnimateTile_Clear,        ///< animate_tile_proc
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   819
	TileLoop_Clear,           ///< tile_loop_clear
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   820
	ChangeTileOwner_Clear,    ///< change_tile_owner_clear
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   821
	NULL,                     ///< get_produced_cargo_proc
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6432
diff changeset
   822
	NULL,                     ///< vehicle_enter_tile_proc
7831
5dded9b03500 (svn r10698) -Codechange [FS#1082]: simplify the code related to foundations. Primarily removal of (duplicated|magic) code and introduction of few helper functions to ease foundation determination. Patch by frosch.
rubidium
parents: 7813
diff changeset
   823
	GetFoundation_Clear,      ///< get_foundation_proc
7990
70039e33e893 (svn r11005) -Codechange: move the tiletype specific terraforming checks to the functions for those tile types.
rubidium
parents: 7983
diff changeset
   824
	TerraformTile_Clear,      ///< terraform_tile_proc
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   825
};