Ejemplo n.º 1
0
    //周囲の同じ種別の地形をカウント
    static private CountInfo countSameCell(int treatCount, Vector2Int size, WorldDataConst.EachTerrainData[] tileMap, int x, int y)
    {
        int cellCount = 0;

        WorldDataConst.EachTerrainData currentTile     = tileMap[y * size.x + x];
        WorldDataConst.TileType        currentTileType = currentTile.type;
        WorldDataConst.TileType        diffTileType    = WorldDataConst.TileType.NONE;

        for (int i = 0; i < treatCount; i++)
        {
            Vector2Int targetPos = treatPosition(size, x + (int)WorldDataConst.DIRECTIONS[i].x, y + (int)WorldDataConst.DIRECTIONS[i].y);
            //           Debug.Log(targetPos.x + " " + size.x + " " +  targetPos.y + " "+size.y);
            WorldDataConst.TileType roundTileType = tileMap[targetPos.y * size.x + targetPos.x].type;
            if (currentTileType != roundTileType)
            {
                cellCount++;
                diffTileType = roundTileType;
            }
        }
        return(new CountInfo()
        {
            currentTile = currentTile,
            diffType = diffTileType,
            count = cellCount
        });
    }
Ejemplo n.º 2
0
    public void TransferData_Split(int minX, int minY, int maxX, int maxY)
    {
        int maxChunkX = maxX / TransferSize;
        int maxChunkY = maxY / TransferSize;
        int minChunkX = minX / TransferSize;
        int minChunkY = minY / TransferSize;

        for (int chunkY = minChunkY; chunkY <= maxChunkY; chunkY++)
        {
            for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++)
            {
                if (dispInfo.generationList == null)
                {
                    dispInfo.generationList = Enumerable.Repeat(-1, (worldMgr.worldData.width / TransferSize) * (worldMgr.worldData.height / TransferSize)).ToArray();
                }
                int currentChunkNum_Session = 0;
                try
                {
                    currentChunkNum_Session = dispInfo.generationList[chunkY * (worldMgr.worldData.width / TransferSize) + chunkX];
                }
                catch (System.Exception ex)
                {
                    Debug.Log(chunkX + " " + TransferSize + " " + minY + " " + worldMgr.worldData.width + " " + chunkY + " " + TransferSize + " " + minX);
                }

                int currentChunkNum_System = 0;
                if (worldMgr.generationList.Length < chunkY * (worldMgr.worldData.width / TransferSize) + chunkX)
                {
                    currentChunkNum_System = worldMgr.generationList[chunkY * (worldMgr.worldData.width / TransferSize) + chunkX];
                }
                if (currentChunkNum_Session != currentChunkNum_System)
                {
                    EachTerrainTileData[] result = new EachTerrainTileData[TransferSize * TransferSize];
                    for (int y = 0; y < TransferSize; y++)
                    {
                        for (int x = 0; x < TransferSize; x++)
                        {
                            try
                            {
                                WorldDataConst.EachTerrainData sourceItem = worldMgr.worldData.terrainList[((chunkY * TransferSize) + y) * worldMgr.worldData.width + chunkX * TransferSize + x];
                                EachTerrainTileData            item       = new EachTerrainTileData();
                                item.type = sourceItem.type;
                                item.x    = sourceItem.x;
                                item.y    = sourceItem.y;
                                result[y * TransferSize + x] = item;
                            }
                            catch (System.Exception ex)
                            {
                                Debug.Log(ex.StackTrace);
                                Debug.Log(chunkX + " " + TransferSize + " " + minY + " " + worldMgr.worldData.width + " " + chunkY + " " + TransferSize + " " + minX);
                            }
                        }
                    }
                    TargetTransfer(connectionToClient, chunkY * TransferSize + minY, chunkX * TransferSize + minX, TransferSize, TransferSize, result);
                    dispInfo.generationList[chunkY * (worldMgr.worldData.width / TransferSize) + chunkX] = currentChunkNum_System;
                }
            }
        }
    }
Ejemplo n.º 3
0
    //地形のサイズを計るため、エリア情報を作成し、サイズをカウント
    static private List <AreaInvestigationInfo> investigationSizeList(Vector2Int size, WorldDataConst.EachTerrainData[] tileMap, int[] areaNolist)
    {
        List <AreaInvestigationInfo> sizeList = new List <AreaInvestigationInfo>();


        for (int y = 0; y < size.y; y++)
        {
            for (int x = 0; x < size.x; x++)
            {
                WorldDataConst.EachTerrainData tile = tileMap[y * size.x + x];

                if (areaNolist[y * size.x + x] == -1)
                {
                    areaNolist[y * size.x + x] = sizeList.Count;
                    AreaInvestigationInfo newfield = new AreaInvestigationInfo();
                    newfield.parentArea = sizeList.Count;
                    newfield.size       = 1;
                    sizeList.Add(newfield);
                }

                Vector2[] dirirections_2 = new Vector2[]
                {
                    new Vector2(1, 0),
                    new Vector2(0, 1)
                };

                int currentAreaNo = areaNolist[y * size.x + x];
                for (int i = 0; i < dirirections_2.Length; i++)
                {
                    Vector2Int targetPos = treatPosition(size, x + (int)WorldDataConst.DIRECTIONS[i].x, y + (int)WorldDataConst.DIRECTIONS[i].y);
                    WorldDataConst.EachTerrainData roundTile = tileMap[targetPos.y * size.x + targetPos.x];
                    if (roundTile.type == tile.type)
                    {
                        int targetAreaNo = areaNolist[targetPos.y * size.x + targetPos.x];
                        if (targetAreaNo == -1)
                        {
                            areaNolist[targetPos.y * size.x + targetPos.x] = currentAreaNo;
                            sizeList[currentAreaNo].size++;
                        }
                        else if (
                            (targetAreaNo != currentAreaNo) &&
                            (sizeList[targetAreaNo].parentArea != currentAreaNo) &&
                            (targetAreaNo != sizeList[currentAreaNo].parentArea)
                            )
                        {
                            int serachPoleA = getRootAreaNo(targetAreaNo, sizeList);
                            int serachPoleB = getRootAreaNo(currentAreaNo, sizeList);
                            if (serachPoleA != serachPoleB)
                            {
                                sizeList[serachPoleA].parentArea = serachPoleB;
                            }
                        }
                    }
                }
            }
        }
        return(sizeList);
    }
