mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r25852) -Codechange: Merge GetFenceXX/SetFenceXX into one common GetFonce/SetFence for all directions that take an extra direction parameter (cirdan, LordAro)
This commit is contained in:
parent
a42f223b2b
commit
fb5dc7762b
@ -65,22 +65,22 @@ static void DrawClearLandFence(const TileInfo *ti)
|
||||
|
||||
int maxz = GetSlopeMaxPixelZ(ti->tileh);
|
||||
|
||||
uint fence_nw = GetFenceNW(ti->tile);
|
||||
uint fence_nw = GetFence(ti->tile, DIAGDIR_NW);
|
||||
if (fence_nw != 0) {
|
||||
int z = GetSlopePixelZInCorner(ti->tileh, CORNER_W);
|
||||
SpriteID sprite = _clear_land_fence_sprites[fence_nw - 1] + _fence_mod_by_tileh_nw[ti->tileh];
|
||||
AddSortableSpriteToDraw(sprite, PAL_NONE, ti->x, ti->y - 15, 16, 31, maxz - z + 4, ti->z + z, false, 0, 15, -z);
|
||||
}
|
||||
|
||||
uint fence_ne = GetFenceNE(ti->tile);
|
||||
uint fence_ne = GetFence(ti->tile, DIAGDIR_NE);
|
||||
if (fence_ne != 0) {
|
||||
int z = GetSlopePixelZInCorner(ti->tileh, CORNER_E);
|
||||
SpriteID sprite = _clear_land_fence_sprites[fence_ne - 1] + _fence_mod_by_tileh_ne[ti->tileh];
|
||||
AddSortableSpriteToDraw(sprite, PAL_NONE, ti->x - 15, ti->y, 31, 16, maxz - z + 4, ti->z + z, false, 15, 0, -z);
|
||||
}
|
||||
|
||||
uint fence_sw = GetFenceSW(ti->tile);
|
||||
uint fence_se = GetFenceSE(ti->tile);
|
||||
uint fence_sw = GetFence(ti->tile, DIAGDIR_SW);
|
||||
uint fence_se = GetFence(ti->tile, DIAGDIR_SE);
|
||||
|
||||
if (fence_sw != 0 || fence_se != 0) {
|
||||
int z = GetSlopePixelZInCorner(ti->tileh, CORNER_S);
|
||||
@ -146,26 +146,26 @@ static void UpdateFences(TileIndex tile)
|
||||
bool dirty = false;
|
||||
|
||||
bool neighbour = (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CLEAR_FIELDS));
|
||||
if (!neighbour && GetFenceSW(tile) == 0) {
|
||||
SetFenceSW(tile, 3);
|
||||
if (!neighbour && GetFence(tile, DIAGDIR_SW) == 0) {
|
||||
SetFence(tile, DIAGDIR_SW, 3);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
neighbour = (IsTileType(TILE_ADDXY(tile, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 0, 1), CLEAR_FIELDS));
|
||||
if (!neighbour && GetFenceSE(tile) == 0) {
|
||||
SetFenceSE(tile, 3);
|
||||
if (!neighbour && GetFence(tile, DIAGDIR_SE) == 0) {
|
||||
SetFence(tile, DIAGDIR_SE, 3);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
neighbour = (IsTileType(TILE_ADDXY(tile, -1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, -1, 0), CLEAR_FIELDS));
|
||||
if (!neighbour && GetFenceNE(tile) == 0) {
|
||||
SetFenceNE(tile, 3);
|
||||
if (!neighbour && GetFence(tile, DIAGDIR_NE) == 0) {
|
||||
SetFence(tile, DIAGDIR_NE, 3);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
neighbour = (IsTileType(TILE_ADDXY(tile, 0, -1), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 0, -1), CLEAR_FIELDS));
|
||||
if (!neighbour && GetFenceNW(tile) == 0) {
|
||||
SetFenceNW(tile, 3);
|
||||
if (!neighbour && GetFence(tile, DIAGDIR_NW) == 0) {
|
||||
SetFence(tile, DIAGDIR_NW, 3);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
|
100
src/clear_map.h
100
src/clear_map.h
@ -214,103 +214,41 @@ static inline void SetIndustryIndexOfField(TileIndex t, IndustryID i)
|
||||
|
||||
|
||||
/**
|
||||
* Is there a fence at the south eastern border?
|
||||
* Is there a fence at the given border?
|
||||
* @param t the tile to check for fences
|
||||
* @param side the border to check
|
||||
* @pre IsClearGround(t, CLEAR_FIELDS)
|
||||
* @return 0 if there is no fence, otherwise the fence type
|
||||
*/
|
||||
static inline uint GetFenceSE(TileIndex t)
|
||||
static inline uint GetFence(TileIndex t, DiagDirection side)
|
||||
{
|
||||
assert(IsClearGround(t, CLEAR_FIELDS));
|
||||
return GB(_m[t].m4, 2, 3);
|
||||
switch (side) {
|
||||
default: NOT_REACHED();
|
||||
case DIAGDIR_SE: return GB(_m[t].m4, 2, 3);
|
||||
case DIAGDIR_SW: return GB(_m[t].m4, 5, 3);
|
||||
case DIAGDIR_NE: return GB(_m[t].m3, 5, 3);
|
||||
case DIAGDIR_NW: return GB(_m[t].m6, 2, 3);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of fence (and whether there is one) for the south
|
||||
* eastern border.
|
||||
* Sets the type of fence (and whether there is one) for the given border.
|
||||
* @param t the tile to check for fences
|
||||
* @param side the border to check
|
||||
* @param h 0 if there is no fence, otherwise the fence type
|
||||
* @pre IsClearGround(t, CLEAR_FIELDS)
|
||||
*/
|
||||
static inline void SetFenceSE(TileIndex t, uint h)
|
||||
static inline void SetFence(TileIndex t, DiagDirection side, uint h)
|
||||
{
|
||||
assert(IsClearGround(t, CLEAR_FIELDS));
|
||||
SB(_m[t].m4, 2, 3, h);
|
||||
switch (side) {
|
||||
default: NOT_REACHED();
|
||||
case DIAGDIR_SE: SB(_m[t].m4, 2, 3, h); break;
|
||||
case DIAGDIR_SW: SB(_m[t].m4, 5, 3, h); break;
|
||||
case DIAGDIR_NE: SB(_m[t].m3, 5, 3, h); break;
|
||||
case DIAGDIR_NW: SB(_m[t].m6, 2, 3, h); break;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there a fence at the south 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 GetFenceSW(TileIndex t)
|
||||
{
|
||||
assert(IsClearGround(t, CLEAR_FIELDS));
|
||||
return GB(_m[t].m4, 5, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @pre IsClearGround(t, CLEAR_FIELDS)
|
||||
*/
|
||||
static inline void SetFenceSW(TileIndex t, uint h)
|
||||
{
|
||||
assert(IsClearGround(t, CLEAR_FIELDS));
|
||||
SB(_m[t].m4, 5, 3, h);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -968,15 +968,15 @@ static void SetupFarmFieldFence(TileIndex tile, int size, byte type, Axis direct
|
||||
|
||||
if (direction == AXIS_X) {
|
||||
if (north) {
|
||||
SetFenceNW(tile, or_);
|
||||
SetFence(tile, DIAGDIR_NW, or_);
|
||||
} else {
|
||||
SetFenceSE(tile, or_);
|
||||
SetFence(tile, DIAGDIR_SE, or_);
|
||||
}
|
||||
} else {
|
||||
if (north) {
|
||||
SetFenceNE(tile, or_);
|
||||
SetFence(tile, DIAGDIR_NE, or_);
|
||||
} else {
|
||||
SetFenceSW(tile, or_);
|
||||
SetFence(tile, DIAGDIR_SW, or_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2695,11 +2695,11 @@ bool AfterLoadGame()
|
||||
if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_FIELDS)) continue;
|
||||
uint fence = GB(_m[t].m4, 5, 3);
|
||||
if (fence != 0 && IsTileType(TILE_ADDXY(t, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(t, 1, 0), CLEAR_FIELDS)) {
|
||||
SetFenceNE(TILE_ADDXY(t, 1, 0), fence);
|
||||
SetFence(TILE_ADDXY(t, 1, 0), DIAGDIR_NE, fence);
|
||||
}
|
||||
fence = GB(_m[t].m4, 2, 3);
|
||||
if (fence != 0 && IsTileType(TILE_ADDXY(t, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(t, 0, 1), CLEAR_FIELDS)) {
|
||||
SetFenceNW(TILE_ADDXY(t, 0, 1), fence);
|
||||
SetFence(TILE_ADDXY(t, 0, 1), DIAGDIR_NW, fence);
|
||||
}
|
||||
SB(_m[t].m4, 2, 3, 0);
|
||||
SB(_m[t].m4, 5, 3, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user