예제 #1
0
 public static TileElementType GetTileElementType(PATile tile)
 {
     if (tile == null)
     {
         return(TileElementType.None);
     }
     return(tile.element.GetTileElementType());
 }
예제 #2
0
        public static PABuildingTile GetByTile(PATileTerrain tileTerrain, PATile tile)
        {
            PABuildingTile buildingTile = new PABuildingTile();
            int            x            = tile.x / 2;
            int            y            = tile.y / 2;

            buildingTile.keyTile = tileTerrain.GetTile(x * 2, y * 2);
            return(buildingTile);
        }
예제 #3
0
 public bool IsFitTile(PATile tile)
 {
     if (tile.qtrTiles[0] == qtrTiles[0] && tile.qtrTiles[1] == qtrTiles[1] &&
         tile.qtrTiles[2] == qtrTiles[2] && tile.qtrTiles[3] == qtrTiles[3])
     {
         return(true);
     }
     return(false);
 }
예제 #4
0
    void PaintNormalTile(PATile tile, int t, int specifiedIndex = -1, UVRotateType rotateType = UVRotateType.None)
    {
        if (tile == null)
        {
            return;
        }

        tile.SetTileProp(t, t, 0, specifiedIndex, rotateType);
        UpdateTileUV(tile);
    }
예제 #5
0
 public static bool IsTileSetType(PATile tile, TileSetType tst)
 {
     if (tile == null)
     {
         return(false);
     }
     else
     {
         return(tile.tileSetType == tst);
     }
 }
예제 #6
0
 public static bool IsMultiElement(PATile tile)
 {
     if (tile == null)
     {
         return(false);
     }
     else
     {
         return(tile.element.IsMultiElement());
     }
 }
예제 #7
0
 static QtrTileElementType GetMixQtrTileElementType(PATile tile, int qtrIndex)
 {
     if (tile == null)
     {
         return(QtrTileElementType.None);
     }
     else
     {
         return(GetMixQtrTileElementType(tile.qtrTiles[qtrIndex]));
     }
 }
예제 #8
0
 public PATile[] GetOtherTiles(PATileTerrain tileTerrain)
 {
     if (keyTile == null)
     {
         return(null);
     }
     PATile[] otherTiles = new PATile[3];
     otherTiles[0] = tileTerrain.GetTile(keyTile.x, keyTile.y + 1);
     otherTiles[1] = tileTerrain.GetTile(keyTile.x + 1, keyTile.y + 1);
     otherTiles[2] = tileTerrain.GetTile(keyTile.x + 1, keyTile.y);
     return(otherTiles);
 }
예제 #9
0
    public int GetTileQtrMissIndex(PATile tile)
    {
        for (int i = 0; i < tile.qtrTiles.Length; i++)
        {
            if (tile.qtrTiles[i] == QtrTileElementType.None)
            {
                return(i);
            }
        }

        return(-1);
    }
예제 #10
0
    public int GetTileMissQtrCount(PATile tile)
    {
        int count = 0;

        for (int i = 0; i < tile.qtrTiles.Length; i++)
        {
            if (tile.qtrTiles[i] == QtrTileElementType.None)
            {
                count++;
            }
        }
        return(count);
    }
예제 #11
0
    TileMixConfigAsset.TileMixConfig GetTileMixConfig(PATile tile)
    {
        foreach (var config in ConfigDataBase.instance.TileMixConfigAsset.configs)
        {
            if (config.qtrTile0 == (int)tile.qtrTiles[0] &&
                config.qtrTile1 == (int)tile.qtrTiles[1] &&
                config.qtrTile2 == (int)tile.qtrTiles[2] &&
                config.qtrTile3 == (int)tile.qtrTiles[3])
            {
                return(config);
            }
        }

        return(null);
    }
예제 #12
0
    void PaintPostProcessMultiElementTile(PATile tile)
    {
        if (tile.QtrTileTypeCount() >= 3)
        {
            TileMixConfigAsset.TileMixConfig mixConfig = GetTileMixConfig(tile);
            if (mixConfig == null)
            {
                Debug.LogError("mixConfig == null tile.x = " + tile.x + " tile.y = " + tile.y);
                tile.SetTileProp(0, 0, 0);
                UpdateTileUV(tile);
                return;
            }

            tile.SetTileProp(FireLevel1Brush, FireLevel1Brush, 0, mixConfig.tilesetIndex, (UVRotateType)mixConfig.rotateType);
        }
        else
        {
            tile.SetTilePropByQtrTile();
        }
        UpdateTileUV(tile);
    }
예제 #13
0
    // tile只有一个未确定的qtrtile
    int IsTileMiss1(PATile tile)
    {
        int index = -1;
        int count = 0;

        for (int i = 0; i < tile.qtrTiles.Length; i++)
        {
            if (tile.qtrTiles[i] == QtrTileElementType.None)
            {
                index = i;
                count++;
            }
        }
        if (count == 1)
        {
            return(index);
        }
        else
        {
            return(-1);
        }
    }
예제 #14
0
    // index=0=lb index=2=lt index=4=rt index=6=rb
    bool IsCornerMix(PATile[] nTiles, int index)
    {
        int  i      = 0;
        bool result = true;

        foreach (var nTile in nTiles)
        {
            if (i++ == index)
            {
                result &= PATile.IsSingleElement(nTile);
            }
            else
            {
                result &= PATile.IsMultiElement(nTile);
            }

            if (!result)
            {
                return(false);
            }
        }
        return(true);
    }
예제 #15
0
    protected void CalcIntermediateTileBits(PATile tile, byte b, IntermediateInfo imInfo)
    {
        if (tile == null || imInfo == null) return;

        IntermediateInfo imInfoInternal;
        CalcTileBits(imInfo.imToType, tile, b, out imInfoInternal);
    }
예제 #16
0
    public void PaintTile3x3(PATile tile, int t)
    {
        if (tile == null) return;
        int i;
        t = Mathf.Clamp(t, 0, settings.tsTypes.Count);

        IntermediateInfo[] imInfo = new IntermediateInfo[16];
        PATile[] tile2 = GetNeighboringTilesNxN(tile, 1);
        PATile[] nTiles = GetNeighboringTilesNxN(tile, 3);
        PATile[] tls = GetNeighboringTilesNxN(tile, 5);

        tile.type = t;
        tile.toType = t;
        tile.bits = 0;
        UpdateTileUV(tile);

        for (i = 0; i < 8; ++i)
            if (tile2[i] != null)
            {
                tile2[i].type = t;
                tile2[i].toType = t;
                tile2[i].bits = 0;
                UpdateTileUV(tile2[i]);
            }

        //Array visualization, where 'c' = current tile
        // 0  1  2  3  4  5  6
        // 23 0  1  2  3  4  7
        // 22 15 x  x  x  5  8
        // 21 14 x  c  x  6  9
        // 20 13 x  x  x  7  10
        // 19 12 11 10 9  8  11
        // 18 17 16 15 14 13 12

        //0
        CalcTileBits(t, nTiles[0], 2, out imInfo[0]);
        //1
        CalcTileBits(t, nTiles[1], 3, out imInfo[1]);
        //2
        CalcTileBits(t, nTiles[2], 3, out imInfo[2]);
        //3
        CalcTileBits(t, nTiles[3], 3, out imInfo[3]);
        //4
        CalcTileBits(t, nTiles[4], 1, out imInfo[4]);

        //5
        CalcTileBits(t, nTiles[5], 9, out imInfo[5]);
        //6
        CalcTileBits(t, nTiles[6], 9, out imInfo[6]);
        //7
        CalcTileBits(t, nTiles[7], 9, out imInfo[7]);

        //8
        CalcTileBits(t, nTiles[8], 8, out imInfo[8]);
        //9
        CalcTileBits(t, nTiles[9], 12, out imInfo[9]);
        //10
        CalcTileBits(t, nTiles[10], 12, out imInfo[10]);
        //11
        CalcTileBits(t, nTiles[11], 12, out imInfo[11]);
        //12
        CalcTileBits(t, nTiles[12], 4, out imInfo[12]);

        //13
        CalcTileBits(t, nTiles[13], 6, out imInfo[13]);
        //14
        CalcTileBits(t, nTiles[14], 6, out imInfo[14]);
        //15
        CalcTileBits(t, nTiles[15], 6, out imInfo[15]);

        //Array visualization, where 'c' = current tile
        // 0  1  2  3  4  5  6
        // 23 0  1  2  3  4  7
        // 22 15 x  x  x  5  8
        // 21 14 x  c  x  6  9
        // 20 13 x  x  x  7  10
        // 19 12 11 10 9  8  11
        // 18 17 16 15 14 13 12

        //0
        CalcIntermediateTileBits(tls[0], 2, imInfo[0]);
        //1
        CalcIntermediateTileBits(tls[1], 3, imInfo[0]);
        //2
        CalcIntermediateTileBits(tls[2], 3, imInfo[1]);
        //3
        CalcIntermediateTileBits(tls[3], 3, imInfo[2]);
        //4
        CalcIntermediateTileBits(tls[4], 3, imInfo[3]);
        //5
        CalcIntermediateTileBits(tls[5], 3, imInfo[4]);
        //6
        CalcIntermediateTileBits(tls[6], 1, imInfo[4]);

        //7
        CalcIntermediateTileBits(tls[7], 9, imInfo[4]);
        //8
        CalcIntermediateTileBits(tls[8], 9, imInfo[5]);
        //9
        CalcIntermediateTileBits(tls[9], 9, imInfo[6]);
        //10
        CalcIntermediateTileBits(tls[10], 9, imInfo[7]);
        //11
        CalcIntermediateTileBits(tls[11], 9, imInfo[8]);

        //12
        CalcIntermediateTileBits(tls[12], 8, imInfo[8]);
        //13
        CalcIntermediateTileBits(tls[13], 12, imInfo[8]);
        //14
        CalcIntermediateTileBits(tls[14], 12, imInfo[9]);
        //15
        CalcIntermediateTileBits(tls[15], 12, imInfo[10]);
        //16
        CalcIntermediateTileBits(tls[16], 12, imInfo[11]);
        //17
        CalcIntermediateTileBits(tls[17], 12, imInfo[12]);
        //18
        CalcIntermediateTileBits(tls[18], 4, imInfo[12]);

        //19
        CalcIntermediateTileBits(tls[19], 6, imInfo[12]);
        //20
        CalcIntermediateTileBits(tls[20], 6, imInfo[13]);
        //21
        CalcIntermediateTileBits(tls[21], 6, imInfo[14]);
        //22
        CalcIntermediateTileBits(tls[22], 6, imInfo[15]);
        //23
        CalcIntermediateTileBits(tls[23], 6, imInfo[0]);
    }
