src/clear_map.h
author rubidium
Thu, 27 Dec 2007 13:35:39 +0000
changeset 8640 1e93b81e96d2
parent 8609 8c0c3e9dd6a0
child 8709 4187ad809fe7
permissions -rw-r--r--
(svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
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:
diff changeset
     1
/* $Id$ */
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:
diff changeset
     2
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
     3
/** @file clear_map.h Map accessors for 'clear' tiles */
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5847
diff changeset
     4
3145
349b745dfbf4 (svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents: 3144
diff changeset
     5
#ifndef CLEAR_MAP_H
349b745dfbf4 (svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents: 3144
diff changeset
     6
#define CLEAR_MAP_H
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:
diff changeset
     7
5828
d54db61cc830 (svn r8014) -Codechange (r7573): When a tile is cleared, empty the general purpose bits in
maedhros
parents: 5726
diff changeset
     8
#include "bridge_map.h"
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:
diff changeset
     9
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    10
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    11
 * Ground types. Valid densities in comments after the enum.
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:
diff changeset
    12
 */
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6449
diff changeset
    13
enum ClearGround {
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5847
diff changeset
    14
	CLEAR_GRASS  = 0, ///< 0-3
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5847
diff changeset
    15
	CLEAR_ROUGH  = 1, ///< 3
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5847
diff changeset
    16
	CLEAR_ROCKS  = 2, ///< 3
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5847
diff changeset
    17
	CLEAR_FIELDS = 3, ///< 3
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5847
diff changeset
    18
	CLEAR_SNOW   = 4, ///< 0-3
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5847
diff changeset
    19
	CLEAR_DESERT = 5  ///< 1,3
6574
e1d1a12faaf7 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6449
diff changeset
    20
};
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:
diff changeset
    21
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:
diff changeset
    22
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    23
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    24
 * Get the type of clear tile.
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    25
 * @param t the tile to get the clear ground type of
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    26
 * @pre IsTileType(t, MP_CLEAR)
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    27
 * @return the ground type
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    28
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    29
static inline ClearGround GetClearGround(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    30
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    31
	assert(IsTileType(t, MP_CLEAR));
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5828
diff changeset
    32
	return (ClearGround)GB(_m[t].m5, 2, 3);
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    33
}
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:
diff changeset
    34
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    35
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    36
 * Set the type of clear tile.
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    37
 * @param t  the tile to set the clear ground type of
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    38
 * @param ct the ground type
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    39
 * @pre IsTileType(t, MP_CLEAR)
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    40
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    41
static inline bool IsClearGround(TileIndex t, ClearGround ct)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    42
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    43
	return GetClearGround(t) == ct;
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    44
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    45
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    46
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    47
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    48
 * Get the density of a non-field clear tile.
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    49
 * @param t the tile to get the density of
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    50
 * @pre IsTileType(t, MP_CLEAR)
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    51
 * @return the density
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    52
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    53
static inline uint GetClearDensity(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    54
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    55
	assert(IsTileType(t, MP_CLEAR));
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    56
	return GB(_m[t].m5, 0, 2);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    57
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    58
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    59
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    60
 * Increment the density of a non-field clear tile.
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    61
 * @param t the tile to increment the density of
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    62
 * @param d the amount to increment the density with
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    63
 * @pre IsTileType(t, MP_CLEAR)
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    64
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    65
static inline void AddClearDensity(TileIndex t, int d)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    66
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    67
	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    68
	_m[t].m5 += d;
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    69
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    70
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    71
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    72
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    73
 * Get the counter used to advance to the next clear density/field type.
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    74
 * @param t the tile to get the counter of
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    75
 * @pre IsTileType(t, MP_CLEAR)
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    76
 * @return the value of the counter
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    77
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    78
static inline uint GetClearCounter(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    79
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    80
	assert(IsTileType(t, MP_CLEAR));
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    81
	return GB(_m[t].m5, 5, 3);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    82
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    83
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    84
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    85
 * Increments the counter used to advance to the next clear density/field type.
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    86
 * @param t the tile to increment the counter of
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    87
 * @param c the amount to increment the counter with
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    88
 * @pre IsTileType(t, MP_CLEAR)
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    89
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    90
static inline void AddClearCounter(TileIndex t, int c)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    91
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    92
	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    93
	_m[t].m5 += c << 5;
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    94
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    95
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    96
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    97
 * Sets the counter used to advance to the next clear density/field type.
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    98
 * @param t the tile to set the counter of
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
    99
 * @param c the amount to set the counter to
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   100
 * @pre IsTileType(t, MP_CLEAR)
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   101
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   102
static inline void SetClearCounter(TileIndex t, uint c)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   103
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   104
	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   105
	SB(_m[t].m5, 5, 3, c);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   106
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   107
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:
diff changeset
   108
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   109
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   110
 * Sets ground type and density in one go, also sets the counter to 0
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   111
 * @param t       the tile to set the ground type and density for
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   112
 * @param type    the new ground type of the tile
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   113
 * @param density the density of the ground tile
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   114
 * @pre IsTileType(t, MP_CLEAR)
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   115
 */
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:
diff changeset
   116
static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint 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:
diff changeset
   117
{
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   118
	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
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:
diff changeset
   119
	_m[t].m5 = 0 << 5 | type << 2 | 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:
diff changeset
   120
}
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:
diff changeset
   121
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   122
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   123
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   124
 * Get the field type (production stage) of the field
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   125
 * @param t the field to get the type of
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   126
 * @pre GetClearGround(t) == CLEAR_FIELDS
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   127
 * @return the field type
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   128
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   129
static inline uint GetFieldType(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   130
{
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
   131
	assert(GetClearGround(t) == CLEAR_FIELDS);
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   132
	return GB(_m[t].m3, 0, 4);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   133
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   134
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   135
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   136
 * Set the field type (production stage) of the field
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   137
 * @param t the field to get the type of
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   138
 * @param f the field type
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   139
 * @pre GetClearGround(t) == CLEAR_FIELDS
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   140
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   141
static inline void SetFieldType(TileIndex t, uint f)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   142
{
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
   143
	assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   144
	SB(_m[t].m3, 0, 4, f);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   145
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   146
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   147
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   148
 * Get the industry (farm) that made the field
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   149
 * @param t the field to get creating industry of
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   150
 * @pre GetClearGround(t) == CLEAR_FIELDS
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   151
 * @return the industry that made the field
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   152
 */
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   153
static inline IndustryID GetIndustryIndexOfField(TileIndex t)
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: 3516
diff changeset
   154
{
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 3516
diff changeset
   155
	assert(GetClearGround(t) == CLEAR_FIELDS);
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   156
	return(IndustryID) _m[t].m2;
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: 3516
diff changeset
   157
}
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 3516
diff changeset
   158
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   159
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   160
 * Set the industry (farm) that made the field
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   161
 * @param t the field to get creating industry of
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   162
 * @param i the industry that made the field
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   163
 * @pre GetClearGround(t) == CLEAR_FIELDS
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   164
 */
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   165
static inline void SetIndustryIndexOfField(TileIndex t, IndustryID i)
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: 3516
diff changeset
   166
{
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 3516
diff changeset
   167
	assert(GetClearGround(t) == CLEAR_FIELDS);
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 3516
diff changeset
   168
	_m[t].m2 = i;
23dd79414386 (svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
truelight
parents: 3516
diff changeset
   169
}
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   170
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   171
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   172
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   173
 * Is there a fence at the south eastern border?
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   174
 * @param t the tile to check for fences
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   175
 * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   176
 * @return 0 if there is no fence, otherwise the fence type
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   177
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   178
static inline uint GetFenceSE(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   179
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   180
	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   181
	return GB(_m[t].m4, 2, 3);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   182
}
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   183
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   184
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   185
 * Sets the type of fence (and whether there is one) for the south
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   186
 * eastern border.
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   187
 * @param t the tile to check for fences
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   188
 * @param h 0 if there is no fence, otherwise the fence type
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   189
 * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   190
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   191
static inline void SetFenceSE(TileIndex t, uint h)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   192
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   193
	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   194
	SB(_m[t].m4, 2, 3, h);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   195
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   196
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   197
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   198
 * Is there a fence at the south western border?
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   199
 * @param t the tile to check for fences
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   200
 * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   201
 * @return 0 if there is no fence, otherwise the fence type
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   202
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   203
static inline uint GetFenceSW(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   204
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   205
	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   206
	return GB(_m[t].m4, 5, 3);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   207
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   208
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   209
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   210
 * Sets the type of fence (and whether there is one) for the south
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   211
 * western border.
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   212
 * @param t the tile to check for fences
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   213
 * @param h 0 if there is no fence, otherwise the fence type
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   214
 * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   215
 */
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   216
static inline void SetFenceSW(TileIndex t, uint h)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   217
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   218
	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   219
	SB(_m[t].m4, 5, 3, h);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   220
}
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   221
3076
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   222
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   223
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   224
 * Make a clear tile.
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   225
 * @param t       the tile to make a clear tile
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   226
 * @param g       the type of ground
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   227
 * @param density the density of the grass/snow/desert etc
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   228
 */
3076
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   229
static inline void MakeClear(TileIndex t, ClearGround g, uint density)
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   230
{
5828
d54db61cc830 (svn r8014) -Codechange (r7573): When a tile is cleared, empty the general purpose bits in
maedhros
parents: 5726
diff changeset
   231
	/* If this is a non-bridgeable tile, clear the bridge bits while the rest
d54db61cc830 (svn r8014) -Codechange (r7573): When a tile is cleared, empty the general purpose bits in
maedhros
parents: 5726
diff changeset
   232
	 * of the tile information is still here. */
5847
9ce114e1d90d (svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents: 5838
diff changeset
   233
	if (!MayHaveBridgeAbove(t)) SB(_m[t].m6, 6, 2, 0);
5828
d54db61cc830 (svn r8014) -Codechange (r7573): When a tile is cleared, empty the general purpose bits in
maedhros
parents: 5726
diff changeset
   234
3076
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   235
	SetTileType(t, MP_CLEAR);
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   236
	SetTileOwner(t, OWNER_NONE);
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   237
	_m[t].m2 = 0;
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   238
	_m[t].m3 = 0;
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   239
	_m[t].m4 = 0 << 5 | 0 << 2;
3291
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   240
	SetClearGroundDensity(t, g, density);
6449
e520244dc71e (svn r8859) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 5847
diff changeset
   241
	SB(_m[t].m6, 2, 4, 0); // Clear the rest of m6, bits 2 to 5
3291
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   242
}
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   243
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   244
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   245
/**
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   246
 * Make a (farm) field tile.
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   247
 * @param t          the tile to make a farm field
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   248
 * @param field_type the 'growth' level of the field
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   249
 * @param industry   the industry this tile belongs to
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   250
 */
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6574
diff changeset
   251
static inline void MakeField(TileIndex t, uint field_type, IndustryID industry)
3291
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   252
{
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   253
	SetTileType(t, MP_CLEAR);
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   254
	SetTileOwner(t, OWNER_NONE);
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: 3516
diff changeset
   255
	_m[t].m2 = industry;
3291
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   256
	_m[t].m3 = field_type;
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   257
	_m[t].m4 = 0 << 5 | 0 << 2;
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
   258
	SetClearGroundDensity(t, CLEAR_FIELDS, 3);
3076
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   259
}
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   260
4666
850b5b6e4bac (svn r6560) - Codechange: Minor fix; add missing #include guards and comments, and correct svn properties on bmp.[ch]
peter1138
parents: 4328
diff changeset
   261
#endif /* CLEAR_MAP_H */