/// <summary> /// Подбор тайлов углов и сторон для blend эффекта - перехода из одних тайлов в другие. /// </summary> /// <param name="tiles">тайл с карты</param> /// <param name="pos">его позиция</param> /// <returns></returns> public static ushort SmoothIndexForPos(CellLayer <TerrainTile> tiles, MPos pos) { var tile = tiles[pos].Type; if (tile == RockTile) { ClearSides clear = ClearSides.None; if (pos.U > 0) { var leftPos = new MPos(pos.U - 1, pos.V); var leftTile = tiles[leftPos]; if (!(leftTile.Type >= 126 && leftTile.Type <= 143) && !(leftTile.Type >= 160 && leftTile.Type <= 175)) { clear |= ClearSides.Left; } } if (pos.V > 0) { var topPos = new MPos(pos.U, pos.V - 1); var topTile = tiles[topPos]; if (!(topTile.Type >= 126 && topTile.Type <= 143) && !(topTile.Type >= 160 && topTile.Type <= 175)) { clear |= ClearSides.Top; } } if (pos.U < tiles.Size.Width - 1) { var rightPos = new MPos(pos.U + 1, pos.V); var rightTile = tiles[rightPos]; if (!(rightTile.Type >= 126 && rightTile.Type <= 143) && !(rightTile.Type >= 160 && rightTile.Type <= 175)) { clear |= ClearSides.Right; } } if (pos.V < tiles.Size.Height - 1) { var bottomPos = new MPos(pos.U, pos.V + 1); var bottomTile = tiles[bottomPos]; if (!(bottomTile.Type >= 126 && bottomTile.Type <= 143) && !(bottomTile.Type >= 160 && bottomTile.Type <= 175)) { clear |= ClearSides.Bottom; } } if (clear != ClearSides.None) { return(SpriteMap[clear]); } } if (tile == DuneTile) { ClearSides clear = ClearSides.None; if (pos.U > 0) { var leftPos = new MPos(pos.U - 1, pos.V); var leftTile = tiles[leftPos]; if (!(leftTile.Type >= 144 && leftTile.Type <= 159)) { clear |= ClearSides.Left; } } if (pos.V > 0) { var topPos = new MPos(pos.U, pos.V - 1); var topTile = tiles[topPos]; if (!(topTile.Type >= 144 && topTile.Type <= 159)) { clear |= ClearSides.Top; } } if (pos.U < tiles.Size.Width - 1) { var rightPos = new MPos(pos.U + 1, pos.V); var rightTile = tiles[rightPos]; if (!(rightTile.Type >= 144 && rightTile.Type <= 159)) { clear |= ClearSides.Right; } } if (pos.V < tiles.Size.Height - 1) { var bottomPos = new MPos(pos.U, pos.V + 1); var bottomTile = tiles[bottomPos]; if (!(bottomTile.Type >= 144 && bottomTile.Type <= 159)) { clear |= ClearSides.Bottom; } } if (clear != ClearSides.None) { return(SpriteMap[clear]); } } if (tile == RoughTile) { ClearSides clear = ClearSides.None; if (pos.U > 0) { var leftPos = new MPos(pos.U - 1, pos.V); var leftTile = tiles[leftPos]; if (!(leftTile.Type >= 160 && leftTile.Type <= 175)) { clear |= ClearSides.Left; } } if (pos.V > 0) { var topPos = new MPos(pos.U, pos.V - 1); var topTile = tiles[topPos]; if (!(topTile.Type >= 160 && topTile.Type <= 175)) { clear |= ClearSides.Top; } } if (pos.U < tiles.Size.Width - 1) { var rightPos = new MPos(pos.U + 1, pos.V); var rightTile = tiles[rightPos]; if (!(rightTile.Type >= 160 && rightTile.Type <= 175)) { clear |= ClearSides.Right; } } if (pos.V < tiles.Size.Height - 1) { var bottomPos = new MPos(pos.U, pos.V + 1); var bottomTile = tiles[bottomPos]; if (!(bottomTile.Type >= 160 && bottomTile.Type <= 175)) { clear |= ClearSides.Bottom; } } if (clear != ClearSides.None) { return(SpriteMap[clear]); } } return(SpriteMap[ClearSides.None]); }
public static ushort SmoothTileTypeForPos(ushort[] m, ushort width, ushort height, ushort x, ushort y) { var index = y * width + x; var tile = m[index]; if (tile == RockTile) { ClearSides clear = ClearSides.None; if (x > 0) { var leftIndex = index - 1; var leftTile = m[leftIndex]; if (!(leftTile >= 126 && leftTile <= 143) && !(leftTile >= 160 && leftTile <= 175)) { clear |= ClearSides.Left; } } if (y > 0) { var topIndex = index - width; var topTile = m[topIndex]; if (!(topTile >= 126 && topTile <= 143) && !(topTile >= 160 && topTile <= 175)) { clear |= ClearSides.Top; } } if (x < width - 1) { var rightIndex = index + 1; var rightTile = m[rightIndex]; if (!(rightTile >= 126 && rightTile <= 143) && !(rightTile >= 160 && rightTile <= 175)) { clear |= ClearSides.Right; } } if (y < height - 1) { var bottomIndex = index + width; var bottomTile = m[bottomIndex]; if (!(bottomTile >= 126 && bottomTile <= 143) && !(bottomTile >= 160 && bottomTile <= 175)) { clear |= ClearSides.Bottom; } } if (clear != ClearSides.None) { return(RockSides[SpriteMap[clear]]); } } if (tile == DuneTile) { ClearSides clear = ClearSides.None; if (x > 0) { var leftIndex = index - 1; var leftTile = m[leftIndex]; if (!(leftTile >= 144 && leftTile <= 159)) { clear |= ClearSides.Left; } } if (y > 0) { var topIndex = index - width; var topTile = m[topIndex]; if (!(topTile >= 144 && topTile <= 159)) { clear |= ClearSides.Top; } } if (x < width - 1) { var rightIndex = index + 1; var rightTile = m[rightIndex]; if (!(rightTile >= 144 && rightTile <= 159)) { clear |= ClearSides.Right; } } if (y < height - 1) { var bottomIndex = index + width; var bottomTile = m[bottomIndex]; if (!(bottomTile >= 144 && bottomTile <= 159)) { clear |= ClearSides.Bottom; } } if (clear != ClearSides.None) { return(DuneSides[SpriteMap[clear]]); } } if (tile == RoughTile) { ClearSides clear = ClearSides.None; if (x > 0) { var leftIndex = index - 1; var leftTile = m[leftIndex]; if (!(leftTile >= 160 && leftTile <= 175)) { clear |= ClearSides.Left; } } if (y > 0) { var topIndex = index - width; var topTile = m[topIndex]; if (!(topTile >= 160 && topTile <= 175)) { clear |= ClearSides.Top; } } if (x < width - 1) { var rightIndex = index + 1; var rightTile = m[rightIndex]; if (!(rightTile >= 160 && rightTile <= 175)) { clear |= ClearSides.Right; } } if (y < height - 1) { var bottomIndex = index + width; var bottomTile = m[bottomIndex]; if (!(bottomTile >= 160 && bottomTile <= 175)) { clear |= ClearSides.Bottom; } } if (clear != ClearSides.None) { return(RoughSides[SpriteMap[clear]]); } } return(tile); }
public void WorldLoaded(World w, WorldRenderer wr) { /* based on SmudgeLayer.cs */ var first = sideSprites.First().Value.First(); var sheet = first.Sheet; if (sideSprites.Values.Any(sprites => sprites.Any(s => s.Sheet != sheet))) { throw new InvalidDataException("Resource sprites span multiple sheets. Try loading their sequences earlier."); } var blendMode = first.BlendMode; if (sideSprites.Values.Any(sprites => sprites.Any(s => s.BlendMode != blendMode))) { throw new InvalidDataException("Smudges specify different blend modes. " + "Try using different smudge types for smudges that use different blend modes."); } render = new TerrainSpriteLayer(w, wr, sheet, blendMode, wr.Palette(Info.Palette), wr.World.Type != WorldType.Editor); var tilesLayer = w.Map.Tiles; for (var v = 0; v < tilesLayer.Size.Height; v++) { for (var u = 0; u < tilesLayer.Size.Width; u++) { var mpos = new MPos(u, v); var tile = tilesLayer[mpos]; if (tile.Type == 143) { ClearSides clear = ClearSides.None; if (u > 0) { var leftPos = new MPos(u - 1, v); var leftTile = tilesLayer[leftPos]; if (!(leftTile.Type >= 126 && leftTile.Type <= 143) && !(leftTile.Type >= 160 && leftTile.Type <= 175)) { clear |= ClearSides.Left; } } if (v > 0) { var topPos = new MPos(u, v - 1); var topTile = tilesLayer[topPos]; if (!(topTile.Type >= 126 && topTile.Type <= 143) && !(topTile.Type >= 160 && topTile.Type <= 175)) { clear |= ClearSides.Top; } } if (u < tilesLayer.Size.Width - 1) { var rightPos = new MPos(u + 1, v); var rightTile = tilesLayer[rightPos]; if (!(rightTile.Type >= 126 && rightTile.Type <= 143) && !(rightTile.Type >= 160 && rightTile.Type <= 175)) { clear |= ClearSides.Right; } } if (v < tilesLayer.Size.Height - 1) { var bottomPos = new MPos(u, v + 1); var bottomTile = tilesLayer[bottomPos]; if (!(bottomTile.Type >= 126 && bottomTile.Type <= 143) && !(bottomTile.Type >= 160 && bottomTile.Type <= 175)) { clear |= ClearSides.Bottom; } } if (clear != ClearSides.None) { CPos cpos = mpos.ToCPos(w.Map); Sprite sprite = sideSprites["rock"][SpriteMap[clear]]; render.Update(cpos, sprite); } } if (tile.Type == 175) { ClearSides clear = ClearSides.None; if (u > 0) { var leftPos = new MPos(u - 1, v); var leftTile = tilesLayer[leftPos]; if (!(leftTile.Type >= 160 && leftTile.Type <= 175)) { clear |= ClearSides.Left; } } if (v > 0) { var topPos = new MPos(u, v - 1); var topTile = tilesLayer[topPos]; if (!(topTile.Type >= 160 && topTile.Type <= 175)) { clear |= ClearSides.Top; } } if (u < tilesLayer.Size.Width - 1) { var rightPos = new MPos(u + 1, v); var rightTile = tilesLayer[rightPos]; if (!(rightTile.Type >= 160 && rightTile.Type <= 175)) { clear |= ClearSides.Right; } } if (v < tilesLayer.Size.Height - 1) { var bottomPos = new MPos(u, v + 1); var bottomTile = tilesLayer[bottomPos]; if (!(bottomTile.Type >= 160 && bottomTile.Type <= 175)) { clear |= ClearSides.Bottom; } } if (clear != ClearSides.None) { CPos cpos = mpos.ToCPos(w.Map); Sprite sprite = sideSprites["rough"][SpriteMap[clear]]; render.Update(cpos, sprite); } } if (tile.Type == 159) { ClearSides clear = ClearSides.None; if (u > 0) { var leftPos = new MPos(u - 1, v); var leftTile = tilesLayer[leftPos]; if (!(leftTile.Type >= 144 && leftTile.Type <= 159)) { clear |= ClearSides.Left; } } if (v > 0) { var topPos = new MPos(u, v - 1); var topTile = tilesLayer[topPos]; if (!(topTile.Type >= 144 && topTile.Type <= 159)) { clear |= ClearSides.Top; } } if (u < tilesLayer.Size.Width - 1) { var rightPos = new MPos(u + 1, v); var rightTile = tilesLayer[rightPos]; if (!(rightTile.Type >= 144 && rightTile.Type <= 159)) { clear |= ClearSides.Right; } } if (v < tilesLayer.Size.Height - 1) { var bottomPos = new MPos(u, v + 1); var bottomTile = tilesLayer[bottomPos]; if (!(bottomTile.Type >= 144 && bottomTile.Type <= 159)) { clear |= ClearSides.Bottom; } } if (clear != ClearSides.None) { CPos cpos = mpos.ToCPos(w.Map); Sprite sprite = sideSprites["dune"][SpriteMap[clear]]; render.Update(cpos, sprite); } } } } }