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