Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rail fences in snow or desert #7024

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Rail fences in snow or desert

  • Loading branch information
pi1985 committed Jan 6, 2019
commit f09986f10744409d68a22b9314e26fef667608e3
@@ -364,7 +364,11 @@ uint32 GetTerrainType(TileIndex tile, TileContext context)
/* During map generation the snowstate may not be valid yet, as the tileloop may not have run yet. */
if (_generating_world) goto genworld; // we do not care about foundations here
RailGroundType ground = GetRailGroundType(tile);
has_snow = (ground == RAIL_GROUND_ICE_DESERT || (context == TCX_UPPER_HALFTILE && ground == RAIL_GROUND_HALF_SNOW));
has_snow = ( (ground == RAIL_GROUND_ICE_DESERT ||
ground == RAIL_GROUND_ICE_DESERT_FENCE_1 ||
ground == RAIL_GROUND_ICE_DESERT_FENCE_2 ||
ground == RAIL_GROUND_ICE_DESERT_FENCE_1_2) ||
(context == TCX_UPPER_HALFTILE && (ground == RAIL_GROUND_HALF_SNOW || ground == RAIL_GROUND_HALF_SNOW_FENCE)));
break;
}

@@ -775,15 +775,15 @@ bool FloodHalftile(TileIndex t)

if (IsNonContinuousFoundation(GetRailFoundation(tileh, rail_bits))) {
flooded = true;
SetRailGroundType(t, RAIL_GROUND_WATER);
SetRailGroundType(t, RAIL_GROUND_WATER_FENCE);
MarkTileDirtyByTile(t);
}
} else {
/* Make shore on steep slopes and 'three-corners-raised'-slopes. */
if (ApplyFoundationToSlope(GetRailFoundation(tileh, rail_bits), &tileh) == 0) {
if (IsSteepSlope(tileh) || IsSlopeWithThreeCornersRaised(tileh)) {
flooded = true;
SetRailGroundType(t, RAIL_GROUND_WATER);
SetRailGroundType(t, RAIL_GROUND_WATER_FENCE);
MarkTileDirtyByTile(t);
}
}
@@ -1996,6 +1996,35 @@ static void DrawTrackFence_SW(const TileInfo *ti, SpriteID base_image, uint num_
DrawTrackFence(ti, base_image, num_sprites, rfo);
}

/**
* Determine direction of fence
* @param tile - tile with rails
* @return rail fence direction
*/
static byte DetermineFenceDirection(TileIndex tile)
{
TrackBits rail = GetTrackBits(tile);

Owner owner = GetTileOwner(tile);
byte fences = 0;

for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
static const TrackBits dir_to_trackbits[DIAGDIR_END] = {TRACK_BIT_3WAY_NE, TRACK_BIT_3WAY_SE, TRACK_BIT_3WAY_SW, TRACK_BIT_3WAY_NW};

// Track bit on this edge => no fence.
if ((rail & dir_to_trackbits[d]) != TRACK_BIT_NONE) continue;

TileIndex tile2 = tile + TileOffsByDiagDir(d);

// Show fences if it's a house, industry, object, road, tunnelbridge or not owned by us.
if (!IsValidTile(tile2) || IsTileType(tile2, MP_HOUSE) || IsTileType(tile2, MP_INDUSTRY) ||
IsTileType(tile2, MP_ROAD) || (IsTileType(tile2, MP_OBJECT) && !IsObjectType(tile2, OBJECT_OWNED_LAND)) || IsTileType(tile2, MP_TUNNELBRIDGE) || !IsTileOwner(tile2, owner)) {
fences |= 1 << d;
}
}
return fences;
}