예제 #17
0
    public void PaintTile1x1(PATile tile, int t)
    {
        if (tile == null) return;
        t = Mathf.Clamp(t, 0, settings.tsTypes.Count);

        //int i, transitionId;
        //PATSTransition transition = FindTransitionForType(t, out transitionId);
        //if (transition == null) return;

        IntermediateInfo[] imInfo = new IntermediateInfo[8];
        PATile[] nTiles = GetNeighboringTilesNxN(tile, 1);
        PATile[] tls = GetNeighboringTilesNxN(tile, 3);

        //Current tile
        tile.type = t;
        tile.toType = t;
        tile.bits = 0;
        UpdateTileUV(tile);

        //0
        CalcTileBits(t, nTiles[0], 2, out imInfo[0]);
        //1
        CalcTileBits(t, nTiles[1], 3, out imInfo[1]);
        //2
        CalcTileBits(t, nTiles[2], 1, out imInfo[2]);
        //3
        CalcTileBits(t, nTiles[3], 9, out imInfo[3]);
        //4
        CalcTileBits(t, nTiles[4], 8, out imInfo[4]);
        //5
        CalcTileBits(t, nTiles[5], 12, out imInfo[5]);
        //6
        CalcTileBits(t, nTiles[6], 4, out imInfo[6]);
        //7
        CalcTileBits(t, nTiles[7], 6, out imInfo[7]);

        //Array visualization, where 'c' = current tile
        // 0  1  2  3  4
        //15  0  1  2  5
        //14  7  c  3  6
        //13  6  5  4  7
        //12 11 10  9  8

        //0
        CalcIntermediateTileBits(tls[0], 2, imInfo[0]);
        //1
        CalcIntermediateTileBits(tls[1], 3, imInfo[0]);
        //2
        CalcIntermediateTileBits(tls[2], 3, imInfo[1]);
        //3
        CalcIntermediateTileBits(tls[3], 3, imInfo[2]);
        //4
        CalcIntermediateTileBits(tls[4], 1, imInfo[2]);

        //5
        CalcIntermediateTileBits(tls[5], 9, imInfo[2]);
        //6
        CalcIntermediateTileBits(tls[6], 9, imInfo[3]);
        //7
        CalcIntermediateTileBits(tls[7], 9, imInfo[4]);

        //8
        CalcIntermediateTileBits(tls[8], 8, imInfo[4]);
        //9
        CalcIntermediateTileBits(tls[9], 12, imInfo[4]);
        //10
        CalcIntermediateTileBits(tls[10], 12, imInfo[5]);
        //11
        CalcIntermediateTileBits(tls[11], 12, imInfo[6]);
        //12
        CalcIntermediateTileBits(tls[12], 4, imInfo[6]);

        //13
        CalcIntermediateTileBits(tls[13], 6, imInfo[6]);
        //14
        CalcIntermediateTileBits(tls[14], 6, imInfo[7]);
        //15
        CalcIntermediateTileBits(tls[15], 6, imInfo[0]);
    }
예제 #18
0
    //n must be 1,3,5,7,9,11... etc
    public PATile[] GetNeighboringTilesNxN(int x, int y, int n)
    {
        //Universal algorithm to search for nearby tiles

        //n = 1 ---> 1x1 - 8
        //Array visualization, where 'x' = current tile
        // 0  1  2
        // 7  x  3
        // 6  5  4

        //n = 3 ---> 3x3 - 16
        //Array visualization, where 'c' = current tile
        // 0  1  2  3  4
        //15  x  x  x  5
        //14  x  c  x  6
        //13  x  x  x  7
        //12 11 10  9  8

        //n = 5 ---> 5x5 - 24
        //Array visualization, where 'c' = current tile
        // 0  1  2  3  4  5  6
        // 23 x  x  x  x  x  7
        // 22 x  x  x  x  x  8
        // 21 x  x  c  x  x  9
        // 20 x  x  x  x  x  10
        // 19 x  x  x  x  x  11
        // 18 17 16 15 14 13 12

        int i;
        int nc = n + 2;
        int ct = nc * nc - n * n;
        int m = (nc - 1) / 2, s;

        PATile[] t = new PATile[ct];
        for (i = 0; i < ct; ++i) t[i] = null;

        //up
        if (x > (m - 1))
        {
            //left and center
            for (i = -1; i < m; ++i)
                if (y > i) t[m - (i + 1)] = GetTile(x - m, y - (i + 1));
            //right
            for (i = 1; i <= m; ++i)
                if (y < settings.yCount - i) t[m + i] = GetTile(x - m, y + i);
        }

        //bottom
        if (x < settings.xCount - m)
        {
            //right and center
            s = nc + n;
            for (i = m; i >= 0; --i)
                if (y < settings.yCount - i) t[s + m - i] = GetTile(x + m, y + i);
            //left
            s += m + 1;
            for (i = 0; i < m; ++i)
                if (y > i) t[s + i] = GetTile(x + m, y - (i + 1));
        }

        //right
        if (y < settings.yCount - m)
        {
            //up
            for (i = m - 2; i >= -1; --i)
                if (x > i) t[n + m - i]	= GetTile(x - (i + 1), y + m);
            //bottom
            for (i = 1; i < m; ++i)
                if (x < settings.xCount - i) t[nc + m + i - 1] = GetTile(x + i, y + m);
        }

        //left
        if (y > m - 1)
        {
            //bottom
            s = ct - n;
            for (i = m - 1; i >= 0; --i)
                if (x < settings.xCount - i) t[s + m - 1 - i] = GetTile(x + i, y - m);
            //up
            s = ct - m + 1;
            for (i = 0; i < m - 1; ++i)
                if (x > i) t[s + i] = GetTile(x - (i + 1), y - m);
        }

        return t;
    }
예제 #19
0
    public void PaintTile1x1(PATile tile, int t)
    {
        if (tile == null)
        {
            return;
        }
        t = Mathf.Clamp(t, 0, settings.tsTypes.Count);

        //int i, transitionId;
        //PATSTransition transition = FindTransitionForType(t, out transitionId);
        //if (transition == null) return;

        IntermediateInfo[] imInfo = new IntermediateInfo[8];
        PATile[]           nTiles = GetNeighboringTilesNxN(tile, 1);
        PATile[]           tls    = GetNeighboringTilesNxN(tile, 3);

        //Current tile
        tile.SetTileProp(t, t, 0);
        UpdateTileUV(tile);

        //0
        CalcTileBits(t, nTiles[0], 2, out imInfo[0]);
        //1
        CalcTileBits(t, nTiles[1], 3, out imInfo[1]);
        //2
        CalcTileBits(t, nTiles[2], 1, out imInfo[2]);
        //3
        CalcTileBits(t, nTiles[3], 9, out imInfo[3]);
        //4
        CalcTileBits(t, nTiles[4], 8, out imInfo[4]);
        //5
        CalcTileBits(t, nTiles[5], 12, out imInfo[5]);
        //6
        CalcTileBits(t, nTiles[6], 4, out imInfo[6]);
        //7
        CalcTileBits(t, nTiles[7], 6, out imInfo[7]);

        //Array visualization, where 'c' = current tile
        // 0  1  2  3  4
        //15  0  1  2  5
        //14  7  c  3  6
        //13  6  5  4  7
        //12 11 10  9  8

        //0
        CalcIntermediateTileBits(tls[0], 2, imInfo[0]);
        //1
        CalcIntermediateTileBits(tls[1], 3, imInfo[0]);
        //2
        CalcIntermediateTileBits(tls[2], 3, imInfo[1]);
        //3
        CalcIntermediateTileBits(tls[3], 3, imInfo[2]);
        //4
        CalcIntermediateTileBits(tls[4], 1, imInfo[2]);

        //5
        CalcIntermediateTileBits(tls[5], 9, imInfo[2]);
        //6
        CalcIntermediateTileBits(tls[6], 9, imInfo[3]);
        //7
        CalcIntermediateTileBits(tls[7], 9, imInfo[4]);

        //8
        CalcIntermediateTileBits(tls[8], 8, imInfo[4]);
        //9
        CalcIntermediateTileBits(tls[9], 12, imInfo[4]);
        //10
        CalcIntermediateTileBits(tls[10], 12, imInfo[5]);
        //11
        CalcIntermediateTileBits(tls[11], 12, imInfo[6]);
        //12
        CalcIntermediateTileBits(tls[12], 4, imInfo[6]);

        //13
        CalcIntermediateTileBits(tls[13], 6, imInfo[6]);
        //14
        CalcIntermediateTileBits(tls[14], 6, imInfo[7]);
        //15
        CalcIntermediateTileBits(tls[15], 6, imInfo[0]);
    }
