mirror of https://github.com/OpenTTD/OpenTTD
(svn r3554) Add accessors for the field type and fences of clear tiles
parent
02c4e63fac
commit
6132fcea44
10
clear.h
10
clear.h
|
@ -33,4 +33,14 @@ static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint den
|
||||||
_m[t].m5 = 0 << 5 | type << 2 | density;
|
_m[t].m5 = 0 << 5 | type << 2 | density;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline uint GetFieldType(TileIndex t) { return GB(_m[t].m3, 0, 4); }
|
||||||
|
static inline void SetFieldType(TileIndex t, uint f) { SB(_m[t].m3, 0, 4, f); }
|
||||||
|
|
||||||
|
/* Is used by tree tiles, too */
|
||||||
|
static inline uint GetFenceSE(TileIndex t) { return GB(_m[t].m4, 2, 3); }
|
||||||
|
static inline void SetFenceSE(TileIndex t, uint h) { SB(_m[t].m4, 2, 3, h); }
|
||||||
|
|
||||||
|
static inline uint GetFenceSW(TileIndex t) { return GB(_m[t].m4, 5, 3); }
|
||||||
|
static inline void SetFenceSW(TileIndex t, uint h) { SB(_m[t].m4, 5, 3, h); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
27
clear_cmd.c
27
clear_cmd.c
|
@ -482,7 +482,6 @@ void DrawHillyLandTile(const TileInfo *ti)
|
||||||
|
|
||||||
void DrawClearLandFence(const TileInfo *ti)
|
void DrawClearLandFence(const TileInfo *ti)
|
||||||
{
|
{
|
||||||
byte m4 = _m[ti->tile].m4;
|
|
||||||
byte z = ti->z;
|
byte z = ti->z;
|
||||||
|
|
||||||
if (ti->tileh & 2) {
|
if (ti->tileh & 2) {
|
||||||
|
@ -490,12 +489,12 @@ void DrawClearLandFence(const TileInfo *ti)
|
||||||
if (ti->tileh == 0x17) z += 8;
|
if (ti->tileh == 0x17) z += 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GB(m4, 5, 3) != 0) {
|
if (GetFenceSW(ti->tile) != 0) {
|
||||||
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(m4, 5, 3) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z);
|
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSW(ti->tile) - 1] + _fence_mod_by_tileh[ti->tileh], ti->x, ti->y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GB(m4, 2, 3) != 0) {
|
if (GetFenceSE(ti->tile) != 0) {
|
||||||
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GB(m4, 2, 3) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z);
|
DrawGroundSpriteAt(_clear_land_fence_sprites_1[GetFenceSE(ti->tile) - 1] + _fence_mod_by_tileh_2[ti->tileh], ti->x, ti->y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,7 +514,7 @@ static void DrawTile_Clear(TileInfo *ti)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CL_FIELDS:
|
case CL_FIELDS:
|
||||||
DrawGroundSprite(_clear_land_sprites_1[GB(_m[ti->tile].m3, 0, 4)] + _tileh_to_sprite[ti->tileh]);
|
DrawGroundSprite(_clear_land_sprites_1[GetFieldType(ti->tile)] + _tileh_to_sprite[ti->tileh]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CL_SNOW:
|
case CL_SNOW:
|
||||||
|
@ -559,27 +558,27 @@ void TileLoopClearHelper(TileIndex tile)
|
||||||
self = (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CL_FIELDS));
|
self = (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CL_FIELDS));
|
||||||
|
|
||||||
neighbour = (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CL_FIELDS));
|
neighbour = (IsTileType(TILE_ADDXY(tile, 1, 0), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 1, 0), CL_FIELDS));
|
||||||
if (GB(_m[tile].m4, 5, 3) == 0) {
|
if (GetFenceSW(tile) == 0) {
|
||||||
if (self != neighbour) {
|
if (self != neighbour) {
|
||||||
SB(_m[tile].m4, 5, 3, 3);
|
SetFenceSW(tile, 3);
|
||||||
dirty = tile;
|
dirty = tile;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (self == 0 && neighbour == 0) {
|
if (self == 0 && neighbour == 0) {
|
||||||
SB(_m[tile].m4, 5, 3, 0);
|
SetFenceSW(tile, 0);
|
||||||
dirty = tile;
|
dirty = tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
neighbour = (IsTileType(TILE_ADDXY(tile, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 0, 1), CL_FIELDS));
|
neighbour = (IsTileType(TILE_ADDXY(tile, 0, 1), MP_CLEAR) && IsClearGround(TILE_ADDXY(tile, 0, 1), CL_FIELDS));
|
||||||
if (GB(_m[tile].m4, 2, 3) == 0) {
|
if (GetFenceSE(tile) == 0) {
|
||||||
if (self != neighbour) {
|
if (self != neighbour) {
|
||||||
SB(_m[tile].m4, 2, 3, 3);
|
SetFenceSE(tile, 3);
|
||||||
dirty = tile;
|
dirty = tile;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (self == 0 && neighbour == 0) {
|
if (self == 0 && neighbour == 0) {
|
||||||
SB(_m[tile].m4, 2, 3, 0);
|
SetFenceSE(tile, 0);
|
||||||
dirty = tile;
|
dirty = tile;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -673,9 +672,9 @@ static void TileLoop_Clear(TileIndex tile)
|
||||||
SetClearCounter(tile, 0);
|
SetClearCounter(tile, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
field_type = GB(_m[tile].m3, 0, 4);
|
field_type = GetFieldType(tile);
|
||||||
field_type = (field_type < 8) ? field_type + 1 : 0;
|
field_type = (field_type < 8) ? field_type + 1 : 0;
|
||||||
SB(_m[tile].m3, 0, 4, field_type);
|
SetFieldType(tile, field_type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -903,23 +903,19 @@ static bool IsBadFarmFieldTile2(TileIndex tile)
|
||||||
|
|
||||||
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, int direction)
|
static void SetupFarmFieldFence(TileIndex tile, int size, byte type, int direction)
|
||||||
{
|
{
|
||||||
byte or, and;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
tile = TILE_MASK(tile);
|
tile = TILE_MASK(tile);
|
||||||
|
|
||||||
if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
|
if (IsTileType(tile, MP_CLEAR) || IsTileType(tile, MP_TREES)) {
|
||||||
|
byte or = type;
|
||||||
|
|
||||||
or = type;
|
|
||||||
if (or == 1 && CHANCE16(1, 7)) or = 2;
|
if (or == 1 && CHANCE16(1, 7)) or = 2;
|
||||||
|
|
||||||
or <<= 2;
|
|
||||||
and = (byte)~0x1C;
|
|
||||||
if (direction) {
|
if (direction) {
|
||||||
or <<= 3;
|
SetFenceSW(tile, or);
|
||||||
and = (byte)~0xE0;
|
} else {
|
||||||
|
SetFenceSE(tile, or);
|
||||||
}
|
}
|
||||||
_m[tile].m4 = (_m[tile].m4 & and) | or;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
|
tile += direction ? TileDiffXY(0, 1) : TileDiffXY(1, 0);
|
||||||
|
@ -931,7 +927,9 @@ static void PlantFarmField(TileIndex tile)
|
||||||
uint size_x, size_y;
|
uint size_x, size_y;
|
||||||
uint32 r;
|
uint32 r;
|
||||||
uint count;
|
uint count;
|
||||||
int type, type2;
|
uint counter;
|
||||||
|
uint field_type;
|
||||||
|
int type;
|
||||||
|
|
||||||
if (_opt.landscape == LT_HILLY) {
|
if (_opt.landscape == LT_HILLY) {
|
||||||
if (GetTileZ(tile) + 16 >= _opt.snow_line)
|
if (GetTileZ(tile) + 16 >= _opt.snow_line)
|
||||||
|
@ -957,19 +955,21 @@ static void PlantFarmField(TileIndex tile)
|
||||||
|
|
||||||
/* determine type of field */
|
/* determine type of field */
|
||||||
r = Random();
|
r = Random();
|
||||||
type = ((r & 0xE0) | 0xF);
|
counter = GB(r, 5, 3);
|
||||||
type2 = GB(r, 8, 8) * 9 >> 8;
|
field_type = GB(r, 8, 8) * 9 >> 8;
|
||||||
|
|
||||||
/* make field */
|
/* make field */
|
||||||
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile)
|
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile)
|
||||||
cur_tile = TILE_MASK(cur_tile);
|
cur_tile = TILE_MASK(cur_tile);
|
||||||
if (!IsBadFarmFieldTile2(cur_tile)) {
|
if (!IsBadFarmFieldTile2(cur_tile)) {
|
||||||
ModifyTile(cur_tile,
|
SetTileType(cur_tile, MP_CLEAR);
|
||||||
MP_SETTYPE(MP_CLEAR) |
|
SetTileOwner(cur_tile, OWNER_NONE);
|
||||||
MP_MAP2_CLEAR | MP_MAP3LO | MP_MAP3HI_CLEAR | MP_MAPOWNER | MP_MAP5,
|
SetFieldType(cur_tile, field_type);
|
||||||
type2, /* map3_lo */
|
SetFenceSW(cur_tile, 0);
|
||||||
OWNER_NONE, /* map_owner */
|
SetFenceSE(cur_tile, 0);
|
||||||
type); /* map5 */
|
SetClearGroundDensity(cur_tile, CL_FIELDS, 3);
|
||||||
|
SetClearCounter(cur_tile, counter);
|
||||||
|
MarkTileDirtyByTile(cur_tile);
|
||||||
}
|
}
|
||||||
END_TILE_LOOP(cur_tile, size_x, size_y, tile)
|
END_TILE_LOOP(cur_tile, size_x, size_y, tile)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue