2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2005-01-29 12:19:05 +00:00
|
|
|
#ifndef TILE_H
|
|
|
|
#define TILE_H
|
|
|
|
|
2005-02-22 12:48:03 +00:00
|
|
|
#include "macros.h"
|
2005-01-29 12:19:05 +00:00
|
|
|
#include "map.h"
|
|
|
|
|
2005-06-17 00:22:46 +00:00
|
|
|
typedef enum TileTypes {
|
2005-01-29 15:12:40 +00:00
|
|
|
MP_CLEAR,
|
|
|
|
MP_RAILWAY,
|
|
|
|
MP_STREET,
|
|
|
|
MP_HOUSE,
|
|
|
|
MP_TREES,
|
|
|
|
MP_STATION,
|
|
|
|
MP_WATER,
|
|
|
|
MP_VOID, // invisible tiles at the SW and SE border
|
|
|
|
MP_INDUSTRY,
|
|
|
|
MP_TUNNELBRIDGE,
|
2005-07-19 11:42:40 +00:00
|
|
|
MP_UNMOVABLE,
|
2005-01-29 15:12:40 +00:00
|
|
|
} TileType;
|
|
|
|
|
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
|
|
|
/* Direction as commonly used in v->direction, 8 way. */
|
|
|
|
typedef enum Directions {
|
|
|
|
DIR_N = 0,
|
|
|
|
DIR_NE = 1, /* Northeast, upper right on your monitor */
|
|
|
|
DIR_E = 2,
|
|
|
|
DIR_SE = 3,
|
|
|
|
DIR_S = 4,
|
|
|
|
DIR_SW = 5,
|
|
|
|
DIR_W = 6,
|
|
|
|
DIR_NW = 7,
|
|
|
|
DIR_END,
|
|
|
|
INVALID_DIR = 0xFF,
|
|
|
|
} Direction;
|
2005-05-02 18:53:06 +00:00
|
|
|
|
(svn r2448) General cleanup of rail related code, more to follow.
* Add: rail.[ch] for rail-related enums and wrapper functions.
* Codechange: Removed dozens of magic numbers with below enums.
* Codechange: Rewrote CheckTrackCombination().
* Add: TILE_SIZE, TILE_PIXELS and TILE_HEIGHT constants.
* Add: enums RailTileType, RailTileSubtype, SignalType to mask against the map arrays.
* Add: enums Track, TrackBits, Trackdir, TrackdirBits for railway track data. (Note that the old RAIL_BIT constants are replaced by TRACK_BIT ones).
* Add: enums Direction and DiagDirection
* Codechange: Moved a bunch of track(dir) related lookup arrays from npf.[ch] to rail.[ch].
* Codechange: move RailType enum from tile.h to rail.h.
* Add: Wrapper functions for masking signal status in the map arrays: SignalAlongTrackdir, SignalAgainstTrackdir and SignalOnTrack.
* Add: Wrapper functions to access rail tiles, using above enums
* Add: Wrapper functions to modify tracks, trackdirs, directions, etc.
* Add: Wrapper functions for all lookup arrays in rail.[ch] (Arrays are still used in parts of the code)
* Codechange: Renamed some variables and arguments to better represent what they contain (railbit -> track, bits -> trackdirbits, etc.).
* Codechange: Don't use FindLandscapeHeight() in CmdRemoveSingleRail(), since it returns way too much info. Use GetTileSlope() instead.
* Codechange: [NPF] Removed some unused globals and code from npf.c.
2005-06-16 18:04:02 +00:00
|
|
|
/* Direction commonly used as the direction of entering and leaving tiles, 4-way */
|
|
|
|
typedef enum DiagonalDirections {
|
|
|
|
DIAGDIR_NE = 0, /* Northeast, upper right on your monitor */
|
|
|
|
DIAGDIR_SE = 1,
|
|
|
|
DIAGDIR_SW = 2,
|
|
|
|
DIAGDIR_NW = 3,
|
|
|
|
DIAGDIR_END,
|
|
|
|
INVALID_DIAGDIR = 0xFF,
|
|
|
|
} DiagDirection;
|
2005-05-02 18:53:06 +00:00
|
|
|
|
2006-02-28 21:19:50 +00:00
|
|
|
/* the 2 axis */
|
|
|
|
typedef enum Axis {
|
|
|
|
AXIS_X = 0,
|
|
|
|
AXIS_Y = 1
|
|
|
|
} Axis;
|
|
|
|
|
2005-01-29 13:33:48 +00:00
|
|
|
void SetMapExtraBits(TileIndex tile, byte flags);
|
|
|
|
uint GetMapExtraBits(TileIndex tile);
|
2005-02-07 10:41:45 +00:00
|
|
|
|
|
|
|
uint GetTileSlope(TileIndex tile, uint *h);
|
|
|
|
uint GetTileZ(TileIndex tile);
|
2005-01-29 13:33:48 +00:00
|
|
|
|
2005-02-22 12:48:03 +00:00
|
|
|
static inline bool CorrectZ(uint tileh)
|
|
|
|
{
|
|
|
|
/* tile height must be corrected if the north corner is not raised, but
|
|
|
|
* any other corner is. These are the cases 1 till 7 */
|
|
|
|
return IS_INT_INSIDE(tileh, 1, 8);
|
|
|
|
}
|
|
|
|
|
2005-01-29 12:19:05 +00:00
|
|
|
static inline uint TileHeight(TileIndex tile)
|
|
|
|
{
|
|
|
|
assert(tile < MapSize());
|
2005-07-13 18:04:01 +00:00
|
|
|
return GB(_m[tile].type_height, 0, 4);
|
2005-01-29 12:19:05 +00:00
|
|
|
}
|
|
|
|
|
2005-07-16 23:47:37 +00:00
|
|
|
static inline bool IsSteepTileh(uint tileh)
|
|
|
|
{
|
|
|
|
return (tileh & 0x10);
|
|
|
|
}
|
|
|
|
|
2005-01-29 12:19:05 +00:00
|
|
|
static inline void SetTileHeight(TileIndex tile, uint height)
|
|
|
|
{
|
|
|
|
assert(tile < MapSize());
|
|
|
|
assert(height < 16);
|
2005-07-13 18:04:01 +00:00
|
|
|
SB(_m[tile].type_height, 0, 4, height);
|
2005-01-29 12:19:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint TilePixelHeight(TileIndex tile)
|
|
|
|
{
|
|
|
|
return TileHeight(tile) * 8;
|
|
|
|
}
|
|
|
|
|
2005-01-29 15:12:40 +00:00
|
|
|
static inline TileType GetTileType(TileIndex tile)
|
2005-01-29 12:19:05 +00:00
|
|
|
{
|
|
|
|
assert(tile < MapSize());
|
2005-07-13 18:04:01 +00:00
|
|
|
return GB(_m[tile].type_height, 4, 4);
|
2005-01-29 12:19:05 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 15:12:40 +00:00
|
|
|
static inline void SetTileType(TileIndex tile, TileType type)
|
2005-01-29 12:19:05 +00:00
|
|
|
{
|
|
|
|
assert(tile < MapSize());
|
2006-01-28 09:45:25 +00:00
|
|
|
/* Allow only MP_VOID to be set to border tiles. This code is put here since
|
|
|
|
* it seems there is a bug that violates this somewhere. (Formely know as
|
|
|
|
* the "old ship pf" bug, which presented a case in which this broke). It
|
|
|
|
* can be removed as soon as the bug is squashed. */
|
|
|
|
assert((TileX(tile) < MapMaxX() && TileY(tile) < MapMaxY()) || type == MP_VOID);
|
2005-07-13 18:04:01 +00:00
|
|
|
SB(_m[tile].type_height, 4, 4, type);
|
2005-01-29 12:19:05 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 15:12:40 +00:00
|
|
|
static inline bool IsTileType(TileIndex tile, TileType type)
|
2005-01-29 12:19:05 +00:00
|
|
|
{
|
2005-01-29 15:12:40 +00:00
|
|
|
return GetTileType(tile) == type;
|
2005-01-29 12:19:05 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 11:42:40 +00:00
|
|
|
static inline bool IsTunnelTile(TileIndex tile)
|
|
|
|
{
|
2005-10-05 07:20:26 +00:00
|
|
|
return IsTileType(tile, MP_TUNNELBRIDGE) && GB(_m[tile].m5, 4, 4) == 0;
|
2005-07-19 11:42:40 +00:00
|
|
|
}
|
|
|
|
|
2005-02-07 10:09:28 +00:00
|
|
|
static inline Owner GetTileOwner(TileIndex tile)
|
2005-02-06 22:36:08 +00:00
|
|
|
{
|
2005-02-07 10:09:28 +00:00
|
|
|
assert(tile < MapSize());
|
2005-06-03 22:43:59 +00:00
|
|
|
assert(!IsTileType(tile, MP_HOUSE));
|
|
|
|
assert(!IsTileType(tile, MP_VOID));
|
|
|
|
assert(!IsTileType(tile, MP_INDUSTRY));
|
|
|
|
|
2005-08-23 18:47:04 +00:00
|
|
|
return _m[tile].m1;
|
2005-02-06 22:36:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-04 12:13:24 +00:00
|
|
|
static inline void SetTileOwner(TileIndex tile, Owner owner)
|
|
|
|
{
|
|
|
|
assert(tile < MapSize());
|
|
|
|
assert(!IsTileType(tile, MP_HOUSE));
|
|
|
|
assert(!IsTileType(tile, MP_VOID));
|
|
|
|
assert(!IsTileType(tile, MP_INDUSTRY));
|
|
|
|
|
2005-08-23 18:47:04 +00:00
|
|
|
_m[tile].m1 = owner;
|
2005-06-04 12:13:24 +00:00
|
|
|
}
|
|
|
|
|
2005-02-06 22:36:08 +00:00
|
|
|
static inline bool IsTileOwner(TileIndex tile, Owner owner)
|
|
|
|
{
|
|
|
|
return GetTileOwner(tile) == owner;
|
|
|
|
}
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
#endif /* TILE_H */
|