src/clear_map.h
branchgamebalance
changeset 9908 0fa543611bbe
parent 9895 7bd07f43b0e3
child 6872 1c4a4a609f85
child 8604 8afdd9877afd
equal deleted inserted replaced
9907:3b068c3a1c74 9908:0fa543611bbe
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 /** @file clear_map.h */
     3 /** @file clear_map.h Map accessors for 'clear' tiles */
     4 
     4 
     5 #ifndef CLEAR_MAP_H
     5 #ifndef CLEAR_MAP_H
     6 #define CLEAR_MAP_H
     6 #define CLEAR_MAP_H
     7 
     7 
     8 #include "macros.h"
     8 #include "macros.h"
     9 #include "tile.h"
     9 #include "tile.h"
    10 #include "bridge_map.h"
    10 #include "bridge_map.h"
    11 
    11 
    12 /* ground type, m5 bits 2...4
    12 /**
    13  * valid densities (bits 0...1) in comments after the enum
    13  * Ground types. Valid densities in comments after the enum.
    14  */
    14  */
    15 enum ClearGround {
    15 enum ClearGround {
    16 	CLEAR_GRASS  = 0, ///< 0-3
    16 	CLEAR_GRASS  = 0, ///< 0-3
    17 	CLEAR_ROUGH  = 1, ///< 3
    17 	CLEAR_ROUGH  = 1, ///< 3
    18 	CLEAR_ROCKS  = 2, ///< 3
    18 	CLEAR_ROCKS  = 2, ///< 3
    20 	CLEAR_SNOW   = 4, ///< 0-3
    20 	CLEAR_SNOW   = 4, ///< 0-3
    21 	CLEAR_DESERT = 5  ///< 1,3
    21 	CLEAR_DESERT = 5  ///< 1,3
    22 };
    22 };
    23 
    23 
    24 
    24 
       
    25 /**
       
    26  * Get the type of clear tile.
       
    27  * @param t the tile to get the clear ground type of
       
    28  * @pre IsTileType(t, MP_CLEAR)
       
    29  * @return the ground type
       
    30  */
    25 static inline ClearGround GetClearGround(TileIndex t)
    31 static inline ClearGround GetClearGround(TileIndex t)
    26 {
    32 {
    27 	assert(IsTileType(t, MP_CLEAR));
    33 	assert(IsTileType(t, MP_CLEAR));
    28 	return (ClearGround)GB(_m[t].m5, 2, 3);
    34 	return (ClearGround)GB(_m[t].m5, 2, 3);
    29 }
    35 }
    30 
    36 
       
    37 /**
       
    38  * Set the type of clear tile.
       
    39  * @param t  the tile to set the clear ground type of
       
    40  * @param ct the ground type
       
    41  * @pre IsTileType(t, MP_CLEAR)
       
    42  */
    31 static inline bool IsClearGround(TileIndex t, ClearGround ct)
    43 static inline bool IsClearGround(TileIndex t, ClearGround ct)
    32 {
    44 {
    33 	return GetClearGround(t) == ct;
    45 	return GetClearGround(t) == ct;
    34 }
    46 }
    35 
    47 
    36 
    48 
       
    49 /**
       
    50  * Get the density of a non-field clear tile.
       
    51  * @param t the tile to get the density of
       
    52  * @pre IsTileType(t, MP_CLEAR)
       
    53  * @return the density
       
    54  */
    37 static inline uint GetClearDensity(TileIndex t)
    55 static inline uint GetClearDensity(TileIndex t)
    38 {
    56 {
    39 	assert(IsTileType(t, MP_CLEAR));
    57 	assert(IsTileType(t, MP_CLEAR));
    40 	return GB(_m[t].m5, 0, 2);
    58 	return GB(_m[t].m5, 0, 2);
    41 }
    59 }
    42 
    60 
       
    61 /**
       
    62  * Increment the density of a non-field clear tile.
       
    63  * @param t the tile to increment the density of
       
    64  * @param d the amount to increment the density with
       
    65  * @pre IsTileType(t, MP_CLEAR)
       
    66  */
    43 static inline void AddClearDensity(TileIndex t, int d)
    67 static inline void AddClearDensity(TileIndex t, int d)
    44 {
    68 {
    45 	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
    69 	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
    46 	_m[t].m5 += d;
    70 	_m[t].m5 += d;
    47 }
    71 }
    48 
    72 
    49 
    73 
       
    74 /**
       
    75  * Get the counter used to advance to the next clear density/field type.
       
    76  * @param t the tile to get the counter of
       
    77  * @pre IsTileType(t, MP_CLEAR)
       
    78  * @return the value of the counter
       
    79  */
    50 static inline uint GetClearCounter(TileIndex t)
    80 static inline uint GetClearCounter(TileIndex t)
    51 {
    81 {
    52 	assert(IsTileType(t, MP_CLEAR));
    82 	assert(IsTileType(t, MP_CLEAR));
    53 	return GB(_m[t].m5, 5, 3);
    83 	return GB(_m[t].m5, 5, 3);
    54 }
    84 }
    55 
    85 
       
    86 /**
       
    87  * Increments the counter used to advance to the next clear density/field type.
       
    88  * @param t the tile to increment the counter of
       
    89  * @param c the amount to increment the counter with
       
    90  * @pre IsTileType(t, MP_CLEAR)
       
    91  */
    56 static inline void AddClearCounter(TileIndex t, int c)
    92 static inline void AddClearCounter(TileIndex t, int c)
    57 {
    93 {
    58 	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
    94 	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
    59 	_m[t].m5 += c << 5;
    95 	_m[t].m5 += c << 5;
    60 }
    96 }
    61 
    97 
       
    98 /**
       
    99  * Sets the counter used to advance to the next clear density/field type.
       
   100  * @param t the tile to set the counter of
       
   101  * @param c the amount to set the counter to
       
   102  * @pre IsTileType(t, MP_CLEAR)
       
   103  */
    62 static inline void SetClearCounter(TileIndex t, uint c)
   104 static inline void SetClearCounter(TileIndex t, uint c)
    63 {
   105 {
    64 	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
   106 	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
    65 	SB(_m[t].m5, 5, 3, c);
   107 	SB(_m[t].m5, 5, 3, c);
    66 }
   108 }
    67 
   109 
    68 
   110 
    69 /* Sets type and density in one go, also sets the counter to 0 */
   111 /**
       
   112  * Sets ground type and density in one go, also sets the counter to 0
       
   113  * @param t       the tile to set the ground type and density for
       
   114  * @param type    the new ground type of the tile
       
   115  * @param density the density of the ground tile
       
   116  * @pre IsTileType(t, MP_CLEAR)
       
   117  */
    70 static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint density)
   118 static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint density)
    71 {
   119 {
    72 	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
   120 	assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
    73 	_m[t].m5 = 0 << 5 | type << 2 | density;
   121 	_m[t].m5 = 0 << 5 | type << 2 | density;
    74 }
   122 }
    75 
   123 
    76 
   124 
       
   125 /**
       
   126  * Get the field type (production stage) of the field
       
   127  * @param t the field to get the type of
       
   128  * @pre GetClearGround(t) == CLEAR_FIELDS
       
   129  * @return the field type
       
   130  */
    77 static inline uint GetFieldType(TileIndex t)
   131 static inline uint GetFieldType(TileIndex t)
    78 {
   132 {
    79 	assert(GetClearGround(t) == CLEAR_FIELDS);
   133 	assert(GetClearGround(t) == CLEAR_FIELDS);
    80 	return GB(_m[t].m3, 0, 4);
   134 	return GB(_m[t].m3, 0, 4);
    81 }
   135 }
    82 
   136 
       
   137 /**
       
   138  * Set the field type (production stage) of the field
       
   139  * @param t the field to get the type of
       
   140  * @param f the field type
       
   141  * @pre GetClearGround(t) == CLEAR_FIELDS
       
   142  */
    83 static inline void SetFieldType(TileIndex t, uint f)
   143 static inline void SetFieldType(TileIndex t, uint f)
    84 {
   144 {
    85 	assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete
   145 	assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete
    86 	SB(_m[t].m3, 0, 4, f);
   146 	SB(_m[t].m3, 0, 4, f);
    87 }
   147 }
    88 
   148 
    89 static inline uint16 GetIndustryIndexOfField(TileIndex t)
   149 /**
       
   150  * Get the industry (farm) that made the field
       
   151  * @param t the field to get creating industry of
       
   152  * @pre GetClearGround(t) == CLEAR_FIELDS
       
   153  * @return the industry that made the field
       
   154  */
       
   155 static inline IndustryID GetIndustryIndexOfField(TileIndex t)
    90 {
   156 {
    91 	assert(GetClearGround(t) == CLEAR_FIELDS);
   157 	assert(GetClearGround(t) == CLEAR_FIELDS);
    92 	return _m[t].m2;
   158 	return(IndustryID) _m[t].m2;
    93 }
   159 }
    94 
   160 
    95 static inline void SetIndustryIndexOfField(TileIndex t, uint16 i)
   161 /**
       
   162  * Set the industry (farm) that made the field
       
   163  * @param t the field to get creating industry of
       
   164  * @param i the industry that made the field
       
   165  * @pre GetClearGround(t) == CLEAR_FIELDS
       
   166  */
       
   167 static inline void SetIndustryIndexOfField(TileIndex t, IndustryID i)
    96 {
   168 {
    97 	assert(GetClearGround(t) == CLEAR_FIELDS);
   169 	assert(GetClearGround(t) == CLEAR_FIELDS);
    98 	_m[t].m2 = i;
   170 	_m[t].m2 = i;
    99 }
   171 }
   100 
   172 
   101 /* Is used by tree tiles, too */
   173 
       
   174 /**
       
   175  * Is there a fence at the south eastern border?
       
   176  * @param t the tile to check for fences
       
   177  * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)
       
   178  * @return 0 if there is no fence, otherwise the fence type
       
   179  */
   102 static inline uint GetFenceSE(TileIndex t)
   180 static inline uint GetFenceSE(TileIndex t)
   103 {
   181 {
   104 	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
   182 	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
   105 	return GB(_m[t].m4, 2, 3);
   183 	return GB(_m[t].m4, 2, 3);
   106 }
   184 }
   107 
   185 
       
   186 /**
       
   187  * Sets the type of fence (and whether there is one) for the south
       
   188  * eastern border.
       
   189  * @param t the tile to check for fences
       
   190  * @param h 0 if there is no fence, otherwise the fence type
       
   191  * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)
       
   192  */
   108 static inline void SetFenceSE(TileIndex t, uint h)
   193 static inline void SetFenceSE(TileIndex t, uint h)
   109 {
   194 {
   110 	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete
   195 	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete
   111 	SB(_m[t].m4, 2, 3, h);
   196 	SB(_m[t].m4, 2, 3, h);
   112 }
   197 }
   113 
   198 
       
   199 /**
       
   200  * Is there a fence at the south western border?
       
   201  * @param t the tile to check for fences
       
   202  * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)
       
   203  * @return 0 if there is no fence, otherwise the fence type
       
   204  */
   114 static inline uint GetFenceSW(TileIndex t)
   205 static inline uint GetFenceSW(TileIndex t)
   115 {
   206 {
   116 	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
   207 	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES));
   117 	return GB(_m[t].m4, 5, 3);
   208 	return GB(_m[t].m4, 5, 3);
   118 }
   209 }
   119 
   210 
       
   211 /**
       
   212  * Sets the type of fence (and whether there is one) for the south
       
   213  * western border.
       
   214  * @param t the tile to check for fences
       
   215  * @param h 0 if there is no fence, otherwise the fence type
       
   216  * @pre IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)
       
   217  */
   120 static inline void SetFenceSW(TileIndex t, uint h)
   218 static inline void SetFenceSW(TileIndex t, uint h)
   121 {
   219 {
   122 	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete
   220 	assert(IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)); // XXX incomplete
   123 	SB(_m[t].m4, 5, 3, h);
   221 	SB(_m[t].m4, 5, 3, h);
   124 }
   222 }
   125 
   223 
   126 
   224 
       
   225 /**
       
   226  * Make a clear tile.
       
   227  * @param t       the tile to make a clear tile
       
   228  * @param g       the type of ground
       
   229  * @param density the density of the grass/snow/desert etc
       
   230  */
   127 static inline void MakeClear(TileIndex t, ClearGround g, uint density)
   231 static inline void MakeClear(TileIndex t, ClearGround g, uint density)
   128 {
   232 {
   129 	/* If this is a non-bridgeable tile, clear the bridge bits while the rest
   233 	/* If this is a non-bridgeable tile, clear the bridge bits while the rest
   130 	 * of the tile information is still here. */
   234 	 * of the tile information is still here. */
   131 	if (!MayHaveBridgeAbove(t)) SB(_m[t].m6, 6, 2, 0);
   235 	if (!MayHaveBridgeAbove(t)) SB(_m[t].m6, 6, 2, 0);
   138 	SetClearGroundDensity(t, g, density);
   242 	SetClearGroundDensity(t, g, density);
   139 	SB(_m[t].m6, 2, 4, 0); // Clear the rest of m6, bits 2 to 5
   243 	SB(_m[t].m6, 2, 4, 0); // Clear the rest of m6, bits 2 to 5
   140 }
   244 }
   141 
   245 
   142 
   246 
   143 static inline void MakeField(TileIndex t, uint field_type, uint16 industry)
   247 /**
       
   248  * Make a (farm) field tile.
       
   249  * @param t          the tile to make a farm field
       
   250  * @param field_type the 'growth' level of the field
       
   251  * @param industry   the industry this tile belongs to
       
   252  */
       
   253 static inline void MakeField(TileIndex t, uint field_type, IndustryID industry)
   144 {
   254 {
   145 	SetTileType(t, MP_CLEAR);
   255 	SetTileType(t, MP_CLEAR);
   146 	SetTileOwner(t, OWNER_NONE);
   256 	SetTileOwner(t, OWNER_NONE);
   147 	_m[t].m2 = industry;
   257 	_m[t].m2 = industry;
   148 	_m[t].m3 = field_type;
   258 	_m[t].m3 = field_type;