clear_map.h
author Darkvater
Mon, 31 Jul 2006 22:40:55 +0000
changeset 4204 3aa39be759f2
parent 3516 4dde641ee82a
child 4328 1b3940c35724
permissions -rw-r--r--
(svn r5688) - Forward-port the release-changes from the 0.4 branch back to trunk. This ensures an updated changelog, known-bugs, etc.
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
3145
e833d7a78887 (svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents: 3144
diff changeset
     3
#ifndef CLEAR_MAP_H
e833d7a78887 (svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents: 3144
diff changeset
     4
#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
     5
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
     6
#include "macros.h"
3076
8b54ff8fa90a (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
     7
#include "tile.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
     8
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
     9
/* ground type, m5 bits 2...4
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
 * valid densities (bits 0...1) in comments after the enum
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
    11
 */
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
    12
typedef enum ClearGround {
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    13
	CLEAR_GRASS  = 0, // 0-3
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    14
	CLEAR_ROUGH  = 1, // 3
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    15
	CLEAR_ROCKS  = 2, // 3
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    16
	CLEAR_FIELDS = 3, // 3
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    17
	CLEAR_SNOW   = 4, // 0-3
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    18
	CLEAR_DESERT = 5  // 1,3
2955
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff changeset
    19
} ClearGround;
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
    20
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
    21
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    22
static inline ClearGround GetClearGround(TileIndex t)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    23
{
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    24
	assert(IsTileType(t, MP_CLEAR));
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    25
	return GB(_m[t].m5, 2, 3);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    26
}
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
    27
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    28
static inline bool IsClearGround(TileIndex t, ClearGround ct)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    29
{
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    30
	return GetClearGround(t) == ct;
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
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    33
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    34
static inline uint GetClearDensity(TileIndex t)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    35
{
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    36
	assert(IsTileType(t, MP_CLEAR));
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    37
	return GB(_m[t].m5, 0, 2);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    38
}
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    39
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    40
static inline void AddClearDensity(TileIndex t, int d)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    41
{
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    42
	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    43
	_m[t].m5 += d;
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    44
}
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
static inline uint GetClearCounter(TileIndex t)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    48
{
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    49
	assert(IsTileType(t, MP_CLEAR));
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    50
	return GB(_m[t].m5, 5, 3);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    51
}
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    52
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    53
static inline void AddClearCounter(TileIndex t, int c)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    54
{
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    55
	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    56
	_m[t].m5 += c << 5;
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    57
}
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
static inline void SetClearCounter(TileIndex t, uint c)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    60
{
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    61
	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    62
	SB(_m[t].m5, 5, 3, c);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    63
}
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    64
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
    65
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
    66
/* Sets type and density in one go, also sets the counter to 0 */
24de69e236d2 (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff changeset
    67
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
    68
{
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    69
	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
    70
	_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
    71
}
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
    72
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    73
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    74
static inline uint GetFieldType(TileIndex t)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    75
{
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    76
	assert(GetClearGround(t) == CLEAR_FIELDS);
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    77
	return GB(_m[t].m3, 0, 4);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    78
}
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    79
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    80
static inline void SetFieldType(TileIndex t, uint f)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    81
{
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    82
	assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    83
	SB(_m[t].m3, 0, 4, f);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    84
}
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    85
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
    86
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
    87
/* Is used by tree tiles, too */
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    88
static inline uint GetFenceSE(TileIndex t)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    89
{
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    90
	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    91
	return GB(_m[t].m4, 2, 3);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    92
}
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
    93
3369
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    94
static inline void SetFenceSE(TileIndex t, uint h)
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
	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
    97
	SB(_m[t].m4, 2, 3, h);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    98
}
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    99
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   100
static inline uint GetFenceSW(TileIndex t)
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   101
{
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   102
	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   103
	return GB(_m[t].m4, 5, 3);
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
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   106
static inline void SetFenceSW(TileIndex t, uint h)
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
	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
   109
	SB(_m[t].m4, 5, 3, h);
cab209754317 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   110
}
2979
3ddf7c78d469 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   111
3076
8b54ff8fa90a (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   112
8b54ff8fa90a (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   113
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
   114
{
8b54ff8fa90a (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   115
	SetTileType(t, MP_CLEAR);
8b54ff8fa90a (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   116
	SetTileOwner(t, OWNER_NONE);
8b54ff8fa90a (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   117
	_m[t].m2 = 0;
8b54ff8fa90a (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   118
	_m[t].m3 = 0;
8b54ff8fa90a (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   119
	_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
   120
	SetClearGroundDensity(t, g, density);
f45158e006d0 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   121
}
f45158e006d0 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   122
f45158e006d0 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   123
f45158e006d0 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   124
static inline void MakeField(TileIndex t, uint field_type)
f45158e006d0 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   125
{
f45158e006d0 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   126
	SetTileType(t, MP_CLEAR);
f45158e006d0 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   127
	SetTileOwner(t, OWNER_NONE);
f45158e006d0 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   128
	_m[t].m2 = 0;
f45158e006d0 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   129
	_m[t].m3 = field_type;
f45158e006d0 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   130
	_m[t].m4 = 0 << 5 | 0 << 2;
3447
1c62c085638a (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
   131
	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
   132
}
8b54ff8fa90a (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   133
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
   134
#endif