예제 #20
0
 public static bool IsNotBaseElement(PATile tile)
 {
     return(tile != null && !tile.element.IsBaseElement());
 }
예제 #21
0
    protected void UpdateTileUV(PATile tile)
    {
        if (tile.type == -1) { return; }

        Mesh mesh = GetChunkMesh(tile.chunkId);
        Vector2[] uvs = mesh.uv;
        int i = tile.cId;
        int index;

        if (tile.bits == 0 || tile.type == tile.toType)
        {
            PATSType type = settings.tsTypes[tile.type];
            index = type.baseIndexes[0];
            tile.bits = 0;
        } else
        {
            int id = FindTransitionBitsId(tile.bits);
            int transitionId;

            PATSTransition transition = FindTransition(tile.type, tile.toType, out transitionId);
            if (transition == null)
            {
                Debug.LogError("For the tile set is not known transition!");
                PATSType type = settings.tsTypes[tile.type];
                index = type.baseIndexes[0];
            } else
            {
                index = transition.transitions[id];
            }
        }

        PATileUV uv = GetIndexUV(index);
        //tile.uvs[0] = uv.p0;
        //tile.uvs[1] = uv.p1;
        //tile.uvs[2] = uv.p2;
        //tile.uvs[3] = uv.p3;
        uvs[i * 4 + 0] = uv.p0;//tile.uvs[0];
        uvs[i * 4 + 1] = uv.p1;//tile.uvs[1];
        uvs[i * 4 + 2] = uv.p2;//tile.uvs[2];
        uvs[i * 4 + 3] = uv.p3;//tile.uvs[3];

        mesh.uv = uvs;
    }
예제 #22
0
    public void PaintATileDecal(PATile tile)
    {
        if (tile == null || tile.decalTilesetIndex != -1)
        {
            return;
        }

        //融合处不能贴花
        if (!tile.IsElementFull())
        {
            return;
        }

        PATile[] nTiles          = GetNeighboringTilesNxN(tile, 1);
        PATile   leftTile        = nTiles[1];
        PATile   topTile         = nTiles[3];
        PATile   rightTile       = nTiles[5];
        PATile   rightBottomTile = nTiles[6];
        PATile   bottomTile      = nTiles[7];

        foreach (var config in ConfigDataBase.instance.DecalConfigAsset.configs)
        {
            if (tile.decalTilesetIndex != -1)
            {
                return;
            }
            if (config.elementType != (int)tile.element.GetDecalSuitTileType())
            {
                continue;
            }
            if (!config.elementValue.Contains(tile.element.GetMaxElementValue()))
            {
                continue;
            }
            TileSetType tileSetType = (TileSetType)config.tileSetType;
            if (tile.tileSetType != tileSetType)
            {
                continue;
            }
            //float rate = (config.maxRate - tile.distance * config.atten);
            int rate        = config.rate;
            int randomValue = RandomManager.instance.Range(0, 1000);
            if (20 < randomValue)
            {
                continue;
            }
            //int randomRotate = RandomManager.instance.Range(0,4);
            //UVRotateType rotateType = (UVRotateType)randomRotate;
            UVRotateType rotateType = UVRotateType._90;
            if (config.decalType == (int)TileDecalType.Decal_2)
            {
                if (config.tileSetIndex.Count != 2)
                {
                    Debug.LogError("config.tileSetIndex.Count != 2");
                    continue;
                }
                if (rotateType == UVRotateType._90)
                {
                    if (rightTile == null || rightTile.decalTilesetIndex != -1 || !rightTile.IsElementFull())
                    {
                        continue;
                    }
                    if (rightTile.tileSetType != tileSetType)
                    {
                        continue;
                    }

                    tile.decalTilesetIndex      = config.tileSetIndex[0];
                    rightTile.decalTilesetIndex = config.tileSetIndex[1];
                    PaintTileDecal(rightTile, rotateType);
                }
                else if (rotateType == UVRotateType.None)
                {
                    if (topTile == null || topTile.decalTilesetIndex != -1 || !topTile.IsElementFull())
                    {
                        continue;
                    }
                    if (topTile.tileSetType != tileSetType)
                    {
                        continue;
                    }
                    tile.decalTilesetIndex    = config.tileSetIndex[0];
                    topTile.decalTilesetIndex = config.tileSetIndex[1];
                    PaintTileDecal(topTile, rotateType);
                }
                else if (rotateType == UVRotateType._180)
                {
                    if (bottomTile == null || bottomTile.decalTilesetIndex != -1 || !bottomTile.IsElementFull())
                    {
                        continue;
                    }
                    if (bottomTile.tileSetType != tileSetType)
                    {
                        continue;
                    }
                    tile.decalTilesetIndex       = config.tileSetIndex[0];
                    bottomTile.decalTilesetIndex = config.tileSetIndex[1];
                    PaintTileDecal(bottomTile, rotateType);
                }
                else if (rotateType == UVRotateType._270)
                {
                    if (leftTile == null || leftTile.decalTilesetIndex != -1)
                    {
                        continue;
                    }
                    if (leftTile.tileSetType != tileSetType)
                    {
                        continue;
                    }
                    tile.decalTilesetIndex     = config.tileSetIndex[0];
                    leftTile.decalTilesetIndex = config.tileSetIndex[1];
                    PaintTileDecal(leftTile, rotateType);
                }
                PaintTileDecal(tile, rotateType);
            }
            else if (config.decalType == (int)TileDecalType.Decal_4)
            {
                if (rightTile == null || rightTile.decalTilesetIndex != -1 || !rightTile.IsElementFull() ||
                    rightBottomTile == null || rightBottomTile.decalTilesetIndex != -1 || !rightBottomTile.IsElementFull() ||
                    bottomTile == null || bottomTile.decalTilesetIndex != -1 || !bottomTile.IsElementFull())
                {
                    continue;
                }
                if (rightTile.tileSetType != tileSetType)
                {
                    continue;
                }
                if (rightBottomTile.tileSetType != tileSetType)
                {
                    continue;
                }
                if (bottomTile.tileSetType != tileSetType)
                {
                    continue;
                }

                if (config.tileSetIndex.Count != 4)
                {
                    Debug.LogError("config.tileSetIndex.Count != 4");
                    continue;
                }

                if (rotateType == UVRotateType._90)
                {
                    tile.decalTilesetIndex            = config.tileSetIndex[0];
                    rightTile.decalTilesetIndex       = config.tileSetIndex[1];
                    bottomTile.decalTilesetIndex      = config.tileSetIndex[2];
                    rightBottomTile.decalTilesetIndex = config.tileSetIndex[3];
                }
                else if (rotateType == UVRotateType.None)
                {
                    tile.decalTilesetIndex            = config.tileSetIndex[1];
                    rightTile.decalTilesetIndex       = config.tileSetIndex[3];
                    bottomTile.decalTilesetIndex      = config.tileSetIndex[0];
                    rightBottomTile.decalTilesetIndex = config.tileSetIndex[2];
                }
                else if (rotateType == UVRotateType._270)
                {
                    tile.decalTilesetIndex            = config.tileSetIndex[3];
                    rightTile.decalTilesetIndex       = config.tileSetIndex[2];
                    bottomTile.decalTilesetIndex      = config.tileSetIndex[1];
                    rightBottomTile.decalTilesetIndex = config.tileSetIndex[0];
                }
                else if (rotateType == UVRotateType._180)
                {
                    tile.decalTilesetIndex            = config.tileSetIndex[2];
                    rightTile.decalTilesetIndex       = config.tileSetIndex[0];
                    bottomTile.decalTilesetIndex      = config.tileSetIndex[3];
                    rightBottomTile.decalTilesetIndex = config.tileSetIndex[1];
                }
                PaintTileDecal(tile, rotateType);
                PaintTileDecal(rightTile, rotateType);
                PaintTileDecal(bottomTile, rotateType);
                PaintTileDecal(rightBottomTile, rotateType);
            }
            else
            {
                if (config.tileSetIndex.Count != 1)
                {
                    Debug.LogError("config.tileSetIndex.Count != 1");
                    continue;
                }
                tile.decalTilesetIndex = config.tileSetIndex[0];
                PaintTileDecal(tile, rotateType);
            }
        }
    }
예제 #23
0
 public float Distance(PATile other)
 {
     return(Vector2.Distance(new Vector2(x, y), new Vector2(other.x, other.y)));
 }
예제 #24
0
 void PaintPostProcessSingleElementTile(PATile tile)
 {
     tile.SetTilePropByQtrTile();
     UpdateTileUV(tile);
 }
예제 #25
0
 void PaintTileDecal(PATile tile, UVRotateType rotateType = UVRotateType.None)
 {
     PaintNormalTile(tile, 0, tile.decalTilesetIndex, rotateType);
 }
