コード例 #1
0
    static void SpawnSpecies(PrefabSpawner spawner, AnimalSpeciesSettings settings)
    {
        int initialPopulationSize = prng.Next(
            settings.minStartingPopulation,
            settings.maxStartingPopulation
            );

        // Select an initial spawn point prior to starting the loop
        MapGraph.Node spawnPoint = SelectSpawnPoint();

        for (int i = 0; i < initialPopulationSize; i++)
        {
            // Spawn a new instance of the prefab.
            MeshRenderer obj = spawner.SpawnPrefab(settings.prefab, spawnPoint.centerPoint - mapGraph.center, RandomRotation());

            // Mark the node as occupied.
            spawnPoint.numAnimalOccupants++;

            // Randomize the neighbours so that we're not just iterating
            // through linearly.
            var neighbours = spawnPoint.GetNeighbourNodes()
                             .OrderBy(_ => prng.Next())
                             .ToList();

            // Attempt to select a random neighbouring node as the next spawn
            // point.
            int j;
            for (j = 0; j < neighbours.Count; j++)
            {
                if (allowedNodeTypes.Contains(neighbours[j].nodeType) &&
                    !neighbours[j].occupied)
                {
                    spawnPoint = neighbours[j];
                    break;
                }
            }

            // If none of the neighbouring nodes are valid candidates, just
            // randomly select a new one instead.
            if (j >= neighbours.Count)
            {
                spawnPoint = SelectSpawnPoint();
            }
        }
    }
コード例 #2
0
ファイル: MapGenerator.cs プロジェクト: r2d2m/EcoSim
    private static void FloodFill(
        MapGraph.Node node,
        MapGraph.NodeType targetType,
        MapGraph.NodeType replacementType
        )
    {
        if (targetType == replacementType ||
            node.nodeType != targetType)
        {
            return;
        }

        node.nodeType = replacementType;
        foreach (var neighbor in node.GetNeighbourNodes())
        {
            FloodFill(neighbor, targetType, replacementType);
        }
    }