2006-02-01 15:31:21 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/** @file clear_map.h Map accessors for 'clear' tiles */
|
2007-02-23 11:50:43 +00:00
|
|
|
|
2006-03-05 11:18:34 +00:00
|
|
|
#ifndef CLEAR_MAP_H
|
|
|
|
#define CLEAR_MAP_H
|
2006-02-01 15:31:21 +00:00
|
|
|
|
2007-01-09 21:43:32 +00:00
|
|
|
#include "bridge_map.h"
|
2008-01-07 14:02:26 +00:00
|
|
|
#include "industry_type.h"
|
2006-02-01 15:31:21 +00:00
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Ground types. Valid densities in comments after the enum.
|
2006-02-01 15:31:21 +00:00
|
|
|
*/
|
2007-03-07 12:11:48 +00:00
|
|
|
enum ClearGround {
|
2007-02-23 11:50:43 +00:00
|
|
|
CLEAR_GRASS = 0, ///< 0-3
|
|
|
|
CLEAR_ROUGH = 1, ///< 3
|
|
|
|
CLEAR_ROCKS = 2, ///< 3
|
|
|
|
CLEAR_FIELDS = 3, ///< 3
|
|
|
|
CLEAR_SNOW = 4, ///< 0-3
|
2011-12-19 17:48:04 +00:00
|
|
|
CLEAR_DESERT = 5, ///< 1,3
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-02-01 15:31:21 +00:00
|
|
|
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
2010-01-04 18:33:43 +00:00
|
|
|
* Test if a tile is covered with snow.
|
|
|
|
* @param t the tile to check
|
|
|
|
* @pre IsTileType(t, MP_CLEAR)
|
|
|
|
* @return whether the tile is covered with snow.
|
|
|
|
*/
|
|
|
|
static inline bool IsSnowTile(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_CLEAR));
|
|
|
|
return HasBit(_m[t].m3, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the type of clear tile but never return CLEAR_SNOW.
|
2007-04-03 21:51:40 +00:00
|
|
|
* @param t the tile to get the clear ground type of
|
|
|
|
* @pre IsTileType(t, MP_CLEAR)
|
|
|
|
* @return the ground type
|
|
|
|
*/
|
2010-01-04 18:33:43 +00:00
|
|
|
static inline ClearGround GetRawClearGround(TileIndex t)
|
2006-03-30 09:29:01 +00:00
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_CLEAR));
|
2007-01-10 18:56:51 +00:00
|
|
|
return (ClearGround)GB(_m[t].m5, 2, 3);
|
2006-03-30 09:29:01 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 18:33:43 +00:00
|
|
|
/**
|
|
|
|
* Get the type of clear tile.
|
|
|
|
* @param t the tile to get the clear ground type of
|
|
|
|
* @pre IsTileType(t, MP_CLEAR)
|
|
|
|
* @return the ground type
|
|
|
|
*/
|
|
|
|
static inline ClearGround GetClearGround(TileIndex t)
|
|
|
|
{
|
|
|
|
if (IsSnowTile(t)) return CLEAR_SNOW;
|
|
|
|
return GetRawClearGround(t);
|
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Set the type of clear tile.
|
|
|
|
* @param t the tile to set the clear ground type of
|
|
|
|
* @param ct the ground type
|
|
|
|
* @pre IsTileType(t, MP_CLEAR)
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline bool IsClearGround(TileIndex t, ClearGround ct)
|
|
|
|
{
|
|
|
|
return GetClearGround(t) == ct;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Get the density of a non-field clear tile.
|
|
|
|
* @param t the tile to get the density of
|
|
|
|
* @pre IsTileType(t, MP_CLEAR)
|
|
|
|
* @return the density
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline uint GetClearDensity(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_CLEAR));
|
|
|
|
return GB(_m[t].m5, 0, 2);
|
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Increment the density of a non-field clear tile.
|
|
|
|
* @param t the tile to increment the density of
|
|
|
|
* @param d the amount to increment the density with
|
|
|
|
* @pre IsTileType(t, MP_CLEAR)
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline void AddClearDensity(TileIndex t, int d)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
|
|
|
|
_m[t].m5 += d;
|
|
|
|
}
|
|
|
|
|
2010-01-04 18:33:43 +00:00
|
|
|
/**
|
|
|
|
* Set the density of a non-field clear tile.
|
|
|
|
* @param t the tile to set the density of
|
|
|
|
* @param d the new density
|
|
|
|
* @pre IsTileType(t, MP_CLEAR)
|
|
|
|
*/
|
|
|
|
static inline void SetClearDensity(TileIndex t, uint d)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_CLEAR));
|
|
|
|
SB(_m[t].m5, 0, 2, d);
|
|
|
|
}
|
|
|
|
|
2006-03-30 09:29:01 +00:00
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Get the counter used to advance to the next clear density/field type.
|
|
|
|
* @param t the tile to get the counter of
|
|
|
|
* @pre IsTileType(t, MP_CLEAR)
|
|
|
|
* @return the value of the counter
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline uint GetClearCounter(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_CLEAR));
|
|
|
|
return GB(_m[t].m5, 5, 3);
|
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Increments the counter used to advance to the next clear density/field type.
|
|
|
|
* @param t the tile to increment the counter of
|
|
|
|
* @param c the amount to increment the counter with
|
|
|
|
* @pre IsTileType(t, MP_CLEAR)
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline void AddClearCounter(TileIndex t, int c)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
|
|
|
|
_m[t].m5 += c << 5;
|
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Sets the counter used to advance to the next clear density/field type.
|
|
|
|
* @param t the tile to set the counter of
|
|
|
|
* @param c the amount to set the counter to
|
|
|
|
* @pre IsTileType(t, MP_CLEAR)
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline void SetClearCounter(TileIndex t, uint c)
|
|
|
|
{
|
|
|
|
assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
|
|
|
|
SB(_m[t].m5, 5, 3, c);
|
|
|
|
}
|
2006-02-01 15:31:21 +00:00
|
|
|
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Sets ground type and density in one go, also sets the counter to 0
|
|
|
|
* @param t the tile to set the ground type and density for
|
|
|
|
* @param type the new ground type of the tile
|
|
|
|
* @param density the density of the ground tile
|
|
|
|
* @pre IsTileType(t, MP_CLEAR)
|
|
|
|
*/
|
2006-02-01 15:31:21 +00:00
|
|
|
static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint density)
|
|
|
|
{
|
2006-03-30 09:29:01 +00:00
|
|
|
assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
|
2006-02-01 15:31:21 +00:00
|
|
|
_m[t].m5 = 0 << 5 | type << 2 | density;
|
|
|
|
}
|
|
|
|
|
2006-03-30 09:29:01 +00:00
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Get the field type (production stage) of the field
|
|
|
|
* @param t the field to get the type of
|
|
|
|
* @pre GetClearGround(t) == CLEAR_FIELDS
|
|
|
|
* @return the field type
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline uint GetFieldType(TileIndex t)
|
|
|
|
{
|
2006-04-04 21:35:13 +00:00
|
|
|
assert(GetClearGround(t) == CLEAR_FIELDS);
|
2006-03-30 09:29:01 +00:00
|
|
|
return GB(_m[t].m3, 0, 4);
|
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Set the field type (production stage) of the field
|
|
|
|
* @param t the field to get the type of
|
|
|
|
* @param f the field type
|
|
|
|
* @pre GetClearGround(t) == CLEAR_FIELDS
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline void SetFieldType(TileIndex t, uint f)
|
|
|
|
{
|
2006-04-04 21:35:13 +00:00
|
|
|
assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete
|
2006-03-30 09:29:01 +00:00
|
|
|
SB(_m[t].m3, 0, 4, f);
|
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Get the industry (farm) that made the field
|
|
|
|
* @param t the field to get creating industry of
|
|
|
|
* @pre GetClearGround(t) == CLEAR_FIELDS
|
|
|
|
* @return the industry that made the field
|
|
|
|
*/
|
|
|
|
static inline IndustryID GetIndustryIndexOfField(TileIndex t)
|
2006-08-20 18:44:26 +00:00
|
|
|
{
|
|
|
|
assert(GetClearGround(t) == CLEAR_FIELDS);
|
2007-04-03 21:51:40 +00:00
|
|
|
return(IndustryID) _m[t].m2;
|
2006-08-20 18:44:26 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Set the industry (farm) that made the field
|
|
|
|
* @param t the field to get creating industry of
|
|
|
|
* @param i the industry that made the field
|
|
|
|
* @pre GetClearGround(t) == CLEAR_FIELDS
|
|
|
|
*/
|
|
|
|
static inline void SetIndustryIndexOfField(TileIndex t, IndustryID i)
|
2006-08-20 18:44:26 +00:00
|
|
|
{
|
|
|
|
assert(GetClearGround(t) == CLEAR_FIELDS);
|
|
|
|
_m[t].m2 = i;
|
|
|
|
}
|
2006-02-05 11:54:25 +00:00
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is there a fence at the south eastern border?
|
|
|
|
* @param t the tile to check for fences
|
2011-11-08 19:48:47 +00:00
|
|
|
* @pre IsClearGround(t, CLEAR_FIELDS)
|
2007-04-03 21:51:40 +00:00
|
|
|
* @return 0 if there is no fence, otherwise the fence type
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline uint GetFenceSE(TileIndex t)
|
|
|
|
{
|
2011-11-08 19:48:47 +00:00
|
|
|
assert(IsClearGround(t, CLEAR_FIELDS));
|
2006-03-30 09:29:01 +00:00
|
|
|
return GB(_m[t].m4, 2, 3);
|
|
|
|
}
|
2006-02-05 11:54:25 +00:00
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Sets the type of fence (and whether there is one) for the south
|
|
|
|
* eastern border.
|
|
|
|
* @param t the tile to check for fences
|
|
|
|
* @param h 0 if there is no fence, otherwise the fence type
|
2011-11-08 19:48:47 +00:00
|
|
|
* @pre IsClearGround(t, CLEAR_FIELDS)
|
2007-04-03 21:51:40 +00:00
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline void SetFenceSE(TileIndex t, uint h)
|
|
|
|
{
|
2011-11-08 19:48:47 +00:00
|
|
|
assert(IsClearGround(t, CLEAR_FIELDS));
|
2006-03-30 09:29:01 +00:00
|
|
|
SB(_m[t].m4, 2, 3, h);
|
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Is there a fence at the south western border?
|
|
|
|
* @param t the tile to check for fences
|
2011-11-08 19:48:47 +00:00
|
|
|
* @pre IsClearGround(t, CLEAR_FIELDS)
|
2007-04-03 21:51:40 +00:00
|
|
|
* @return 0 if there is no fence, otherwise the fence type
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline uint GetFenceSW(TileIndex t)
|
|
|
|
{
|
2011-11-08 19:48:47 +00:00
|
|
|
assert(IsClearGround(t, CLEAR_FIELDS));
|
2006-03-30 09:29:01 +00:00
|
|
|
return GB(_m[t].m4, 5, 3);
|
|
|
|
}
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Sets the type of fence (and whether there is one) for the south
|
|
|
|
* western border.
|
|
|
|
* @param t the tile to check for fences
|
|
|
|
* @param h 0 if there is no fence, otherwise the fence type
|
2011-11-08 19:48:47 +00:00
|
|
|
* @pre IsClearGround(t, CLEAR_FIELDS)
|
2007-04-03 21:51:40 +00:00
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline void SetFenceSW(TileIndex t, uint h)
|
|
|
|
{
|
2011-11-08 19:48:47 +00:00
|
|
|
assert(IsClearGround(t, CLEAR_FIELDS));
|
2006-03-30 09:29:01 +00:00
|
|
|
SB(_m[t].m4, 5, 3, h);
|
|
|
|
}
|
2006-02-05 11:54:25 +00:00
|
|
|
|
2011-11-08 19:48:47 +00:00
|
|
|
/**
|
|
|
|
* Is there a fence at the north eastern border?
|
|
|
|
* @param t the tile to check for fences
|
|
|
|
* @pre IsClearGround(t, CLEAR_FIELDS)
|
|
|
|
* @return 0 if there is no fence, otherwise the fence type
|
|
|
|
*/
|
|
|
|
static inline uint GetFenceNE(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsClearGround(t, CLEAR_FIELDS));
|
|
|
|
return GB(_m[t].m3, 5, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the type of fence (and whether there is one) for the north
|
|
|
|
* eastern border.
|
|
|
|
* @param t the tile to check for fences
|
|
|
|
* @param h 0 if there is no fence, otherwise the fence type
|
|
|
|
* @pre IsClearGround(t, CLEAR_FIELDS)
|
|
|
|
*/
|
|
|
|
static inline void SetFenceNE(TileIndex t, uint h)
|
|
|
|
{
|
|
|
|
assert(IsClearGround(t, CLEAR_FIELDS));
|
|
|
|
SB(_m[t].m3, 5, 3, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is there a fence at the north western border?
|
|
|
|
* @param t the tile to check for fences
|
|
|
|
* @pre IsClearGround(t, CLEAR_FIELDS)
|
|
|
|
* @return 0 if there is no fence, otherwise the fence type
|
|
|
|
*/
|
|
|
|
static inline uint GetFenceNW(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(IsClearGround(t, CLEAR_FIELDS));
|
|
|
|
return GB(_m[t].m6, 2, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the type of fence (and whether there is one) for the north
|
|
|
|
* western border.
|
|
|
|
* @param t the tile to check for fences
|
|
|
|
* @param h 0 if there is no fence, otherwise the fence type
|
|
|
|
* @pre IsClearGround(t, CLEAR_FIELDS)
|
|
|
|
*/
|
|
|
|
static inline void SetFenceNW(TileIndex t, uint h)
|
|
|
|
{
|
|
|
|
assert(IsClearGround(t, CLEAR_FIELDS));
|
|
|
|
SB(_m[t].m6, 2, 3, h);
|
|
|
|
}
|
|
|
|
|
2006-02-24 19:56:24 +00:00
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Make a clear tile.
|
|
|
|
* @param t the tile to make a clear tile
|
|
|
|
* @param g the type of ground
|
|
|
|
* @param density the density of the grass/snow/desert etc
|
|
|
|
*/
|
2006-02-24 19:56:24 +00:00
|
|
|
static inline void MakeClear(TileIndex t, ClearGround g, uint density)
|
|
|
|
{
|
2007-01-09 21:43:32 +00:00
|
|
|
/* If this is a non-bridgeable tile, clear the bridge bits while the rest
|
|
|
|
* of the tile information is still here. */
|
2007-01-11 02:05:13 +00:00
|
|
|
if (!MayHaveBridgeAbove(t)) SB(_m[t].m6, 6, 2, 0);
|
2007-01-09 21:43:32 +00:00
|
|
|
|
2006-02-24 19:56:24 +00:00
|
|
|
SetTileType(t, MP_CLEAR);
|
2010-08-11 14:14:06 +00:00
|
|
|
_m[t].m1 = 0;
|
2006-02-24 19:56:24 +00:00
|
|
|
SetTileOwner(t, OWNER_NONE);
|
|
|
|
_m[t].m2 = 0;
|
|
|
|
_m[t].m3 = 0;
|
|
|
|
_m[t].m4 = 0 << 5 | 0 << 2;
|
2009-03-08 16:10:39 +00:00
|
|
|
SetClearGroundDensity(t, g, density); // Sets m5
|
|
|
|
SB(_m[t].m6, 2, 4, 0); // Other bits are "tropic zone" and "bridge above"
|
|
|
|
_me[t].m7 = 0;
|
2006-03-22 08:48:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-03 21:51:40 +00:00
|
|
|
/**
|
|
|
|
* Make a (farm) field tile.
|
|
|
|
* @param t the tile to make a farm field
|
|
|
|
* @param field_type the 'growth' level of the field
|
|
|
|
* @param industry the industry this tile belongs to
|
|
|
|
*/
|
|
|
|
static inline void MakeField(TileIndex t, uint field_type, IndustryID industry)
|
2006-03-22 08:48:50 +00:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_CLEAR);
|
2010-08-11 14:14:06 +00:00
|
|
|
_m[t].m1 = 0;
|
2006-03-22 08:48:50 +00:00
|
|
|
SetTileOwner(t, OWNER_NONE);
|
2006-08-20 18:44:26 +00:00
|
|
|
_m[t].m2 = industry;
|
2006-03-22 08:48:50 +00:00
|
|
|
_m[t].m3 = field_type;
|
|
|
|
_m[t].m4 = 0 << 5 | 0 << 2;
|
2006-04-04 21:35:13 +00:00
|
|
|
SetClearGroundDensity(t, CLEAR_FIELDS, 3);
|
2009-03-08 16:10:39 +00:00
|
|
|
SB(_m[t].m6, 2, 4, 0);
|
|
|
|
_me[t].m7 = 0;
|
2006-02-24 19:56:24 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 18:33:43 +00:00
|
|
|
/**
|
|
|
|
* Make a snow tile.
|
|
|
|
* @param t the tile to make snowy
|
2011-05-02 20:59:54 +00:00
|
|
|
* @param density The density of snowiness.
|
2010-01-04 18:33:43 +00:00
|
|
|
* @pre GetClearGround(t) != CLEAR_SNOW
|
|
|
|
*/
|
2010-01-05 22:32:47 +00:00
|
|
|
static inline void MakeSnow(TileIndex t, uint density = 0)
|
2010-01-04 18:33:43 +00:00
|
|
|
{
|
|
|
|
assert(GetClearGround(t) != CLEAR_SNOW);
|
|
|
|
SetBit(_m[t].m3, 4);
|
2010-12-01 21:35:18 +00:00
|
|
|
if (GetRawClearGround(t) == CLEAR_FIELDS) {
|
2010-01-05 22:32:47 +00:00
|
|
|
SetClearGroundDensity(t, CLEAR_GRASS, density);
|
2010-01-04 18:33:43 +00:00
|
|
|
} else {
|
2010-01-05 22:32:47 +00:00
|
|
|
SetClearDensity(t, density);
|
2010-01-04 18:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-04-12 14:12:47 +00:00
|
|
|
* Clear the snow from a tile and return it to its previous type.
|
2010-01-04 18:33:43 +00:00
|
|
|
* @param t the tile to clear of snow
|
|
|
|
* @pre GetClearGround(t) == CLEAR_SNOW
|
|
|
|
*/
|
|
|
|
static inline void ClearSnow(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(GetClearGround(t) == CLEAR_SNOW);
|
|
|
|
ClrBit(_m[t].m3, 4);
|
|
|
|
SetClearDensity(t, 3);
|
|
|
|
}
|
|
|
|
|
2006-09-28 18:42:35 +00:00
|
|
|
#endif /* CLEAR_MAP_H */
|