예제 #26
0
    void PaintASingleElementTile(PATile tile, List <PATile> postProcessSingleElementTiles = null)
    {
        //if (tile.element.IsMultiElement())
        //    return;

        PATile[] nTiles = GetNeighboringTilesNxN(tile, 1);
        int      leftBottomValue = 99, leftValue = 99, leftTopValue = 99, topValue = 99,
                 rightTopValue = 99, rightValue = 99, rightBottomValue = 99, bottomValue = 99;

        PATile leftBottomTile  = nTiles[0];
        PATile leftTile        = nTiles[1];
        PATile leftTopTile     = nTiles[2];
        PATile topTile         = nTiles[3];
        PATile rightTopTile    = nTiles[4];
        PATile rightTile       = nTiles[5];
        PATile rightBottomTile = nTiles[6];
        PATile bottomTile      = nTiles[7];

        bool needPostProcess = false;

        foreach (var nTile in nTiles)
        {
            if (PATile.IsMultiElement(nTile))
            {
                needPostProcess = true;
            }
        }
        if (needPostProcess)
        {
            postProcessSingleElementTiles.Add(tile);
        }

        int t            = 0;
        int elementValue = 0;
        QtrTileElementType qtrTileElementType    = QtrTileElementType.Base;
        QtrTileElementType mixQtrTileElementType = QtrTileElementType.Base;

        TileElementType elementType = tile.element.GetTileElementType();

        t = elementValue = tile.element.GetElementPaintBrushType(elementType);
        if (leftBottomTile != null)
        {
            leftBottomValue = leftBottomTile.GetSingleElementPaintBrushType(elementType);
        }
        if (leftTile != null)
        {
            leftValue = leftTile.GetSingleElementPaintBrushType(elementType);
        }
        if (leftTopTile != null)
        {
            leftTopValue = leftTopTile.GetSingleElementPaintBrushType(elementType);
        }
        if (topTile != null)
        {
            topValue = topTile.GetSingleElementPaintBrushType(elementType);
        }
        if (rightTopTile != null)
        {
            rightTopValue = rightTopTile.GetSingleElementPaintBrushType(elementType);
        }
        if (rightTile != null)
        {
            rightValue = rightTile.GetSingleElementPaintBrushType(elementType);
        }
        if (rightBottomTile != null)
        {
            rightBottomValue = rightBottomTile.GetSingleElementPaintBrushType(elementType);
        }
        if (bottomTile != null)
        {
            bottomValue = bottomTile.GetSingleElementPaintBrushType(elementType);
        }

        if (t == FireLevel1Brush)
        {
            qtrTileElementType    = QtrTileElementType.Fire;
            mixQtrTileElementType = QtrTileElementType.Base;
        }
        else if (t == FireLevel2Brush)
        {
            qtrTileElementType    = QtrTileElementType.Fire2;
            mixQtrTileElementType = QtrTileElementType.Fire;
        }
        else if (t == FireLevel3Brush)
        {
            qtrTileElementType    = QtrTileElementType.Fire3;
            mixQtrTileElementType = QtrTileElementType.Fire2;
        }
        else if (t == WoodLevel1Brush)
        {
            qtrTileElementType    = QtrTileElementType.Wood;
            mixQtrTileElementType = QtrTileElementType.Base;
        }
        else if (t == WoodLevel2Brush)
        {
            qtrTileElementType    = QtrTileElementType.Wood2;
            mixQtrTileElementType = QtrTileElementType.Wood;
        }
        else if (t == WoodLevel3Brush)
        {
            qtrTileElementType    = QtrTileElementType.Wood3;
            mixQtrTileElementType = QtrTileElementType.Wood2;
        }

        if (leftValue < elementValue && bottomValue < elementValue)
        {
            CalcTileBits(t, tile, 2);//左下角
            tile.tileSetType = TileSetType.Corner;
            tile.SetQtrTiles(mixQtrTileElementType, mixQtrTileElementType, qtrTileElementType, mixQtrTileElementType);
        }
        else if (leftValue < elementValue && topValue < elementValue)
        {
            CalcTileBits(t, tile, 1);//左上角
            tile.tileSetType = TileSetType.Corner;
            tile.SetQtrTiles(mixQtrTileElementType, mixQtrTileElementType, mixQtrTileElementType, qtrTileElementType);
        }
        else if (rightValue < elementValue && bottomValue < elementValue)
        {
            CalcTileBits(t, tile, 4);//右下角
            tile.tileSetType = TileSetType.Corner;
            tile.SetQtrTiles(mixQtrTileElementType, qtrTileElementType, mixQtrTileElementType, mixQtrTileElementType);
        }
        else if (topValue < elementValue && rightValue < elementValue)
        {
            CalcTileBits(t, tile, 8);//右上角
            tile.tileSetType = TileSetType.Corner;
            tile.SetQtrTiles(qtrTileElementType, mixQtrTileElementType, mixQtrTileElementType, mixQtrTileElementType);
        }

        else if (leftValue < elementValue)
        {
            CalcTileBits(t, tile, 3);
            tile.tileSetType = TileSetType.Edge;
            tile.SetQtrTiles(mixQtrTileElementType, mixQtrTileElementType, qtrTileElementType, qtrTileElementType);
        }
        else if (topValue < elementValue)
        {
            CalcTileBits(t, tile, 9);
            tile.tileSetType = TileSetType.Edge;
            tile.SetQtrTiles(qtrTileElementType, mixQtrTileElementType, mixQtrTileElementType, qtrTileElementType);
        }
        else if (rightValue < elementValue)
        {
            CalcTileBits(t, tile, 12);
            tile.tileSetType = TileSetType.Edge;
            tile.SetQtrTiles(qtrTileElementType, qtrTileElementType, mixQtrTileElementType, mixQtrTileElementType);
        }
        else if (bottomValue < elementValue)
        {
            CalcTileBits(t, tile, 6);
            tile.tileSetType = TileSetType.Edge;
            tile.SetQtrTiles(mixQtrTileElementType, qtrTileElementType, qtrTileElementType, mixQtrTileElementType);
        }

        else if (leftBottomValue < elementValue)
        {
            CalcTileBits(t, tile, 7);
            tile.tileSetType = TileSetType.BigCorner;
            tile.SetQtrTiles(mixQtrTileElementType, qtrTileElementType, qtrTileElementType, qtrTileElementType);
        }
        else if (leftTopValue < elementValue)
        {
            CalcTileBits(t, tile, 11);
            tile.tileSetType = TileSetType.BigCorner;
            tile.SetQtrTiles(qtrTileElementType, mixQtrTileElementType, qtrTileElementType, qtrTileElementType);
        }
        else if (rightTopValue < elementValue)
        {
            CalcTileBits(t, tile, 13);
            tile.tileSetType = TileSetType.BigCorner;
            tile.SetQtrTiles(qtrTileElementType, qtrTileElementType, mixQtrTileElementType, qtrTileElementType);
        }
        else if (rightBottomValue < elementValue)
        {
            CalcTileBits(t, tile, 14);
            tile.tileSetType = TileSetType.BigCorner;
            tile.SetQtrTiles(qtrTileElementType, qtrTileElementType, qtrTileElementType, mixQtrTileElementType);
        }
        else
        {
            PaintNormalTile(tile, t);
            tile.tileSetType = TileSetType.Full;
            tile.SetQtrTiles(qtrTileElementType);
        }
    }
예제 #27
0
    protected void CalcTileBits(int t, PATile tile, byte b, out IntermediateInfo imInfo)
    {
        imInfo = null;
        if (tile == null) return;

        PATSTransition transition = null;
        bool invertedBits, needIntermediate = false;
        byte bits = tile.bits;
        bool isNull = (bits == 0 || tile.type == tile.toType);
        int fromType = t, toType = t;

        if (isNull)
        {
            if (fromType != tile.type)
            {
                transition = FindTransition(fromType, tile.type);
                toType = tile.type;
                if (transition != null)
                {
                    invertedBits = (fromType == transition.to);
                    bits = b;
                    if (invertedBits) bits = InvertBits(bits);

                } else
                {
                    needIntermediate = true;
                }
            } else if (fromType == tile.type)
            {
                //nothing to do
                toType = fromType; bits = 0;
            }

        } else
        {
            if (fromType == tile.type)
            {
                transition = FindTransition(fromType, tile.toType);
                toType = tile.toType;
            }
            else if (fromType == tile.toType)
            {
                transition = FindTransition(fromType, tile.type);
                toType = tile.type;
            } else
            {
                needIntermediate = true;
                toType = tile.type;
            }

            if (transition != null)
            {
                invertedBits = (fromType == transition.to);

                //if (fromType == tile.type)
                    // -----       -----
                    // |1|2|  ---  | 1 |
                    // -----       -----
                //else if (fromType == tile.toType)
                    // -----       -----
                    // |2|1|  ---  | 1 |
                    // -----       -----

                if (invertedBits) bits = InvertBits(bits);
                bits = (byte)(bits | b);
                if (invertedBits) bits = InvertBits(bits);
                if (bits == 15) { bits = 0; toType = fromType; }
            }

        }

        //Intermediate transition
        if (needIntermediate)
        {
            imInfo = new IntermediateInfo();
            imInfo.fromType = fromType;
            imInfo.toType = toType;

            transition = FindIntermediateTransition(fromType, toType);
            if (transition != null)
            {
                //Debug.Log("Intermediate transition = " + transition.name);
                if (fromType == transition.from) toType = transition.to;
                else if (fromType == transition.to) toType = transition.from;

                invertedBits = (fromType == transition.to);
                bits = b;
                if (invertedBits) bits = InvertBits(bits);
                if (bits == 15) { bits = 0; toType = fromType; }

                imInfo.imFromType = fromType;
                imInfo.imToType = toType;
            } else
            {
                Debug.LogError("Not found transition between '"+ settings.tsTypes[fromType].name +"' and '" + settings.tsTypes[toType].name + "'!");
                imInfo = null;
            }
        }

        tile.type = fromType;
        tile.toType = toType;
        tile.bits = bits;
        UpdateTileUV(tile);
    }