Ejemplo n.º 4
0
    //小さな島を削除
    static private WorldDataConst.EachTerrainData[] removeSmallIsland(Vector2Int size, WorldDataConst.EachTerrainData[] tileMap, int[] areaNolist, List <AreaInvestigationInfo> sizeList)
    {
        for (int y = 0; y < size.y; y++)
        {
            for (int x = 0; x < size.x; x++)
            {
                WorldDataConst.EachTerrainData tile = tileMap[y * size.x + x];
                int areaNo     = areaNolist[y * size.x + x];
                int islandNum  = sizeList[areaNo].parentArea;
                int islandSize = sizeList[islandNum].size;

                if ((tile.type == WorldDataConst.TileType.FIELD) && (islandSize < 10))
                {
                    tile.type = WorldDataConst.TileType.SEA;
                }
            }
        }
        return(tileMap);
    }
Ejemplo n.º 5
0
    static public Texture2D createMapPicture(WorldDataConst.WorldData worldData)
    {
        // テクスチャ生成
        var tex = new Texture2D(worldData.width, worldData.height);

        for (int y = 0; y < worldData.height; y++)
        {
            for (int x = 0; x < worldData.width; x++)
            {
                WorldDataConst.EachTerrainData terrainData = worldData.terrainList[y * worldData.width + x];
                Color  color       = Color.cyan;
                string colorString = "#4080C0"; // 赤色の16進数文字列
                ColorUtility.TryParseHtmlString(colorString, out color);
                if (terrainData.type == WorldDataConst.TileType.FIELD)
                {
                    colorString = "#A7C131"; // 赤色の16進数文字列
                    ColorUtility.TryParseHtmlString(colorString, out color);
                }
                tex.SetPixel(x, y, color);
            }
        }
        return(tex);
    }
Ejemplo n.º 6
0
    //初期マップを生成
    static private WorldDataConst.EachTerrainData[] generateFirstTileMap(
        System.Random rnd,
        Vector2Int size,
        List <BandSeed> verticalBands,
        List <BandSeed> horizontalBands,
        List <TerrainSeed> sea_seeds,
        List <TerrainSeed> field_seeds
        )
    {
        WorldDataConst.EachTerrainData[] tileMap = new WorldDataConst.EachTerrainData[size.x * size.y];
        for (int y = 0; y < size.y; y++)
        {
            bool verticalSplitFlag = false;
            for (int i = 0; i < verticalBands.Count; i++)
            {
                if ((verticalBands[i].position * verticalBands[i].bandWidth <= y) && ((verticalBands[i].position + 1) * verticalBands[i].bandWidth > y))
                {
                    verticalSplitFlag = true;
                    break;
                }
            }
            for (int x = 0; x < size.x; x++)
            {
                WorldDataConst.EachTerrainData tile = new WorldDataConst.EachTerrainData();
                tile.x = x;
                tile.y = y;
                WorldDataConst.TileType type = WorldDataConst.TileType.NONE;

                for (int i = 0; i < sea_seeds.Count; i++)
                {
                    if ((Mathf.Pow((sea_seeds[i].position.x - x), 2) + Mathf.Pow((sea_seeds[i].position.y - y), 2)) < Mathf.Pow(sea_seeds[i].radius, 2))
                    {
                        type = WorldDataConst.TileType.SEA;
                        break;
                    }
                }

                if (type == WorldDataConst.TileType.NONE)
                {
                    for (int i = 0; i < field_seeds.Count; i++)
                    {
                        if ((Mathf.Pow((field_seeds[i].position.x - x), 2) + Mathf.Pow((field_seeds[i].position.y - y), 2)) < Mathf.Pow(field_seeds[i].radius, 2))
                        {
                            type = WorldDataConst.TileType.FIELD;
                            break;
                        }
                    }
                }
                if ((type == WorldDataConst.TileType.NONE) && (verticalSplitFlag))
                {
                    type = WorldDataConst.TileType.SEA;
                }

                if (type == WorldDataConst.TileType.NONE)
                {
                    for (int i = 0; i < horizontalBands.Count; i++)
                    {
                        if ((horizontalBands[i].position * horizontalBands[i].bandWidth <= x) && ((horizontalBands[i].position + 1) * horizontalBands[i].bandWidth > x))
                        {
                            type = WorldDataConst.TileType.SEA;
                            break;
                        }
                    }
                }
                if (type == WorldDataConst.TileType.NONE)
                {
                    type = WorldDataConst.TileType.SEA;
                    if (rnd.Next(0, 2) == 0)
                    {
                        type = WorldDataConst.TileType.FIELD;
                    }
                }

                tile.type = type;
                tileMap[y * size.x + x] = tile;
            }
        }
        return(tileMap);
    }