private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
     GenerateLakes();
 }
示例#2
0
    /// <summary>
    /// Generates the world.
    /// Initiates a <see cref="TerrainGenerator"/> & generates the base Terrain <see cref="TerrainGenerator.GenerateBaseTerrain"/>
    /// Then Initiates a <see cref="KingdomsGenerator"/> that generates all the kingdoms, as well as claiming all their territory
    /// Then generates terrain details using <see cref="TerrainGenerator.GenerateWorldDetailTerrain"/>
    /// Finally, generates all settlements using <see cref="KingdomsGenerator.GenerateAllKingdomSettlements"/>
    ///
    /// TODO - Add dungeon generation, add settlement details generation (roads + paths)
    /// </summary>
    /// <returns></returns>
    public void GenerateWorld(WorldManager wm)
    {
        //Set Random init state based on seed
        Random.InitState(Seed);
        MiscMaths.SetRandomSeed(Seed);
        //Initiate empty world and generate base terrain
        World = new World();
        wm.SetWorld(World);

        //Create a default RNG to be used by the generators (Not thread safe)
        MainGenerator = new GenerationRandom(Seed);
        //Generation starts
        TerrainGenerator = new TerrainGenerator(this, World);
        RiverGenerator   = new RiverGenerator(this);
        LakeGenerator    = new LakeGenerator(this);


        Debug.BeginDeepProfile("chunk_base_gen");

        TerrainGenerator.GenerateChunkBases();//Generate the chunk bases, these only define if they are land or sea.

        //Generates fine terrain details: rivers, lakes, (todo - marshes, more variety to forrests?)
        TerrainGenerator.GenerateTerrainDetails();

        Debug.EndDeepProfile("chunk_base_gen");



        //TODO - check if this is still required (probably not)
        ChunkGenerator = new ChunkGenerator(this);



        Debug.BeginDeepProfile("kingdom_set_gen");
        //We then generate empty kingdoms based on these empty chunks
        KingdomsGenerator kingGen = new KingdomsGenerator(World, this);

        //We also generate the all empty settlements for the world.
        kingGen.GenerateEmptyKingdomsFromBaseChunks(4);
        //Generates all settlement chunks
        PreGeneratedChunks = kingGen.GenerateSettlements();

        Debug.EndDeepProfile("kingdom_set_gen");


        Debug.BeginDeepProfile("chunk_struct_gen");
        //Generate chunk structures (bandit camps, etc)
        StructureGenerator = new ChunkStructureGenerator(this);
        StructureGenerator.GenerateStructureShells();

        //Iterate all chunks generated for chunk structures, add them to the PreGeneratedChunks
        foreach (KeyValuePair <Vec2i, ChunkData> kvp in StructureGenerator.GenerateAllStructures())
        {
            PreGeneratedChunks.Add(kvp.Key, kvp.Value);
        }
        Debug.EndDeepProfile("chunk_struct_gen");


        Debug.BeginDeepProfile("terrain_map_gen");
        //Create a simple map based on the terrain of the world
        GenerateTerrainMap(TerrainGenerator.ChunkBases);
        Debug.EndDeepProfile("terrain_map_gen");
    }