예제 #28
0
    ////如果tile只有一个qtrtile是未知的 那么未知的qtrtile直接设置成融合属性
    //void ProcessMiss1Tile(PATile tile)
    //{
    //    int miss1Index = IsTileMiss1(tile);
    //    if (miss1Index == -1)
    //        return;

    //    if(tile.element.IsMultiElement())
    //        tile.qtrTiles[miss1Index] = QtrTileElementType.Sand;
    //}

    void ProcessMiss1Tile(PATile tile)
    {
        if (tile.IsQtrTilesSet())
        {
            return;
        }

        PATile[] nTiles = GetNeighboringTilesNxN(tile, 1);

        PATile leftBottomTile  = nTiles[0];
        PATile leftTile        = nTiles[1];
        PATile leftTopTile     = nTiles[2];
        PATile topTile         = nTiles[3];
        PATile rightTopTile    = nTiles[4];
        PATile rightTile       = nTiles[5];
        PATile rightBottomTile = nTiles[6];
        PATile bottomTile      = nTiles[7];

        int fireCount = 0;
        int woodCount = 0;

        for (int i = 0; i < tile.qtrTiles.Length; i++)
        {
            if (tile.qtrTiles[i] == QtrTileElementType.Fire)
            {
                fireCount++;
            }
            else if (tile.qtrTiles[i] == QtrTileElementType.Wood)
            {
                woodCount++;
            }
        }

        QtrTileElementType missedQtrTileElementType = QtrTileElementType.None;
        //if (tile.element.FireValueFloat > tile.element.WoodValueFloat)
        //{
        //    if (fireCount - woodCount > 1)
        //        missedQtrTileElementType = QtrTileElementType.Wood;
        //    else
        //        missedQtrTileElementType = QtrTileElementType.Fire;
        //}
        //else if (tile.element.WoodValueFloat > tile.element.FireValueFloat)
        //{
        //    if (woodCount - fireCount > 1)
        //        missedQtrTileElementType = QtrTileElementType.Fire;
        //    else
        //        missedQtrTileElementType = QtrTileElementType.Wood;
        //}
        //else
        //    Debug.LogError("error state");

        int randomValue = RandomManager.instance.Range(1, 3);

        missedQtrTileElementType = (QtrTileElementType)randomValue;

        int missIndex = GetTileQtrMissIndex(tile);

        tile.qtrTiles[missIndex] = missedQtrTileElementType;

        if (missIndex == 0)
        {
            if (leftTile != null && leftTile.qtrTiles[3] == QtrTileElementType.None)
            {
                leftTile.qtrTiles[3] = missedQtrTileElementType;
            }
            if (leftBottomTile != null && leftBottomTile.qtrTiles[2] == QtrTileElementType.None)
            {
                leftBottomTile.qtrTiles[2] = missedQtrTileElementType;
            }
            if (bottomTile != null && bottomTile.qtrTiles[1] == QtrTileElementType.None)
            {
                bottomTile.qtrTiles[1] = missedQtrTileElementType;
            }
        }
        else if (missIndex == 1)
        {
            if (leftTopTile != null && leftTopTile.qtrTiles[3] == QtrTileElementType.None)
            {
                leftTopTile.qtrTiles[3] = missedQtrTileElementType;
            }
            if (leftTile != null && leftTile.qtrTiles[2] == QtrTileElementType.None)
            {
                leftTile.qtrTiles[2] = missedQtrTileElementType;
            }
            if (topTile != null && topTile.qtrTiles[0] == QtrTileElementType.None)
            {
                topTile.qtrTiles[0] = missedQtrTileElementType;
            }
        }
        else if (missIndex == 2)
        {
            if (rightTopTile != null && rightTopTile.qtrTiles[0] == QtrTileElementType.None)
            {
                rightTopTile.qtrTiles[0] = missedQtrTileElementType;
            }
            if (rightTile != null && rightTile.qtrTiles[1] == QtrTileElementType.None)
            {
                rightTile.qtrTiles[1] = missedQtrTileElementType;
            }
            if (topTile != null && topTile.qtrTiles[3] == QtrTileElementType.None)
            {
                topTile.qtrTiles[3] = missedQtrTileElementType;
            }
        }
        else if (missIndex == 3)
        {
            if (rightBottomTile != null && rightBottomTile.qtrTiles[1] == QtrTileElementType.None)
            {
                rightBottomTile.qtrTiles[1] = missedQtrTileElementType;
            }
            if (rightTile != null && rightTile.qtrTiles[0] == QtrTileElementType.None)
            {
                rightTile.qtrTiles[0] = missedQtrTileElementType;
            }
            if (bottomTile != null && bottomTile.qtrTiles[2] == QtrTileElementType.None)
            {
                bottomTile.qtrTiles[2] = missedQtrTileElementType;
            }
        }
    }
예제 #29
0
    /*public PATile[] GetNeighboringTiles1x1(PATile tile)
    {
        //Array visualization, where 'x' = current tile
        // 0  1  2
        // 7  x  3
        // 6  5  4
        PATile[] t = new PATile[8];
        for (int i = 0; i < 8; ++i) t[i] = null;

        if (tile.x > 0) //0, 1, 2
        {
            //0
            if (tile.y > 0) t[0] = GetTile(tile.x - 1, tile.y - 1);
            //1
            t[1] = GetTile(tile.x - 1, tile.y);
            //2
            if (tile.y < settings.yCount - 1) t[2] = GetTile(tile.x - 1, tile.y + 1);
        }

        if (tile.x < settings.xCount - 1) //4, 5, 6
        {
            //4
            if (tile.y < settings.yCount - 1) t[4] = GetTile(tile.x + 1, tile.y + 1);
            //5
            t[5] = GetTile(tile.x + 1, tile.y);
            //6
            if (tile.y > 0) t[6] = GetTile(tile.x + 1, tile.y - 1);
        }

        //7
        if (tile.y > 0) t[7] = GetTile(tile.x, tile.y - 1);
        //3
        if (tile.y < settings.yCount - 1) t[3] = GetTile(tile.x, tile.y + 1);

        for (int i = 0; i < 8; ++i) CheckTile(t[i]);
        return t;
    }

    public PATile[] GetNeighboringTiles3x3(PATile tile)
    {
        //Array visualization, where 'c' = current tile
        // 0  1  2  3  4
        //15  x  x  x  5
        //14  x  c  x  6
        //13  x  x  x  7
        //12 11 10  9  8
        PATile[] t = new PATile[16];
        for (int i = 0; i < 16; ++i) t[i] = null;

        if (tile.x > 1) //0, 1, 2, 3, 4
        {
            //0
            if (tile.y > 1) t[0] = GetTile(tile.x - 2, tile.y - 2);
            //1
            if (tile.y > 0) t[1] = GetTile(tile.x - 2, tile.y - 1);
            //2
            t[2] = GetTile(tile.x - 2, tile.y);
            //3
            if (tile.y < settings.yCount - 1) t[3] = GetTile(tile.x - 2, tile.y + 1);
            //4
            if (tile.y < settings.yCount - 2) t[4] = GetTile(tile.x - 2, tile.y + 2);
        }

        if (tile.x < settings.xCount - 2) //12, 11, 10, 9, 8
        {
            //8
            if (tile.y < settings.yCount - 2) t[8] = GetTile(tile.x + 2, tile.y + 2);
            //9
            if (tile.y < settings.yCount - 1) t[9] = GetTile(tile.x + 2, tile.y + 1);
            //10
            t[10] = GetTile(tile.x + 2, tile.y);
            //11
            if (tile.y > 0) t[11] = GetTile(tile.x + 2, tile.y - 1);
            //12
            if (tile.y > 1) t[12] = GetTile(tile.x + 2, tile.y - 2);
        }

        //5, 6, 7
        if (tile.y < settings.yCount - 2)
        {
            //5
            if (tile.x > 0) t[5] = GetTile(tile.x - 1, tile.y + 2);
            //6
            t[6] = GetTile(tile.x, tile.y + 2);
            //7
            if (tile.x < settings.xCount - 1) t[7] = GetTile(tile.x + 1, tile.y + 2);
        }

        //13, 14, 15
        if (tile.y > 1)
        {
            //13
            if (tile.x < settings.xCount - 1) t[13] = GetTile(tile.x + 1, tile.y - 2);
            //14
            t[14] = GetTile(tile.x, tile.y - 2);
            //15
            if (tile.x > 0) t[15] = GetTile(tile.x - 1, tile.y - 2);
        }

        return t;
    }

    public PATile[] GetNeighboringTiles5x5(PATile tile)
    {
        //Array visualization, where 'c' = current tile
        // 0  1  2  3  4  5  6
        // 23 x  x  x  x  x  7
        // 22 x  x  x  x  x  8
        // 21 x  x  c  x  x  9
        // 20 x  x  x  x  x  10
        // 19 x  x  x  x  x  11
        // 18 17 16 15 14 13 12
        PATile[] t = new PATile[24];
        for (int i = 0; i < 24; ++i) t[i] = null;

        if (tile.x > 2) //0, 1, 2, 3, 4, 5, 6
        {
            //0
            if (tile.y > 2) t[0] = GetTile(tile.x - 3, tile.y - 3);
            //1
            if (tile.y > 1) t[1] = GetTile(tile.x - 3, tile.y - 2);
            //2
            if (tile.y > 0) t[2] = GetTile(tile.x - 3, tile.y - 1);
            //3
            t[3] = GetTile(tile.x - 3, tile.y);
            //4
            if (tile.y < settings.yCount - 1) t[4] = GetTile(tile.x - 3, tile.y + 1);
            //5
            if (tile.y < settings.yCount - 2) t[5] = GetTile(tile.x - 3, tile.y + 2);
            //6
            if (tile.y < settings.yCount - 3) t[6] = GetTile(tile.x - 3, tile.y + 3);
        }

        if (tile.x < settings.xCount - 3) //12, 13, 14, 15, 16, 17, 18
        {
            //12
            if (tile.y < settings.yCount - 3) t[12] = GetTile(tile.x + 3, tile.y + 3);
            //13
            if (tile.y < settings.yCount - 2) t[13] = GetTile(tile.x + 3, tile.y + 2);
            //14
            if (tile.y < settings.yCount - 1) t[14] = GetTile(tile.x + 3, tile.y + 1);
            //15
            t[15] = GetTile(tile.x + 3, tile.y);
            //16
            if (tile.y > 0) t[16] = GetTile(tile.x + 3, tile.y - 1);
            //17
            if (tile.y > 1) t[17] = GetTile(tile.x + 3, tile.y - 2);
            //18
            if (tile.y > 2) t[18] = GetTile(tile.x + 3, tile.y - 3);
        }

        //Array visualization, where 'c' = current tile
        // 0  1  2  3  4  5  6
        // 23 x  x  x  x  x  7
        // 22 x  x  x  x  x  8
        // 21 x  x  c  x  x  9
        // 20 x  x  x  x  x  10
        // 19 x  x  x  x  x  11
        // 18 17 16 15 14 13 12

        //7, 8, 9, 10, 11
        if (tile.y < settings.yCount - 3)
        {
            //7
            if (tile.x > 1) t[7] = GetTile(tile.x - 2, tile.y + 3);
            //8
            if (tile.x > 0) t[8] = GetTile(tile.x - 1, tile.y + 3);
            //9
            t[9] = GetTile(tile.x, tile.y + 3);
            //10
            if (tile.x < settings.xCount - 1) t[10] = GetTile(tile.x + 1, tile.y + 3);
            //11
            if (tile.x < settings.xCount - 2) t[11] = GetTile(tile.x + 2, tile.y + 3);
        }

        //19, 20, 21, 22, 23
        if (tile.y > 2)
        {
            //19
            if (tile.x < settings.xCount - 2) t[19] = GetTile(tile.x + 2, tile.y - 3);
            //20
            if (tile.x < settings.xCount - 1) t[20] = GetTile(tile.x + 1, tile.y - 3);
            //21
            t[21] = GetTile(tile.x, tile.y - 3);
            //22
            if (tile.x > 0) t[22] = GetTile(tile.x - 1, tile.y - 3);
            //23
            if (tile.x > 1) t[23] = GetTile(tile.x - 2, tile.y - 3);
        }

        return t;
    }*/
    protected void CheckTile(PATile tile)
    {
        if (tile != null && tile.type >= settings.tsTypes.Count) { tile.type = -1; tile.bits = 0; }
    }
