clear_map.h
author bjarni
Mon, 14 Aug 2006 15:03:01 +0000
changeset 4262 4657d940a84c
parent 3516 2179c24faed1
child 4328 23dd79414386
permissions -rw-r--r--
(svn r5888) -Fix: [autoreplace] if vehicles breakdowns and service are turned off, the vehicles failed to enter any depots
now they will quickly go to a depot if set to be replaced
the tradeoff is that a vehicle set to be replaced and without a depot in the orders will forget about the orders and head for a depot. If the replace fails (lack of money), it will exit and try to head for the depot again
also all vehicles of that type will rush to the depots at once, risking causing traffic jams. This is because there is no way to even it out like normal depot visits offers
Tip: add a depot to the orders of all vehicles, set it to service only and it will always be skipped unless the vehicle is set to be replaced. This should help on the jam issue and if the replace fails, the vehicle will go though a whole round of the orders and make more money before trying again
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
3145
349b745dfbf4 (svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents: 3144
diff changeset
     3
#ifndef CLEAR_MAP_H
349b745dfbf4 (svn r3765) Fix some naming glitches in r3763 and add missing svn properties
tron
parents: 3144
diff changeset
     4
#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
     5
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
     6
#include "macros.h"
3076
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
     7
#include "tile.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
     8
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
/* ground type, m5 bits 2...4
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
    10
 * valid densities (bits 0...1) in comments after the enum
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
    11
 */
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
typedef enum ClearGround {
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    13
	CLEAR_GRASS  = 0, // 0-3
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    14
	CLEAR_ROUGH  = 1, // 3
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    15
	CLEAR_ROCKS  = 2, // 3
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    16
	CLEAR_FIELDS = 3, // 3
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    17
	CLEAR_SNOW   = 4, // 0-3
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    18
	CLEAR_DESERT = 5  // 1,3
2955
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff changeset
    19
} ClearGround;
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
    20
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
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    22
static inline ClearGround GetClearGround(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    23
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    24
	assert(IsTileType(t, MP_CLEAR));
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    25
	return GB(_m[t].m5, 2, 3);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    26
}
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
    27
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    28
static inline bool IsClearGround(TileIndex t, ClearGround ct)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    29
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    30
	return GetClearGround(t) == ct;
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    31
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    32
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    33
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    34
static inline uint GetClearDensity(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    35
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    36
	assert(IsTileType(t, MP_CLEAR));
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    37
	return GB(_m[t].m5, 0, 2);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    38
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    39
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    40
static inline void AddClearDensity(TileIndex t, int d)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    41
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    42
	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    43
	_m[t].m5 += d;
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
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    47
static inline uint GetClearCounter(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    48
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    49
	assert(IsTileType(t, MP_CLEAR));
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    50
	return GB(_m[t].m5, 5, 3);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    51
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    52
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    53
static inline void AddClearCounter(TileIndex t, int c)
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)); // XXX incomplete
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    56
	_m[t].m5 += c << 5;
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
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    59
static inline void SetClearCounter(TileIndex t, uint c)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    60
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    61
	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    62
	SB(_m[t].m5, 5, 3, c);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    63
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    64
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
    65
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
    66
/* Sets type and density in one go, also sets the counter to 0 */
27221592ebbc (svn r3514) -Codechange: Replace direct fiddling of bits for the ground type and density of clear tiles with symbolic names and accessors.
tron
parents:
diff changeset
    67
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
    68
{
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    69
	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
    70
	_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
    71
}
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
    72
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    73
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    74
static inline uint GetFieldType(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    75
{
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    76
	assert(GetClearGround(t) == CLEAR_FIELDS);
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    77
	return GB(_m[t].m3, 0, 4);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    78
}
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
static inline void SetFieldType(TileIndex t, uint f)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    81
{
3447
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
    82
	assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    83
	SB(_m[t].m3, 0, 4, f);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    84
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    85
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
    86
883788245931 (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
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    88
static inline uint GetFenceSE(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    89
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    90
	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    91
	return GB(_m[t].m4, 2, 3);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    92
}
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
    93
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    94
static inline void SetFenceSE(TileIndex t, uint h)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    95
{
00c2ca209a89 (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
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    97
	SB(_m[t].m4, 2, 3, h);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    98
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
    99
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   100
static inline uint GetFenceSW(TileIndex t)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   101
{
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   102
	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   103
	return GB(_m[t].m4, 5, 3);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   104
}
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   105
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   106
static inline void SetFenceSW(TileIndex t, uint h)
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   107
{
00c2ca209a89 (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
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   109
	SB(_m[t].m4, 5, 3, h);
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3291
diff changeset
   110
}
2979
883788245931 (svn r3554) Add accessors for the field type and fences of clear tiles
tron
parents: 2955
diff changeset
   111
3076
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   112
9584f34a83dc (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)
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   114
{
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   115
	SetTileType(t, MP_CLEAR);
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   116
	SetTileOwner(t, OWNER_NONE);
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   117
	_m[t].m2 = 0;
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   118
	_m[t].m3 = 0;
9584f34a83dc (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
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   120
	SetClearGroundDensity(t, g, density);
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   121
}
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   122
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   123
e0b2c01649f7 (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)
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   125
{
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   126
	SetTileType(t, MP_CLEAR);
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   127
	SetTileOwner(t, OWNER_NONE);
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   128
	_m[t].m2 = 0;
e0b2c01649f7 (svn r4007) Add a function to make a farm field tile
tron
parents: 3145
diff changeset
   129
	_m[t].m3 = field_type;
e0b2c01649f7 (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
d136931464f7 (svn r4279) s/\<CL_/CLEAR_/
tron
parents: 3369
diff changeset
   131
	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
   132
}
9584f34a83dc (svn r3665) Add a function to turn a tile into a clear tile
tron
parents: 2979
diff changeset
   133
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
   134
#endif