Beispiel #1
0
    public TileProject[,] GenerateOres(int mapSizeX, int mapSizeY, int surfaceLevel, int bedrockSize, OresSettings oresSettings, TileMap groundPrefab)
    {
        OreToSpawn ore;

        tempTiles = new TileProject[mapSizeX, mapSizeY];

        for (int i = 0; i < oresSettings.ores.Count; i++)
        {
            ore           = new OreToSpawn();
            ore.ore       = oresSettings.ores[i].oreType;
            ore.settings  = oresSettings.ores[i].smallGroup;
            ore.groupSize = 0;
            ore.CalculateChances();
            waitingOres.Add(ore);
            ore           = new OreToSpawn();
            ore.ore       = oresSettings.ores[i].oreType;
            ore.settings  = oresSettings.ores[i].mediumGroup;
            ore.groupSize = 1;
            ore.CalculateChances();
            waitingOres.Add(ore);
            ore           = new OreToSpawn();
            ore.ore       = oresSettings.ores[i].oreType;
            ore.settings  = oresSettings.ores[i].largeGroup;
            ore.groupSize = 2;
            ore.CalculateChances();
            waitingOres.Add(ore);
        }

        for (int i = surfaceLevel + 1; i < mapSizeY - bedrockSize; i++)
        {
            CheckAvailability(i);
            for (int j = bedrockSize; j < mapSizeX - bedrockSize; j++)
            {
                for (int k = 0; k < readyOres.Count; k++)
                {
                    if (Randomize(readyOres[k].chancesPerRow[i]) && tempTiles[j, i] == null)
                    {
                        SpawnGroup(j, i, readyOres[k]);
                        break;
                    }
                }
            }
        }
        return(tempTiles);
    }
Beispiel #2
0
    void SpawnGroup(int x, int y, OreToSpawn ore)
    {
        TileProject tile = new TileProject();

        tile.groupSize  = ore.groupSize;
        tile.ore        = ore.ore;
        tile.amount     = ore.settings.oreAmount;
        tempTiles[x, y] = tile;
        int        groupSize = Random.Range(ore.settings.minGroupSize, ore.settings.maxGroupSize + 1);
        int        check = 0, minGroupSize = 0, rand;
        List <int> dirs = RandomizeDir();

        // dodaj while który w przypadku dużych grup będzie umieszczał złoża z innych pól a nie tylko z pierwszego
        for (int i = 0; i < dirs.Count; i++)
        {
            rand = ore.groupSize;             //Random.Range(minGroupSize, ore.groupSize + 1);
            //if (rand == minGroupSize) minGroupSize = minGroupSize == 0 ? minGroupSize : minGroupSize - 1;
            //else minGroupSize = minGroupSize < ore.groupSize ? minGroupSize + 1 : minGroupSize;

            if (dirs[i] == 0)
            {
                if (tempTiles[x + 1, y] == null)
                {
                    tempTiles[x + 1, y]           = tile;
                    tempTiles[x + 1, y].groupSize = rand;
                    tempTiles[x, y].UpdateList(tempTiles[x + 1, y]);
                    tempTiles[x + 1, y].group = tempTiles[x, y].group;
                    groupSize--;
                    // dodaj w każdym ifie zliczanie wygenerowanych złóż żeby na końcu podliczyć ich ilość
                    // i na bierząco kontrolować czy nie spawnuje sie ich za dużo
                }
            }
            else if (dirs[i] == 1)
            {
                if (tempTiles[x, y + 1] == null)
                {
                    tempTiles[x, y + 1]           = tile;
                    tempTiles[x, y + 1].groupSize = rand;
                    tempTiles[x, y].UpdateList(tempTiles[x, y + 1]);
                    tempTiles[x, y + 1].group = tempTiles[x, y].group;
                    groupSize--;
                }
            }
            else if (dirs[i] == 2)
            {
                if (tempTiles[x - 1, y] == null)
                {
                    tempTiles[x - 1, y]           = tile;
                    tempTiles[x - 1, y].groupSize = rand;
                    tempTiles[x, y].UpdateList(tempTiles[x - 1, y]);
                    tempTiles[x - 1, y].group = tempTiles[x, y].group;
                    groupSize--;
                }
            }
            else if (dirs[i] == 3)
            {
                if (tempTiles[x, y - 1] == null)
                {
                    tempTiles[x, y - 1]           = tile;
                    tempTiles[x, y - 1].groupSize = rand;
                    tempTiles[x, y].UpdateList(tempTiles[x, y - 1]);
                    tempTiles[x, y - 1].group = tempTiles[x, y].group;
                    groupSize--;
                }
            }
            if (groupSize == 0)
            {
                return;
            }

            check++;
            if (check > 10)
            {
                return;
            }
        }
    }