예제 #30
0
        //将没有完美融合的qtrtile设置成none
        public bool ProcessMixPerfect(PATileTerrain tileTerrain)
        {
            PATile[] nTiles = tileTerrain.GetNeighboringTilesNxN(this, 1);

            PATile leftBottomTile  = nTiles[0];
            PATile leftTile        = nTiles[1];
            PATile leftTopTile     = nTiles[2];
            PATile topTile         = nTiles[3];
            PATile rightTopTile    = nTiles[4];
            PATile rightTile       = nTiles[5];
            PATile rightBottomTile = nTiles[6];
            PATile bottomTile      = nTiles[7];
            bool   isPerfect       = true;

            QtrTileElementType qte0 = GetQtrTileElementType(bottomTile, 1);
            QtrTileElementType qte1 = GetQtrTileElementType(leftBottomTile, 2);
            QtrTileElementType qte2 = GetQtrTileElementType(leftTile, 3);
            QtrTileElementType qte  = qtrTiles[0];

            if (qte == qte0 && qte == qte1 && qte == qte2)
            {
            }
            else
            {
                isPerfect   = false;
                qtrTiles[0] = QtrTileElementType.None;
            }


            qte0 = GetQtrTileElementType(leftTile, 2);
            qte1 = GetQtrTileElementType(leftTopTile, 3);
            qte2 = GetQtrTileElementType(topTile, 0);
            qte  = qtrTiles[1];
            if (qte == qte0 && qte == qte1 && qte == qte2)
            {
            }
            else
            {
                isPerfect   = false;
                qtrTiles[1] = QtrTileElementType.None;
            }

            qte0 = GetQtrTileElementType(topTile, 3);
            qte1 = GetQtrTileElementType(rightTopTile, 0);
            qte2 = GetQtrTileElementType(rightTile, 1);
            qte  = qtrTiles[2];
            if (qte == qte0 && qte == qte1 && qte == qte2)
            {
            }
            else
            {
                isPerfect   = false;
                qtrTiles[2] = QtrTileElementType.None;
            }

            qte0 = GetQtrTileElementType(rightTile, 0);
            qte1 = GetQtrTileElementType(rightBottomTile, 1);
            qte2 = GetQtrTileElementType(bottomTile, 2);
            qte  = qtrTiles[3];
            if (qte == qte0 && qte == qte1 && qte == qte2)
            {
            }
            else
            {
                isPerfect   = false;
                qtrTiles[3] = QtrTileElementType.None;
            }

            return(isPerfect);
        }
예제 #31
0
 //n must be 1,3,5,7,9,11... etc
 public PATile[] GetNeighboringTilesNxN(PATile tile, int n)
 {
     return GetNeighboringTilesNxN(tile.x, tile.y, n);
 }
예제 #32
0
    void ProcessMultiElementTile(PATile tile)
    {
        if (tile.IsQtrTilesSet())
        {
            return;
        }

        PATile[] nTiles = GetNeighboringTilesNxN(tile, 1);

        PATile leftBottomTile  = nTiles[0];
        PATile leftTile        = nTiles[1];
        PATile leftTopTile     = nTiles[2];
        PATile topTile         = nTiles[3];
        PATile rightTopTile    = nTiles[4];
        PATile rightTile       = nTiles[5];
        PATile rightBottomTile = nTiles[6];
        PATile bottomTile      = nTiles[7];

        QtrTileElementType qte0 = GetMixQtrTileElementType(bottomTile, 1);
        QtrTileElementType qte1 = GetMixQtrTileElementType(leftBottomTile, 2);
        QtrTileElementType qte2 = GetMixQtrTileElementType(leftTile, 3);

        if (qte0 != QtrTileElementType.None && qte0 != QtrTileElementType.Base)
        {
            tile.qtrTiles[0] = qte0;
        }
        else if (qte1 != QtrTileElementType.None && qte1 != QtrTileElementType.Base)
        {
            tile.qtrTiles[0] = qte1;
        }
        else if (qte2 != QtrTileElementType.None && qte2 != QtrTileElementType.Base)
        {
            tile.qtrTiles[0] = qte2;
        }

        qte0 = GetMixQtrTileElementType(leftTile, 2);
        qte1 = GetMixQtrTileElementType(leftTopTile, 3);
        qte2 = GetMixQtrTileElementType(topTile, 0);
        if (qte0 != QtrTileElementType.None && qte0 != QtrTileElementType.Base)
        {
            tile.qtrTiles[1] = qte0;
        }
        else if (qte1 != QtrTileElementType.None && qte1 != QtrTileElementType.Base)
        {
            tile.qtrTiles[1] = qte1;
        }
        else if (qte2 != QtrTileElementType.None && qte2 != QtrTileElementType.Base)
        {
            tile.qtrTiles[1] = qte2;
        }

        qte0 = GetMixQtrTileElementType(topTile, 3);
        qte1 = GetMixQtrTileElementType(rightTopTile, 0);
        qte2 = GetMixQtrTileElementType(rightTile, 1);
        if (qte0 != QtrTileElementType.None && qte0 != QtrTileElementType.Base)
        {
            tile.qtrTiles[2] = qte0;
        }
        else if (qte1 != QtrTileElementType.None && qte1 != QtrTileElementType.Base)
        {
            tile.qtrTiles[2] = qte1;
        }
        else if (qte2 != QtrTileElementType.None && qte2 != QtrTileElementType.Base)
        {
            tile.qtrTiles[2] = qte2;
        }

        qte0 = GetMixQtrTileElementType(rightTile, 0);
        qte1 = GetMixQtrTileElementType(rightBottomTile, 1);
        qte2 = GetMixQtrTileElementType(bottomTile, 2);
        if (qte0 != QtrTileElementType.None && qte0 != QtrTileElementType.Base)
        {
            tile.qtrTiles[3] = qte0;
        }
        else if (qte1 != QtrTileElementType.None && qte1 != QtrTileElementType.Base)
        {
            tile.qtrTiles[3] = qte1;
        }
        else if (qte2 != QtrTileElementType.None && qte2 != QtrTileElementType.Base)
        {
            tile.qtrTiles[3] = qte2;
        }
    }