/**
* Draw track fences.
* @param ti Tile drawing information.
@@ -2015,19 +2044,108 @@ static void DrawTrackDetails(const TileInfo *ti, const RailtypeInfo *rti)
assert(num_sprites > 0);

switch (GetRailGroundType(ti->tile)) {
case RAIL_GROUND_FENCE_NW: DrawTrackFence_NW(ti, base_image, num_sprites); break;
case RAIL_GROUND_FENCE_SE: DrawTrackFence_SE(ti, base_image, num_sprites); break;
case RAIL_GROUND_FENCE_SENW: DrawTrackFence_NW(ti, base_image, num_sprites);
DrawTrackFence_SE(ti, base_image, num_sprites); break;
case RAIL_GROUND_FENCE_NE: DrawTrackFence_NE(ti, base_image, num_sprites); break;
case RAIL_GROUND_FENCE_SW: DrawTrackFence_SW(ti, base_image, num_sprites); break;
case RAIL_GROUND_FENCE_NESW: DrawTrackFence_NE(ti, base_image, num_sprites);
DrawTrackFence_SW(ti, base_image, num_sprites); break;
case RAIL_GROUND_FENCE_VERT1: DrawTrackFence(ti, base_image, num_sprites, RFO_FLAT_LEFT); break;
case RAIL_GROUND_FENCE_VERT2: DrawTrackFence(ti, base_image, num_sprites, RFO_FLAT_RIGHT); break;
case RAIL_GROUND_FENCE_HORIZ1: DrawTrackFence(ti, base_image, num_sprites, RFO_FLAT_UPPER); break;
case RAIL_GROUND_FENCE_HORIZ2: DrawTrackFence(ti, base_image, num_sprites, RFO_FLAT_LOWER); break;
case RAIL_GROUND_WATER: {
// No fences on this grounds
case RAIL_GROUND_BARREN:
case RAIL_GROUND_GRASS:
case RAIL_GROUND_ICE_DESERT:
case RAIL_GROUND_HALF_SNOW:
case RAIL_GROUND_WATER:
break;

// Drawing only fence 1
case RAIL_GROUND_GRASS_FENCE_1:
case RAIL_GROUND_ICE_DESERT_FENCE_1: {
byte fences = DetermineFenceDirection(ti->tile);

switch (fences) {
case (1 << DIAGDIR_SE):
DrawTrackFence_SE(ti, base_image, num_sprites);
break;
case (1 << DIAGDIR_SW):
DrawTrackFence_SW(ti, base_image, num_sprites);
break;
case (1 << DIAGDIR_SW) | (1 << DIAGDIR_NW):
DrawTrackFence(ti, base_image, num_sprites, RFO_FLAT_RIGHT);
break;
case (1 << DIAGDIR_NE) | (1 << DIAGDIR_NW):
DrawTrackFence(ti, base_image, num_sprites, RFO_FLAT_LOWER);
break;
default:
break;
}
break;
}

//Drawing only fence 2
case RAIL_GROUND_GRASS_FENCE_2:
case RAIL_GROUND_ICE_DESERT_FENCE_2: {
byte fences = DetermineFenceDirection(ti->tile);

switch (fences) {
case (1 << DIAGDIR_NE):
DrawTrackFence_NE(ti, base_image, num_sprites);
break;
case (1 << DIAGDIR_NW):
DrawTrackFence_NW(ti, base_image, num_sprites);
break;
case (1 << DIAGDIR_NE) | (1 << DIAGDIR_SE):
DrawTrackFence(ti, base_image, num_sprites, RFO_FLAT_LEFT);
break;
case (1 << DIAGDIR_SE) | (1 << DIAGDIR_SW):
DrawTrackFence(ti, base_image, num_sprites, RFO_FLAT_UPPER);
break;
default:
break;
}
break;
}

//Drawing fence 1 and 2
case RAIL_GROUND_GRASS_FENCE_1_2:
case RAIL_GROUND_ICE_DESERT_FENCE_1_2:
case RAIL_GROUND_HALF_SNOW_FENCE: {
byte fences = DetermineFenceDirection(ti->tile);

switch (fences) {
case (1 << DIAGDIR_SE):
DrawTrackFence_SE(ti, base_image, num_sprites);
break;
case (1 << DIAGDIR_SW):
DrawTrackFence_SW(ti, base_image, num_sprites);
break;
case (1 << DIAGDIR_SW) | (1 << DIAGDIR_NW):
DrawTrackFence(ti, base_image, num_sprites, RFO_FLAT_RIGHT);
break;
case (1 << DIAGDIR_NE) | (1 << DIAGDIR_NW):
DrawTrackFence(ti, base_image, num_sprites, RFO_FLAT_LOWER);
break;
case (1 << DIAGDIR_NE):
DrawTrackFence_NE(ti, base_image, num_sprites);
break;
case (1 << DIAGDIR_NW):
DrawTrackFence_NW(ti, base_image, num_sprites);
break;
case (1 << DIAGDIR_NE) | (1 << DIAGDIR_SE):
DrawTrackFence(ti, base_image, num_sprites, RFO_FLAT_LEFT);
break;
case (1 << DIAGDIR_SE) | (1 << DIAGDIR_SW):
DrawTrackFence(ti, base_image, num_sprites, RFO_FLAT_UPPER);
break;
case (1 << DIAGDIR_NE) | (1 << DIAGDIR_SW):
DrawTrackFence_NE(ti, base_image, num_sprites);
DrawTrackFence_SW(ti, base_image, num_sprites);
break;
case (1 << DIAGDIR_SE) | (1 << DIAGDIR_NW):
DrawTrackFence_SE(ti, base_image, num_sprites);
DrawTrackFence_NW(ti, base_image, num_sprites);
break;
default:
break;
}
break;
}

case RAIL_GROUND_WATER_FENCE: {
Corner track_corner;
if (IsHalftileSlope(ti->tileh)) {
/* Steep slope or one-corner-raised slope with halftile foundation */
@@ -2081,7 +2199,7 @@ static void DrawTrackBitsOverlay(TileInfo *ti, TrackBits track, const RailtypeIn
/* DrawFoundation modifies ti */

/* Draw ground */
if (rgt == RAIL_GROUND_WATER) {
if (rgt == RAIL_GROUND_WATER || rgt == RAIL_GROUND_WATER_FENCE) {
if (track != TRACK_BIT_NONE || IsSteepSlope(ti->tileh)) {
/* three-corner-raised slope or steep slope with track on upper part */
DrawShoreTile(ti->tileh);
@@ -2094,8 +2212,11 @@ static void DrawTrackBitsOverlay(TileInfo *ti, TrackBits track, const RailtypeIn

switch (rgt) {
case RAIL_GROUND_BARREN: image = SPR_FLAT_BARE_LAND; break;
case RAIL_GROUND_ICE_DESERT: image = SPR_FLAT_SNOW_DESERT_TILE; break;
default: image = SPR_FLAT_GRASS_TILE; break;
case RAIL_GROUND_ICE_DESERT:
case RAIL_GROUND_ICE_DESERT_FENCE_1:
case RAIL_GROUND_ICE_DESERT_FENCE_2:
case RAIL_GROUND_ICE_DESERT_FENCE_1_2: image = SPR_FLAT_SNOW_DESERT_TILE; break;
default: image = SPR_FLAT_GRASS_TILE; break;
}

image += SlopeToSpriteOffset(ti->tileh);
@@ -2184,6 +2305,10 @@ static void DrawTrackBitsOverlay(TileInfo *ti, TrackBits track, const RailtypeIn
switch (rgt) {
case RAIL_GROUND_BARREN: image = SPR_FLAT_BARE_LAND; break;
case RAIL_GROUND_ICE_DESERT:
case RAIL_GROUND_ICE_DESERT_FENCE_1:
case RAIL_GROUND_ICE_DESERT_FENCE_2:
case RAIL_GROUND_ICE_DESERT_FENCE_1_2:
case RAIL_GROUND_HALF_SNOW_FENCE:
case RAIL_GROUND_HALF_SNOW: image = SPR_FLAT_SNOW_DESERT_TILE; break;
default: image = SPR_FLAT_GRASS_TILE; break;
}
@@ -2247,7 +2372,7 @@ static void DrawTrackBits(TileInfo *ti, TrackBits track)
/* Select the sprite to use. */
if (track == 0) {
/* Clear ground (only track on halftile foundation) */
if (rgt == RAIL_GROUND_WATER) {
if (rgt == RAIL_GROUND_WATER || rgt == RAIL_GROUND_WATER_FENCE) {
if (IsSteepSlope(ti->tileh)) {
DrawShoreTile(ti->tileh);
image = 0;
@@ -2256,9 +2381,20 @@ static void DrawTrackBits(TileInfo *ti, TrackBits track)
}
} else {
switch (rgt) {
case RAIL_GROUND_BARREN: image = SPR_FLAT_BARE_LAND; break;
case RAIL_GROUND_ICE_DESERT: image = SPR_FLAT_SNOW_DESERT_TILE; break;
default: image = SPR_FLAT_GRASS_TILE; break;
case RAIL_GROUND_BARREN:
image = SPR_FLAT_BARE_LAND;
break;

case RAIL_GROUND_ICE_DESERT:
case RAIL_GROUND_ICE_DESERT_FENCE_1:
case RAIL_GROUND_ICE_DESERT_FENCE_2:
case RAIL_GROUND_ICE_DESERT_FENCE_1_2:
image = SPR_FLAT_SNOW_DESERT_TILE;
break;

default:
image = SPR_FLAT_GRASS_TILE;
break;
}
image += SlopeToSpriteOffset(ti->tileh);
}
@@ -2289,7 +2425,10 @@ static void DrawTrackBits(TileInfo *ti, TrackBits track)

switch (rgt) {
case RAIL_GROUND_BARREN: pal = PALETTE_TO_BARE_LAND; break;
case RAIL_GROUND_ICE_DESERT: image += rti->snow_offset; break;
case RAIL_GROUND_ICE_DESERT:
case RAIL_GROUND_ICE_DESERT_FENCE_1:
case RAIL_GROUND_ICE_DESERT_FENCE_2:
case RAIL_GROUND_ICE_DESERT_FENCE_1_2: image += rti->snow_offset; break;
case RAIL_GROUND_WATER: {
/* three-corner-raised slope */
DrawShoreTile(ti->tileh);
@@ -2347,7 +2486,11 @@ static void DrawTrackBits(TileInfo *ti, TrackBits track)
switch (rgt) {
case RAIL_GROUND_BARREN: pal = PALETTE_TO_BARE_LAND; break;
case RAIL_GROUND_ICE_DESERT:
case RAIL_GROUND_HALF_SNOW: image += rti->snow_offset; break; // higher part has snow in this case too
case RAIL_GROUND_ICE_DESERT_FENCE_1:
case RAIL_GROUND_ICE_DESERT_FENCE_2:
case RAIL_GROUND_ICE_DESERT_FENCE_1_2:
case RAIL_GROUND_HALF_SNOW:
case RAIL_GROUND_HALF_SNOW_FENCE: image += rti->snow_offset; break; // higher part has snow in this case too
default: break;
}
DrawGroundSprite(image, pal, &(_halftile_sub_sprite[halftile_corner]));
@@ -2618,9 +2761,31 @@ static void TileLoop_Track(TileIndex tile)
if (z > GetSnowLine()) {
if (half && z - GetSnowLine() == 1) {
/* track on non-continuous foundation, lower part is not under snow */
new_ground = RAIL_GROUND_HALF_SNOW;
if (old_ground == RAIL_GROUND_HALF_SNOW)
new_ground = RAIL_GROUND_HALF_SNOW_FENCE;
else
new_ground = RAIL_GROUND_HALF_SNOW;
} else {
new_ground = RAIL_GROUND_ICE_DESERT;
switch (old_ground) {
case RAIL_GROUND_ICE_DESERT:
// TODO:
// make to random select _FENCE_1 or _FENCE_2
new_ground = RAIL_GROUND_ICE_DESERT_FENCE_1;
break;

case RAIL_GROUND_ICE_DESERT_FENCE_1:
case RAIL_GROUND_ICE_DESERT_FENCE_2:
case RAIL_GROUND_ICE_DESERT_FENCE_1_2:
new_ground = RAIL_GROUND_ICE_DESERT_FENCE_1_2;
break;

case RAIL_GROUND_BARREN:
new_ground = RAIL_GROUND_ICE_DESERT;
break;

default:
NOT_REACHED();
}
}
goto set_ground;
}
@@ -2637,42 +2802,29 @@ static void TileLoop_Track(TileIndex tile)

new_ground = RAIL_GROUND_GRASS;

if (IsPlainRail(tile) && old_ground != RAIL_GROUND_BARREN) { // wait until bottom is green
/* determine direction of fence */
TrackBits rail = GetTrackBits(tile);

Owner owner = GetTileOwner(tile);
byte fences = 0;

for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
static const TrackBits dir_to_trackbits[DIAGDIR_END] = {TRACK_BIT_3WAY_NE, TRACK_BIT_3WAY_SE, TRACK_BIT_3WAY_SW, TRACK_BIT_3WAY_NW};

/* Track bit on this edge => no fence. */
if ((rail & dir_to_trackbits[d]) != TRACK_BIT_NONE) continue;

TileIndex tile2 = tile + TileOffsByDiagDir(d);

/* Show fences if it's a house, industry, object, road, tunnelbridge or not owned by us. */
if (!IsValidTile(tile2) || IsTileType(tile2, MP_HOUSE) || IsTileType(tile2, MP_INDUSTRY) ||
IsTileType(tile2, MP_ROAD) || (IsTileType(tile2, MP_OBJECT) && !IsObjectType(tile2, OBJECT_OWNED_LAND)) || IsTileType(tile2, MP_TUNNELBRIDGE) || !IsTileOwner(tile2, owner)) {
fences |= 1 << d;
}
}

switch (fences) {
case 0: break;
case (1 << DIAGDIR_NE): new_ground = RAIL_GROUND_FENCE_NE; break;
case (1 << DIAGDIR_SE): new_ground = RAIL_GROUND_FENCE_SE; break;
case (1 << DIAGDIR_SW): new_ground = RAIL_GROUND_FENCE_SW; break;
case (1 << DIAGDIR_NW): new_ground = RAIL_GROUND_FENCE_NW; break;
case (1 << DIAGDIR_NE) | (1 << DIAGDIR_SW): new_ground = RAIL_GROUND_FENCE_NESW; break;
case (1 << DIAGDIR_SE) | (1 << DIAGDIR_NW): new_ground = RAIL_GROUND_FENCE_SENW; break;
case (1 << DIAGDIR_NE) | (1 << DIAGDIR_SE): new_ground = RAIL_GROUND_FENCE_VERT1; break;
case (1 << DIAGDIR_NE) | (1 << DIAGDIR_NW): new_ground = RAIL_GROUND_FENCE_HORIZ2; break;
case (1 << DIAGDIR_SE) | (1 << DIAGDIR_SW): new_ground = RAIL_GROUND_FENCE_HORIZ1; break;
case (1 << DIAGDIR_SW) | (1 << DIAGDIR_NW): new_ground = RAIL_GROUND_FENCE_VERT2; break;
default: NOT_REACHED();
if (IsPlainRail(tile)) {
switch (old_ground) {
case RAIL_GROUND_BARREN:
new_ground = RAIL_GROUND_GRASS;
break;

case RAIL_GROUND_GRASS:
// TODO:
// make randon select of _FENCE_1 or _FENCE_2;
new_ground = RAIL_GROUND_GRASS_FENCE_1;
break;

case RAIL_GROUND_GRASS_FENCE_1:
case RAIL_GROUND_GRASS_FENCE_2:
case RAIL_GROUND_GRASS_FENCE_1_2:
new_ground = RAIL_GROUND_GRASS_FENCE_1_2;
break;

default:
NOT_REACHED();
}
} else {
new_ground = RAIL_GROUND_GRASS;
}

set_ground:
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.