예제 #33
0
 public bool GetWalkability(PATile tile)
 {
     return tile.walkability;
 }
예제 #34
0
    void ProcessSingleElememtTile(PATile tile)
    {
        PATile[] nTiles = GetNeighboringTilesNxN(tile, 1);

        PATile leftBottomTile  = nTiles[0];
        PATile leftTile        = nTiles[1];
        PATile leftTopTile     = nTiles[2];
        PATile topTile         = nTiles[3];
        PATile rightTopTile    = nTiles[4];
        PATile rightTile       = nTiles[5];
        PATile rightBottomTile = nTiles[6];
        PATile bottomTile      = nTiles[7];

        QtrTileElementType qte0   = PATile.GetQtrTileElementType(bottomTile, 1);
        QtrTileElementType qte1   = PATile.GetQtrTileElementType(leftBottomTile, 2);
        QtrTileElementType qte2   = PATile.GetQtrTileElementType(leftTile, 3);
        QtrTileElementType preQte = tile.qtrTiles[0];

        if (qte0 != QtrTileElementType.None)
        {
            tile.qtrTiles[0] = qte0;
        }
        else if (qte1 != QtrTileElementType.None)
        {
            tile.qtrTiles[0] = qte1;
        }
        else if (qte2 != QtrTileElementType.None)
        {
            tile.qtrTiles[0] = qte2;
        }

        qte0   = PATile.GetQtrTileElementType(leftTile, 2);
        qte1   = PATile.GetQtrTileElementType(leftTopTile, 3);
        qte2   = PATile.GetQtrTileElementType(topTile, 0);
        preQte = tile.qtrTiles[1];
        if (qte0 != QtrTileElementType.None)
        {
            tile.qtrTiles[1] = qte0;
        }
        else if (qte1 != QtrTileElementType.None)
        {
            tile.qtrTiles[1] = qte1;
        }
        else if (qte2 != QtrTileElementType.None)
        {
            tile.qtrTiles[1] = qte2;
        }

        qte0   = PATile.GetQtrTileElementType(topTile, 3);
        qte1   = PATile.GetQtrTileElementType(rightTopTile, 0);
        qte2   = PATile.GetQtrTileElementType(rightTile, 1);
        preQte = tile.qtrTiles[2];
        if (qte0 != QtrTileElementType.None)
        {
            tile.qtrTiles[2] = qte0;
        }
        else if (qte1 != QtrTileElementType.None)
        {
            tile.qtrTiles[2] = qte1;
        }
        else if (qte2 != QtrTileElementType.None)
        {
            tile.qtrTiles[2] = qte2;
        }

        qte0   = PATile.GetQtrTileElementType(rightTile, 0);
        qte1   = PATile.GetQtrTileElementType(rightBottomTile, 1);
        qte2   = PATile.GetQtrTileElementType(bottomTile, 2);
        preQte = tile.qtrTiles[3];
        if (qte0 != QtrTileElementType.None)
        {
            tile.qtrTiles[3] = qte0;
        }
        else if (qte1 != QtrTileElementType.None)
        {
            tile.qtrTiles[3] = qte1;
        }
        else if (qte2 != QtrTileElementType.None)
        {
            tile.qtrTiles[3] = qte2;
        }

        if (!tile.IsQtrTilesSet())
        {
            Debug.LogWarning("ProcessSingleElememtTile !tile.IsQtrTilesSet() tile.x = " + tile.x + " tile.y " + tile.y);
        }
    }
예제 #35
0
    public void PaintTile5x5(PATile tile, int t)
    {
        if (tile == null)
        {
            return;
        }
        int i;

        t = Mathf.Clamp(t, 0, settings.tsTypes.Count);

        IntermediateInfo[] imInfo = new IntermediateInfo[24];
        PATile[]           tile2  = GetNeighboringTilesNxN(tile, 1);
        PATile[]           tile3  = GetNeighboringTilesNxN(tile, 3);
        PATile[]           nTiles = GetNeighboringTilesNxN(tile, 5);
        PATile[]           tls    = GetNeighboringTilesNxN(tile, 7);

        tile.SetTileProp(t, t, 0);
        UpdateTileUV(tile);

        for (i = 0; i < 8; ++i)
        {
            if (tile2[i] != null)
            {
                tile2[i].SetTileProp(t, t, 0);
                UpdateTileUV(tile2[i]);
            }
        }
        for (i = 0; i < 16; ++i)
        {
            if (tile3[i] != null)
            {
                tile3[i].SetTileProp(t, t, 0);
                UpdateTileUV(tile3[i]);
            }
        }

        //Array visualization, where 'c' = current tile
        // 0  1  2  3  4  5  6  7  8
        // 31 0  1  2  3  4  5  6  9
        // 30 23 x  x  x  x  x  7  10
        // 29 22 x  x  x  x  x  8  11
        // 28 21 x  x  c  x  x  9  12
        // 27 20 x  x  x  x  x  10 13
        // 26 19 x  x  x  x  x  11 14
        // 25 18 17 16 15 14 13 12 15
        // 24 23 22 21 20 19 18 17 16
        //0
        CalcTileBits(t, nTiles[0], 2, out imInfo[0]);
        //1
        CalcTileBits(t, nTiles[1], 3, out imInfo[1]);
        //2
        CalcTileBits(t, nTiles[2], 3, out imInfo[2]);
        //3
        CalcTileBits(t, nTiles[3], 3, out imInfo[3]);
        //4
        CalcTileBits(t, nTiles[4], 3, out imInfo[4]);
        //5
        CalcTileBits(t, nTiles[5], 3, out imInfo[5]);
        //6
        CalcTileBits(t, nTiles[6], 1, out imInfo[6]);

        //7
        CalcTileBits(t, nTiles[7], 9, out imInfo[7]);
        //8
        CalcTileBits(t, nTiles[8], 9, out imInfo[8]);
        //9
        CalcTileBits(t, nTiles[9], 9, out imInfo[9]);
        //10
        CalcTileBits(t, nTiles[10], 9, out imInfo[10]);
        //11
        CalcTileBits(t, nTiles[11], 9, out imInfo[11]);

        //12
        CalcTileBits(t, nTiles[12], 8, out imInfo[12]);
        //13
        CalcTileBits(t, nTiles[13], 12, out imInfo[13]);
        //14
        CalcTileBits(t, nTiles[14], 12, out imInfo[14]);
        //15
        CalcTileBits(t, nTiles[15], 12, out imInfo[15]);
        //16
        CalcTileBits(t, nTiles[16], 12, out imInfo[16]);
        //17
        CalcTileBits(t, nTiles[17], 12, out imInfo[17]);
        //18
        CalcTileBits(t, nTiles[18], 4, out imInfo[18]);

        //19
        CalcTileBits(t, nTiles[19], 6, out imInfo[19]);
        //20
        CalcTileBits(t, nTiles[20], 6, out imInfo[20]);
        //21
        CalcTileBits(t, nTiles[21], 6, out imInfo[21]);
        //22
        CalcTileBits(t, nTiles[22], 6, out imInfo[22]);
        //23
        CalcTileBits(t, nTiles[23], 6, out imInfo[23]);

        //0
        //CalcIntermediateTileBits(tls[0], 2, imInfo[0]);
        ////1
        //CalcIntermediateTileBits(tls[1], 3, imInfo[0]);
        ////2
        //CalcIntermediateTileBits(tls[2], 3, imInfo[1]);
        ////3
        //CalcIntermediateTileBits(tls[3], 3, imInfo[2]);
        ////4
        //CalcIntermediateTileBits(tls[4], 3, imInfo[3]);
        ////5
        //CalcIntermediateTileBits(tls[5], 3, imInfo[4]);
        ////6
        //CalcIntermediateTileBits(tls[6], 1, imInfo[4]);

        ////7
        //CalcIntermediateTileBits(tls[7], 9, imInfo[4]);
        ////8
        //CalcIntermediateTileBits(tls[8], 9, imInfo[5]);
        ////9
        //CalcIntermediateTileBits(tls[9], 9, imInfo[6]);
        ////10
        //CalcIntermediateTileBits(tls[10], 9, imInfo[7]);
        ////11
        //CalcIntermediateTileBits(tls[11], 9, imInfo[8]);

        ////12
        //CalcIntermediateTileBits(tls[12], 8, imInfo[8]);
        ////13
        //CalcIntermediateTileBits(tls[13], 12, imInfo[8]);
        ////14
        //CalcIntermediateTileBits(tls[14], 12, imInfo[9]);
        ////15
        //CalcIntermediateTileBits(tls[15], 12, imInfo[10]);
        ////16
        //CalcIntermediateTileBits(tls[16], 12, imInfo[11]);
        ////17
        //CalcIntermediateTileBits(tls[17], 12, imInfo[12]);
        ////18
        //CalcIntermediateTileBits(tls[18], 4, imInfo[12]);

        ////19
        //CalcIntermediateTileBits(tls[19], 6, imInfo[12]);
        ////20
        //CalcIntermediateTileBits(tls[20], 6, imInfo[13]);
        ////21
        //CalcIntermediateTileBits(tls[21], 6, imInfo[14]);
        ////22
        //CalcIntermediateTileBits(tls[22], 6, imInfo[15]);
        ////23
        //CalcIntermediateTileBits(tls[23], 6, imInfo[0]);
    }
예제 #36
0
    //bool IsFullMix(PATile[] nTiles)
    //{
    //    bool result = true;
    //    foreach(var nTile in nTiles)
    //    {
    //        result &= PATile.IsMultiElement(nTile);
    //        if (!result)
    //            return false;
    //    }
    //    return true;
    //}

    void PaintAMultiElementTile(PATile tile, List <PATile> postProcessMultiElementTiles = null)
    {
        //if (tile.element.IsSingleElement())
        //    return;

        PATile[] nTiles = GetNeighboringTilesNxN(tile, 1);

        PATile leftBottomTile  = nTiles[0];
        PATile leftTile        = nTiles[1];
        PATile leftTopTile     = nTiles[2];
        PATile topTile         = nTiles[3];
        PATile rightTopTile    = nTiles[4];
        PATile rightTile       = nTiles[5];
        PATile rightBottomTile = nTiles[6];
        PATile bottomTile      = nTiles[7];

        int fromType = 0;
        int toType   = 0;
        //QtrTileElementType qtrTileElementType = QtrTileElementType.None;
        QtrTileElementType qtrTileElementType   = GetQtrTileElementType(nTiles);
        QtrTileElementType toQtrTileElementType = QtrTileElementType.None;

        if (qtrTileElementType == QtrTileElementType.Fire)
        {
            fromType             = FireLevel1Brush;
            toType               = WoodLevel1Brush;
            toQtrTileElementType = QtrTileElementType.Wood;
        }
        else if (qtrTileElementType == QtrTileElementType.Wood)
        {
            fromType             = WoodLevel1Brush;
            toType               = FireLevel1Brush;
            toQtrTileElementType = QtrTileElementType.Fire;
        }

        //TileElementState leftTopElementState = GetTileElementState(leftTopTile);
        //TileElementState leftBottomElementState = GetTileElementState(leftBottomTile);
        //TileElementState rightTopElementState = GetTileElementState(rightTopTile);
        //TileElementState rightBottomElementState = GetTileElementState(rightBottomTile);

        TileElementType leftTopElementType     = PATileElement.GetTileElementType(leftTopTile);
        TileElementType leftBottomElementType  = PATileElement.GetTileElementType(leftBottomTile);
        TileElementType rightTopElementType    = PATileElement.GetTileElementType(rightTopTile);
        TileElementType rightBottomElementType = PATileElement.GetTileElementType(rightBottomTile);


        if (PATile.IsSingleElement(leftTopTile) &&
            PATile.IsSingleElement(leftTile) &&
            PATile.IsSingleElement(topTile) &&
            PATile.IsMultiElement(rightBottomTile) &&
            PATile.IsTileSetType(leftTopTile, TileSetType.Full) &&
            PATile.IsTileSetType(leftTile, TileSetType.Full) &&
            PATile.IsTileSetType(topTile, TileSetType.Full))
        {
            if (leftTopElementType == TileElementType.Fire)
            {
                qtrTileElementType   = QtrTileElementType.Fire;
                toQtrTileElementType = QtrTileElementType.Wood;
                fromType             = FireLevel1Brush;
                toType = WoodLevel1Brush;
            }
            else if (leftTopElementType == TileElementType.Wood)
            {
                qtrTileElementType   = QtrTileElementType.Wood;
                toQtrTileElementType = QtrTileElementType.Fire;
                fromType             = WoodLevel1Brush;
                toType = FireLevel1Brush;
            }

            tile.SetTileProp(fromType, toType, 14);
            tile.SetQtrTiles(qtrTileElementType, qtrTileElementType, qtrTileElementType, toQtrTileElementType);
            tile.tileSetType = TileSetType.BigCorner;
        }
        else if (PATile.IsSingleElement(rightTopTile) &&
                 PATile.IsSingleElement(rightTile) &&
                 PATile.IsSingleElement(topTile) &&
                 PATile.IsMultiElement(leftBottomTile) &&
                 PATile.IsTileSetType(rightTopTile, TileSetType.Full) &&
                 PATile.IsTileSetType(rightTile, TileSetType.Full) &&
                 PATile.IsTileSetType(topTile, TileSetType.Full))
        {
            if (rightTopElementType == TileElementType.Fire)
            {
                qtrTileElementType   = QtrTileElementType.Fire;
                toQtrTileElementType = QtrTileElementType.Wood;
                fromType             = FireLevel1Brush;
                toType = WoodLevel1Brush;
            }
            else if (rightTopElementType == TileElementType.Wood)
            {
                qtrTileElementType   = QtrTileElementType.Wood;
                toQtrTileElementType = QtrTileElementType.Fire;
                fromType             = WoodLevel1Brush;
                toType = FireLevel1Brush;
            }

            tile.SetTileProp(fromType, toType, 7);
            tile.SetQtrTiles(toQtrTileElementType, qtrTileElementType, qtrTileElementType, qtrTileElementType);
            tile.tileSetType = TileSetType.BigCorner;
        }
        else if (PATile.IsSingleElement(leftBottomTile) &&
                 PATile.IsSingleElement(leftTile) &&
                 PATile.IsSingleElement(bottomTile) &&
                 PATile.IsMultiElement(rightTopTile) &&
                 PATile.IsTileSetType(leftBottomTile, TileSetType.Full) &&
                 PATile.IsTileSetType(leftTile, TileSetType.Full) &&
                 PATile.IsTileSetType(bottomTile, TileSetType.Full))
        {
            if (leftBottomElementType == TileElementType.Fire)
            {
                qtrTileElementType   = QtrTileElementType.Fire;
                toQtrTileElementType = QtrTileElementType.Wood;
                fromType             = FireLevel1Brush;
                toType = WoodLevel1Brush;
            }
            else if (leftBottomElementType == TileElementType.Wood)
            {
                qtrTileElementType   = QtrTileElementType.Wood;
                toQtrTileElementType = QtrTileElementType.Fire;
                fromType             = WoodLevel1Brush;
                toType = FireLevel1Brush;
            }

            tile.SetTileProp(fromType, toType, 13);
            tile.SetQtrTiles(qtrTileElementType, qtrTileElementType, toQtrTileElementType, qtrTileElementType);
            tile.tileSetType = TileSetType.BigCorner;
        }
        else if (PATile.IsSingleElement(rightBottomTile) &&
                 PATile.IsSingleElement(rightTile) &&
                 PATile.IsSingleElement(bottomTile) &&
                 PATile.IsMultiElement(leftTopTile) &&
                 PATile.IsTileSetType(rightBottomTile, TileSetType.Full) &&
                 PATile.IsTileSetType(rightTile, TileSetType.Full) &&
                 PATile.IsTileSetType(bottomTile, TileSetType.Full))
        {
            if (rightBottomElementType == TileElementType.Fire)
            {
                qtrTileElementType   = QtrTileElementType.Fire;
                toQtrTileElementType = QtrTileElementType.Wood;
                fromType             = FireLevel1Brush;
                toType = WoodLevel1Brush;
            }
            else if (rightBottomElementType == TileElementType.Wood)
            {
                qtrTileElementType   = QtrTileElementType.Wood;
                toQtrTileElementType = QtrTileElementType.Fire;
                fromType             = WoodLevel1Brush;
                toType = FireLevel1Brush;
            }

            tile.SetTileProp(fromType, toType, 11);
            tile.SetQtrTiles(qtrTileElementType, toQtrTileElementType, qtrTileElementType, qtrTileElementType);
            tile.tileSetType = TileSetType.BigCorner;
        }

        //else if (IsFullMix(nTiles))
        //{
        //    tile.SetTileProp(SandBrush, SandBrush, 0);
        //    tile.SetQtrTiles(QtrTileElementType.Sand);
        //    tile.tileSetType = TileSetType.Full;
        //}

        else if (IsCornerMix(nTiles, 0))
        {
            tile.SetTileProp(fromType, toType, 8);
            tile.SetQtrTiles(qtrTileElementType, toQtrTileElementType, toQtrTileElementType, toQtrTileElementType);
            tile.tileSetType = TileSetType.Corner;
        }
        else if (IsCornerMix(nTiles, 2))
        {
            tile.SetTileProp(fromType, toType, 4);
            tile.SetQtrTiles(toQtrTileElementType, qtrTileElementType, toQtrTileElementType, toQtrTileElementType);
            tile.tileSetType = TileSetType.Corner;
        }
        else if (IsCornerMix(nTiles, 4))
        {
            tile.SetTileProp(fromType, toType, 2);
            tile.SetQtrTiles(toQtrTileElementType, toQtrTileElementType, qtrTileElementType, toQtrTileElementType);
            tile.tileSetType = TileSetType.Corner;
        }
        else if (IsCornerMix(nTiles, 6))
        {
            tile.SetTileProp(fromType, toType, 1);
            tile.SetQtrTiles(toQtrTileElementType, toQtrTileElementType, toQtrTileElementType, qtrTileElementType);
            tile.tileSetType = TileSetType.Corner;
        }

        else
        {
            postProcessMultiElementTiles.Add(tile);
            tile.SetQtrTiles(QtrTileElementType.None);
            return;
        }

        UpdateTileUV(tile);
    }