示例#1
0
    private void Start()
    {
        int Size = 8;
        int seed = System.DateTime.Now.Millisecond;

        Debug.Log(seed);
        GenerationRandom genRan = new GenerationRandom(seed);


        TestBuildingBuilder tbb = new TestBuildingBuilder(new Vec2i(0, 0), new Vec2i(Size, Size));


        for (int x = 0; x < Size / 2; x++)
        {
            for (int z = 0; z < Size / 2; z++)
            {
                //  if (x != 0 || z != 0)
                //    continue;
                int xP = x * World.ChunkSize * 2;
                int zP = z * World.ChunkSize * 2;
            }
        }


/*
 *      Building b = BuildingGenerator.CreateBuilding(genRan, out BuildingVoxels vox, Building.HOUSE);
 *      Building b1 = BuildingGenerator.CreateBuilding(genRan, out BuildingVoxels vox1, Building.BLACKSMITH);
 *
 *      Building b2 = BuildingGenerator.CreateBuilding(genRan, out BuildingVoxels vox2, Building.HOUSE);
 *      Building b3 = BuildingGenerator.CreateBuilding(genRan, out BuildingVoxels vox3, Building.HOUSE);
 *      Building b4 = BuildingGenerator.CreateBuilding(genRan, out BuildingVoxels vox4, Building.HOUSE);
 *
 *      //tbb.AddBuilding(b, vox, new Vec2i(10, 10));
 *      tbb.AddBuilding(b1, vox1, new Vec2i(40, 40));
 *      tbb.AddBuilding(b2, vox2, new Vec2i(60, 60));
 *      tbb.AddBuilding(b3, vox3, new Vec2i(60, 40));
 *      tbb.AddBuilding(b4, vox4, new Vec2i(40, 60));
 */
        List <ChunkData> chunks = tbb.ToChunkData();

        Chunks = new ChunkData[Size, Size];

        foreach (ChunkData cd in chunks)
        {
            Chunks[cd.X, cd.Z] = cd;
        }

        foreach (ChunkData cd in Chunks)
        {
            PreLoadedChunk plc = GeneratePreLoadedChunk(cd);

            CreateChunk(plc, cd);
        }

        for (int x = 0; x < 20; x++)
        {
            //Debug.Log(tbb.GetVoxelNode(x,1,15);
        }
    }
示例#2
0
 public KingdomNPCGenerator(GameGenerator gameGen, Kingdom kingdom, EntityManager entityManager)
 {
     GameGen = gameGen;
     //Create a RNG based on this seed and kingdomID
     GenerationRan = new GenerationRandom(GameGen.Seed * 13 + kingdom.KingdomID * 27);
     Kingdom       = kingdom;
     EntityManager = entityManager;
 }
示例#3
0
 //Initiats the Kingdom generator, the World given is the world the kingdoms will be added to.
 public KingdomsGenerator(World world, GameGenerator gameGen)
 {
     GameGenerator      = gameGen;
     World              = world;
     TerrainGenerator   = GameGenerator.TerrainGenerator;
     KingdomChunks      = new Dictionary <Kingdom, List <Vec2i> >(World.ChunkSize * World.ChunkSize / 3);
     KingdomSettlements = new Dictionary <Kingdom, List <SettlementBase> >();
     GenerationRandom   = new GenerationRandom(gameGen.Seed);
 }
示例#4
0
 public Entity ChooseRandomEntity(GenerationRandom ran = null)
 {
     Debug.Log(AllEntities.Count);
     if (ran == null)
     {
         return(GameManager.RNG.RandomFromList(AllEntities));
     }
     return(ran.RandomFromList(AllEntities));
 }
示例#5
0
    private static void ChooseWallBounds(GenerationRandom genRan, Barracks bar)
    {
        Vec2i[] wallPoints = new Vec2i[4];
        wallPoints[0] = new Vec2i(0, 0);
        wallPoints[1] = new Vec2i(bar.Width / 2, 0);
        wallPoints[2] = new Vec2i(bar.Width / 2, bar.Height - 1);
        wallPoints[3] = new Vec2i(0, bar.Height - 1);

        bar.BoundingWall = wallPoints;
    }
示例#6
0
    /// <summary>
    /// We override the create world object function for a tree. This is done as we need to load in multiple
    /// parts of the tree
    /// </summary>
    /// <param name="transform"></param>
    /// <returns></returns>
    public override WorldObject CreateWorldObject(Transform transform = null)
    {
        //Create random with seed unique to tree position - this ensures tree should be same every time.
        GenerationRandom genRan = new GenerationRandom(WorldPosition.x * World.WorldSize * World.ChunkSize + WorldPosition.z);
        int   canopy            = genRan.RandomInt(3, 7);
        float angleOffset       = genRan.Random(0, Mathf.PI);

        float       range    = Mathf.Sqrt(canopy * 0.5f) * 0.8f;
        WorldObject treeBase = WorldObject.CreateWorldObject(this, transform);
        Vec2i       zero     = new Vec2i(0, 0);

        Vector3[] canopyPositions = new Vector3[canopy];

        for (int i = 0; i < canopy; i++)
        {
            //Define the positions of each canopy as roughly circular about the middle of the tree.
            float   angle  = (Mathf.PI * 2 / (canopy)) * i + angleOffset;
            Vector2 delta  = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * range + genRan.RandomVector2(-0.1f, 0.1f);
            float   height = 1.8f + genRan.Random(0, 1f);
            //Store the total position for use later, then generate the canopy itself.
            canopyPositions[i] = new Vector3(delta.x, height, delta.y);
            TreeCanopy tr = new TreeCanopy(zero, canopyPositions[i]);
            tr.SetRandom(genRan);
            tr.CreateWorldObject(treeBase.transform);
        }
        //Generate the trunk

        float      trunkHeight = 1.2f;
        float      trunkScale  = 1.2f;
        TreeBranch trunk       = new TreeBranch(zero);

        trunk.SetCharacteristic(Vector3.zero, new Vector3(0, 0, 0), new Vector3(1, trunkScale, 1));
        WorldObject trunkObj = trunk.CreateWorldObject(treeBase.transform);
        //MeshCollider mc  =trunkObj.gameObject.AddComponent<MeshCollider>();
        //mc.sharedMesh = trunkObj.gameObject.GetComponent<MeshFilter>().mesh;
        Vector3 trunkTop = Vector3.up * trunkHeight * trunkScale; //Scale to correct height

        foreach (Vector3 v in canopyPositions)
        {
            TreeBranch canopyBranch = new TreeBranch(zero);
            //Calculate the Euler angles from the branch base to the canopy
            Vector3 delta_pos = v - trunkTop;
            Quaternion.FromToRotation(Vector3.up, delta_pos);
            //Vector3 rot = Quaternion.FromToRotation(trunkTop, v*5f).eulerAngles;
            Vector3 rot   = Quaternion.FromToRotation(Vector3.up, delta_pos).eulerAngles;
            float   scale = Vector3.Distance(v, trunkTop) / trunkHeight;
            canopyBranch.SetCharacteristic(trunkTop, rot, new Vector3(1 / scale, scale, 1 / scale));
            canopyBranch.CreateWorldObject(treeBase.transform);
        }

        return(treeBase);
    }
    public void Init(ChunkBase2[,] chunks, GridPlacement gp, List <WorldLocation> eventLocations)
    {
        Groups        = new Dictionary <Vec2i, List <EntityGroup> >();
        PathFinder    = new WorldEventPathFinder(chunks);
        GridPlacement = gp;
        ChunkBases    = chunks;

        WorldEventLocations = eventLocations;


        ThreadLock = new Object();
        GenRan     = new GenerationRandom(0);
    }
 public DungeonGenerator(GameGenerator gameGen)
 {
     GameGenerator = gameGen;
     GenRan        = new GenerationRandom(gameGen.Seed);
     BASE_DIRT     = new int[World.ChunkSize, World.ChunkSize];
     for (int x = 0; x < World.ChunkSize; x++)
     {
         for (int z = 0; z < World.ChunkSize; z++)
         {
             BASE_DIRT[x, z] = Tile.DIRT.ID;
         }
     }
 }
    /// <summary>
    /// Defines the bounds of the building to have an L shape.
    ///
    /// </summary>
    /// <param name="genRan">RNG used to generate building</param>
    /// <param name="smith">Building shell to define wall of</param>
    private static void ChooseLShapedWall(GenerationRandom genRan, Blacksmith smith)
    {
        //Define a base rectangular wall
        List <Vec2i> wallPoints = new List <Vec2i>();

        wallPoints.Add(new Vec2i(0, 0));
        wallPoints.Add(new Vec2i(smith.Width - 1, 0));
        wallPoints.Add(new Vec2i(smith.Width - 1, smith.Height - 1));
        wallPoints.Add(new Vec2i(0, smith.Height - 1));



        //Choose which point index we wish to move
        int deltaPointI = genRan.RandomInt(0, wallPoints.Count);
        //We find which direction and amount the point has to move to not leave the bounds
        int   xDir     = (wallPoints[deltaPointI].x == 0 ? 1 : -1) * genRan.RandomInt(smith.Width / 3, smith.Width - smith.Width / 3);
        int   zDir     = (wallPoints[deltaPointI].z == 0 ? 1 : -1) * genRan.RandomInt(smith.Height / 3, smith.Height - smith.Height / 3);
        Vec2i newPoint = new Vec2i(xDir, zDir) + wallPoints[deltaPointI];

        //wallPoints.Insert(deltaPointI-1, newPoint);
        //We find the direction from the previous corner to this one,
        //we use this to translate the point accordingly
        Vec2i nm1_to_n = wallPoints[deltaPointI] - wallPoints[(deltaPointI - 1 + wallPoints.Count) % wallPoints.Count];
        Vec2i np1_to_n = wallPoints[(deltaPointI + 1) % wallPoints.Count] - wallPoints[deltaPointI];

        if (nm1_to_n.x == 0)
        {
            wallPoints[deltaPointI].z = newPoint.z;
        }
        else
        {
            wallPoints[deltaPointI].x = newPoint.x;
        }

        // Vec2i np1_to_n = wallPoints[(deltaPointI + 1) % wallPoints.Count] - wallPoints[deltaPointI];

        Vec2i newPoint2 = new Vec2i(newPoint.x, newPoint.z);

        if (np1_to_n.x == 0)
        {
            newPoint2.x = wallPoints[(deltaPointI + 1) % wallPoints.Count].x;
        }
        else
        {
            newPoint2.z = wallPoints[(deltaPointI + 1) % wallPoints.Count].z;
        }
        wallPoints.Insert((deltaPointI + 1), newPoint);
        wallPoints.Insert((deltaPointI + 2), newPoint2);

        smith.BoundingWall = wallPoints.ToArray();
    }
示例#10
0
 public SettlementBuilder2(HeightFunction heightFunc, SettlementShell shell) : base(shell.ChunkPosition, new Vec2i(1, 1) * shell.Type.GetSize(), heightFunc, shell.ChunkBases)
 {
     Shell = shell;
     Debug.Log(shell + "," + shell.LocationData);
     GenerationRandom = new GenerationRandom(0);
     TileSize         = shell.Type.GetSize() * World.ChunkSize;
     Middle           = new Vec2i(TileSize / 2, TileSize / 2);
     //Tiles = new Tile[TileSize, TileSize];
     //SettlementObjects = new WorldObjectData[TileSize, TileSize];
     Buildings = new List <Building>();
     //PathNodes = new List<Vec2i>();
     BuildingPlots  = new List <Recti>();
     SettlementType = shell.Type;
 }
    // Start is called before the first frame update
    void Start()
    {
        return;

        int maxSize             = 32 * World.ChunkSize;
        GenerationRandom genRan = new GenerationRandom(0);

        for (int i = 0; i < 20; i++)
        {
            Vec2i      pos = genRan.RandomVec2i(maxSize / 2, maxSize);
            GameObject ent = Instantiate(EntityPrefab);
            ent.transform.parent   = transform;
            ent.transform.position = new Vector3(pos.x, 0, pos.z);
        }
    }
示例#12
0
    public static Farm GenerateVegFarm(GenerationRandom genRan, Farm farm, out BuildingVoxels vox, BuildingGenerationPlan plan)
    {
        vox = new BuildingVoxels(farm.Width, World.ChunkHeight, farm.Height);

        Tile[,] tiles = new Tile[farm.Width, farm.Height];
        BuildingGenerator.SetTiles(tiles, 0, 0, farm.Width - 1, farm.Height - 1, Tile.TEST_MAGENTA);

        farm.SetBuilding(tiles);
        BuildingGenerator.BuildBoundingWallRect(vox, farm.Width, farm.Height, 2, Voxel.stone);

        BuildingGenerator.ChooseEntrancePoint(genRan, vox, farm, plan, false);


        return(farm);
    }
    public override Dungeon Generate(DungeonEntrance entr, GenerationRandom ran = null)
    {
        if (ran == null)
        {
            ran = new GenerationRandom(ChunkPosition.x << 16 + ChunkPosition.z);
        }


        ChunkData[,] chunks = CreateChunks();
        Vec2i         dunEntr = ChunkPosition * World.ChunkSize + new Vec2i(World.ChunkSize / 2, World.ChunkSize / 2);
        List <Entity> dunEnt  = GenerateEntities();
        DungeonBoss   dunBoss = GenerateDungeonBoss();


        return(new Dungeon(chunks, new Vec2i(5, 5), dunEntr, dunEnt, dunBoss));
    }
示例#14
0
    public static void ChooseEntrancePoint(GenerationRandom genRan, BuildingVoxels vox, Building build, BuildingGenerationPlan plan, bool requiredSubworld = true)
    {
        Vec2i entranceSide = plan.EntranceSide;

        Vec2i mid  = new Vec2i(build.Width / 2, build.Height / 2);
        Vec2i entr = null;

        //Travel out iterativly till we reach the wall
        for (int r = 0; r < Mathf.Max(build.Width, build.Height); r++)
        {
            Vec2i v = mid + entranceSide * r;
            if (v.x < 0 || v.z < 0 || v.x >= build.Width || v.z >= build.Height)
            {
                break;
            }
            if (vox.GetVoxel(v.x, 1, v.z) != Voxel.none)
            {
                entr = v;
                break;
            }
        }

        if (entr == null)
        {
            entr = new Vec2i(2, 2);
        }
        build.SetEntrancePoint(entr);
        for (int y = 0; y < 4; y++)
        {
            vox.ClearVoxel(entr.x, y, entr.z);
        }
        if (requiredSubworld)
        {
            Door interior = new Door();
            interior.SetRotation(Vector2.Angle(Vector2.up, entranceSide));
            interior.SetPosition(entr);
            build.InternalEntranceObject = interior;
            AddObject(build, vox, interior, true);

            Door external = new Door();
            external.SetPosition(entr);
            external.SetRotation(Vector2.Angle(Vector2.up, entranceSide));

            build.ExternalEntranceObject = external;
            build.AddExternalObject(external);
        }
    }
    public override void Generate(GenerationRandom ran)
    {
        GenRan = ran;
        BuildWallAndEntrance();
        GenerateSubworldCave(new Vec2i(TileSize.x - 10, TileSize.z - 10));
        DEBUG = false;
        EntityFaction bandits = new EntityFaction("Bandits");

        for (int i = 0; i < 10; i++)
        {
            Vector3 pos    = GenRan.RandomVector3(Boundry + 2, Mathf.Min(TileSize.x, TileSize.z) - Boundry - 2);
            Bandit  bandit = new Bandit();
            bandit.SetEntityFaction(bandits);
            bandit.MoveEntity(pos);
            AddEntity(bandit);
        }
    }
示例#16
0
    /// <summary>
    /// Generates the simplest type of house - a shack
    /// A shack is made of either (cobble?) stone or wood,
    /// it consists of only 1 room, with basic objects inside (bed, chair, table)
    /// </summary>
    /// <param name="house"></param>
    /// <param name="vox"></param>
    /// <returns></returns>
    public static House GenerateShack(GenerationRandom genRan, House house, out BuildingVoxels vox, BuildingGenerationPlan plan)
    {
        vox           = new BuildingVoxels(house.Width, World.ChunkHeight, house.Height);
        Tile[,] floor = new Tile[house.Width, house.Height];

        BuildingGenerator.BuildBoundingWallRect(vox, house.Width, house.Height, 6, Voxel.wood);
        //BuildingGenerator.ConnectBoundingWall(vox, house.BoundingWall, Voxel.wood, 5);
        BuildingGenerator.SetTiles(floor, 0, 0, house.Width - 1, house.Height - 1, Tile.STONE_FLOOR);
        house.SetBuilding(floor);

        BuildingGenerator.ChooseEntrancePoint(genRan, vox, house, plan);
        BuildingGenerator.AddWindow(genRan, vox, house, size: genRan.RandomInt(1, 4), autoReattempt: true);
        BuildingGenerator.AddWindow(genRan, vox, house, size: genRan.RandomInt(1, 4), autoReattempt: true);
        BuildingGenerator.AddWindow(genRan, vox, house, size: genRan.RandomInt(1, 4), autoReattempt: false);
        BuildingGenerator.AddWindow(genRan, vox, house, size: genRan.RandomInt(1, 4), autoReattempt: false);
        BuildingGenerator.AddWindow(genRan, vox, house, size: genRan.RandomInt(1, 4), autoReattempt: false);
        house.InsideWallPoints = BuildingGenerator.FindInsideWallBoundryPoints(vox, house);

        /*foreach (Vec2i v in house.InsideWallPoints)
         * {
         *  //house.AddObjectReference(new Chest().SetPosition(v));
         *  WorldObjectData bed = new Bed().SetPosition(v);
         *  bed.SetRotation(Vec2i.Angle(Vec2i.Forward, BuildingGenerator.GetWallPointDirection(house, v)));
         *  if(!house.ObjectIntersects(bed))
         *      house.AddObjectReference(bed);
         * }*/

        BuildingGenerator.PlaceObjectAgainstWall(genRan, new DoubleBed(), 0, vox, house, .3f, distToEntr: 4, attemptsCount: 40);
        BuildingGenerator.PlaceObjectAgainstWall(genRan, new Chest(), 0, vox, house, 0.1f, distToEntr: 3, attemptsCount: 40);

        for (int i = 0; i < house.BoundingWall.Length; i++)
        {
            BuildingGenerator.PlaceObjectAgainstWall(genRan, new WallTorch(), 1.5f, vox, house, 0f, requireWallBacking: true);
        }
        house.AddExternalObject(new BuildingInternalNoWalkFloor(new Vector3(1, 0, 1), new Vector3(house.Width - 2, 5, house.Height - 2)));
        BuildingGenerator.AddRoof(genRan, vox, house, Voxel.thatch);

        BuildingSubworldBuilder b = new BuildingSubworldBuilder(house, vox, plan);

        b.CreateSubworld();
        //ChunkData[,] subChunks = new ChunkData[1, 1];


        return(house);
    }
示例#17
0
    /// <summary>
    /// Starts the main part of the game.
    /// Checks if a game exists to load, and if so loads it.
    /// If not, we generate a game <see cref="GameManager.GenerateGame(int)"/>
    /// If we generate a game, at current we set the players location
    /// </summary>
    void Start()
    {
        Debug.BeginDeepProfile("game_start");
        if (GameToLoad == null || GameToLoad == "none")
        {
            Stopwatch s = new Stopwatch();
            s.Start();
            //UnityEngine.Profiling.CustomSampler gen = UnityEngine.Profiling.CustomSampler.Create("GenSampler");
            int seed = 0;
            Debug.Log("No game to load, generating with seed " + seed);

            GenerateGame(seed);
            PathFinder = new PathFinder(WorldManager.World);
            PathFinder.SetPlayerPosition(PlayerManager.Player.TilePos);

            System.GC.Collect();
            s.Stop();
            Debug.Log("Generation took total time: " + s.ElapsedMilliseconds / 1000f);
            DebugGUI.SetData("genTime", s.ElapsedMilliseconds / 1000f);
        }
        else
        {
            UnityEngine.Profiling.CustomSampler load = UnityEngine.Profiling.CustomSampler.Create("LoadSampler");
            load.Begin();
            GameLoadSave gls   = LoadSave.Load();
            World        world = new World();
            world.LoadWorld(gls);
            EntityManager.Load(gls);
            WorldManager.SetWorld(world);
            Player player = new Player();
            TestSettle = WorldManager.World.GetSettlement(0);
            Vec2i set = TestSettle.Centre;
            //player.SetPosition(new Vector3(set.x * World.ChunkSize, 0, set.z * World.ChunkSize));
            player.SetPosition(new Vector3(World.WorldSize / 2 * World.ChunkSize, 0, World.WorldSize / 2 * World.ChunkSize));
            PlayerManager.SetPlayer(player);

            load.End();
        }
        Debug.EndDeepProfile("game_start");



        RNG = new GenerationRandom(System.DateTime.Now.Millisecond);
    }
示例#18
0
    /// <summary>
    /// Generates a chunk that has no special land features
    /// </summary>
    /// <param name="x"></param>
    /// <param name="z"></param>
    /// <param name="cb"></param>
    /// <returns></returns>
    private ChunkData GenerateSimpleChunk(int x, int z, ChunkBase2 cb)
    {
        if (cb.Biome == ChunkBiome.ocean)
        {
            return(new ChunkData(x, z, (int[, ])OCEAN.Clone(), false));
        }/*
          * if(cb.Biome == ChunkBiome.dessert)
          * {
          * return new ChunkData(x, z, (int[,])EMPTY_DESERT.Clone(), cb.IsLand, 1, (float[,])OCEAN_HEIGHT.Clone());
          * }if(cb.Biome == ChunkBiome.mountain)
          * {
          * return new ChunkData(x, z, (int[,])MOUNTAIN.Clone(), cb.IsLand, 1, (float[,])OCEAN_HEIGHT.Clone());
          *
          * }*/
        int[,] tiles = (int[, ])(cb.Biome == ChunkBiome.dessert ? EMPTY_DESERT.Clone() : cb.Biome == ChunkBiome.mountain ? MOUNTAIN.Clone() : EMPTY_PLAINS.Clone());

        GenerationRandom genRan = new GenerationRandom(Seed + x << 16 + z);

        //if(genRan.Random() > 0.1f)
        //    return new ChunkData(x, z, tiles, cb.IsLand);

        Dictionary <int, WorldObjectData> obs = new Dictionary <int, WorldObjectData>(256);

        float[,] heights = new float[World.ChunkSize, World.ChunkSize];
        for (int i = 0; i < World.ChunkSize; i++)
        {
            for (int j = 0; j < World.ChunkSize; j++)
            {
                if (genRan.Random() < 0.01f)
                {
                    //obs.Add(WorldObject.ObjectPositionHash(i,j), new Tree(new Vec2i(x * World.ChunkSize + i, z * World.ChunkSize + j)));
                }
                else if (genRan.Random() < 0.3f)
                {
                    //obs.Add(WorldObject.ObjectPositionHash(i, j), new Tree(new Vec2i(x * World.ChunkSize + i, z * World.ChunkSize + j)));
                }
                heights[i, j] = GameGen.TerGen.GetWorldHeightAt(x * World.ChunkSize + i, z * World.ChunkSize + j);
            }
        }
        ChunkData cd = new ChunkData(x, z, tiles, true, cb.Height, heightMap: heights);

        return(cd);
    }
    /// <summary>
    /// Defines the building shape to be rectangular, with a rectangular section defining outside,
    /// and another defining inside
    /// </summary>
    /// <param name="genRan"></param>
    /// <param name="smith"></param>
    private static void ChooseHalfCutWall(GenerationRandom genRan, Blacksmith smith)
    {
        //Define a base rectangular wall
        List <Vec2i> wallPoints = new List <Vec2i>();

        wallPoints.Add(new Vec2i(0, 0));
        wallPoints.Add(new Vec2i(smith.Width - 1, 0));
        wallPoints.Add(new Vec2i(smith.Width - 1, smith.Height - 1));
        wallPoints.Add(new Vec2i(0, smith.Height - 1));

        int wallIndex = genRan.RandomInt(0, 4);
        int wp1       = (wallIndex + 1) % 4;

        wallPoints[wallIndex].x = (int)(wallPoints[wallIndex].x * 0.5f);
        wallPoints[wallIndex].z = (int)(wallPoints[wallIndex].z * 0.5f);
        wallPoints[wp1].x       = (int)(wallPoints[wp1].x * 0.5f);
        wallPoints[wp1].z       = (int)(wallPoints[wp1].z * 0.5f);

        smith.BoundingWall = wallPoints.ToArray();
    }
    private void InternalThreadStructureGeneration(ChunkStructure[] toGen)
    {
        //Ensure we have some structures to generate
        if (toGen[0] == null)
        {
            return;
        }

        //Create list to hold generated chunks. Create random (thread safe)
        List <ChunkData> generatedChunks = new List <ChunkData>(40);
        GenerationRandom genRan          = new GenerationRandom(toGen[0].Position.x * 13 + toGen[0].Position.z * 3064);

        //iterate all structures to generate, ignore if null
        foreach (ChunkStructure str in toGen)
        {
            if (str == null)
            {
                continue;
            }
            //If a bandit camp, create a bandit camp builder then generate structure.
            if (str is BanditCamp)
            {
                BanditCampBuilder bcb = new BanditCampBuilder(str as BanditCamp);
                generatedChunks.AddRange(bcb.Generate(genRan));
                str.SetLootChest(bcb.FinalLootChest);
            }
        }
        //Lock for thread safe adding
        lock (GeneratedChunksAddLock)
        {
            //iterate generated threads, add to dictionary
            foreach (ChunkData cd in generatedChunks)
            {
                GeneratedChunks.Add(new Vec2i(cd.X, cd.Z), cd);
            }
        }

        generatedChunks = null;
        genRan          = null;
    }
示例#21
0
    private Settlement GenerateSettlement(SettlementShell ss)
    {
        SettlementBuilder2 builder = new SettlementBuilder2(GameGen.TerGen.GetWorldHeightAt, ss);
        GenerationRandom   genRan  = new GenerationRandom(GameGen.Seed + ss.ChunkPosition.GetHashCode());

        builder.Generate(genRan);


        List <ChunkData> data = builder.ToChunkData();

        lock (ChunkLock)
        {
            foreach (ChunkData cd in data)
            {
                PreGeneratedChunks.Add(cd.Position, cd);
            }
        }

        Settlement set = new Settlement(ss.GetKingdom(), "test set", builder);

        return(set);
    }
    private static void PlaceOutsideObjects(GenerationRandom genRan, Blacksmith smith, BuildingVoxels vox, Vec2i outMin, Vec2i outMax)
    {
        List <WorldObjectData> toPlace = new List <WorldObjectData>(new WorldObjectData[] { new Anvil(), new Anvil() });
        bool isFinished = false;

        while (!isFinished)
        {
            WorldObjectData toPlaceCur = toPlace[0];
            toPlace.RemoveAt(0);
            Vector3 pos = genRan.RandomVector3(outMin.x, outMax.x, 0, 0, outMin.z, outMax.z);
            toPlaceCur.SetPosition(pos);
            while (!BuildingGenerator.AddObject(smith, vox, toPlaceCur))
            {
                pos = genRan.RandomVector3(outMin.x, outMax.x, 0, 0, outMin.z, outMax.z);
                toPlaceCur.SetPosition(pos);
            }
            if (toPlace.Count == 0)
            {
                isFinished = true;
            }
        }
    }
示例#23
0
    public static Building CreateBuilding(GenerationRandom genRan, out BuildingVoxels vox, BuildingGenerationPlan plan)
    {
        Vec2i zero      = new Vec2i(0, 0);
        int   maxWidth  = (plan.DesiredSize == null || plan.DesiredSize == zero) ?Mathf.Min(plan.BuildingPlan.MaxSize, plan.MaxWidth): plan.DesiredSize.x;
        int   maxHeight = (plan.DesiredSize == null || plan.DesiredSize == zero)? Mathf.Min(plan.BuildingPlan.MaxSize, plan.MaxHeight) : plan.DesiredSize.z;
        int   width     = genRan.RandomInt(plan.BuildingPlan.MinSize, maxWidth);
        int   height    = genRan.RandomInt(plan.BuildingPlan.MinSize, maxHeight);

        if (plan.BuildingPlan == Building.BLACKSMITH)
        {
            Blacksmith smith = BlacksmithGenerator.GenerateBlacksmith(genRan, new Blacksmith(width, height), out vox, plan);
            return(smith);
        }
        if (plan.BuildingPlan == Building.BARACKS)
        {
            Barracks barr = BarracksGenerator.GenerateBarracks(genRan, new Barracks(width, height), out vox, plan);
            return(barr);
        }
        if (plan.BuildingPlan == Building.TAVERN)
        {
            return(TavernGenerator.GenerateTavern(genRan, new Tavern(width, height), out vox, plan));
        }
        if (plan.BuildingPlan == Building.VEGFARM)
        {
            Farm farm = FarmGenerator.GenerateVegFarm(genRan, new Farm(width, height), out vox, plan);
            return(farm);
        }
        if (plan.BuildingPlan == Building.WHEATFARM)
        {
            Farm farm = FarmGenerator.GenerateWheatFarm(genRan, new Farm(width, height), out vox, plan);
            return(farm);
        }

        House house = HouseGenerator.GenerateHouse(genRan, new House(width, height), out vox, plan);

        return(house);
        //return GenerateHouse(out vox, width, height);
    }
示例#24
0
    public override WorldObject CreateWorldObject(Transform transform = null)
    {
        WorldObject baseObj = new EmptyObjectBase(WorldPosition, meta: MetaData).CreateWorldObject(transform);
        Vec2i       dir     = new Vec2i(0, 1);

        if (HasMetaData() && GetMetaData().Direction != null)
        {
            dir = GetMetaData().Direction;
        }
        WorldObjectMetaData door1Dir = new WorldObjectMetaData(direction: Vec2i.Rotate(new Vec2i(0, 1), dir));
        WorldObjectMetaData door2Dir = new WorldObjectMetaData(direction: Vec2i.Rotate(new Vec2i(0, -1), dir));

        WorldObject baseDoor   = new WoodDoor(new Vec2i(1, 0), door1Dir, onDoorOpen: OnEntityEnter).CreateWorldObject(baseObj.transform);
        WorldObject secondDoor = new WoodDoor(new Vec2i(3, 0), door2Dir, onDoorOpen: OnEntityEnter).CreateWorldObject(baseObj.transform);

        Vec2i[] rockPos = new Vec2i[] { new Vec2i(0, 0), new Vec2i(0, 1), new Vec2i(0, 2), new Vec2i(0, 3),
                                        new Vec2i(1, 3), new Vec2i(2, 3), new Vec2i(3, 3), new Vec2i(3, 3), new Vec2i(3, 2), new Vec2i(3, 1), new Vec2i(3, 0) };
        GenerationRandom genRan = new GenerationRandom(WorldPosition.x << 16 + WorldPosition.z);

        foreach (Vec2i v in rockPos)
        {
            for (int y = 0; y < 3; y++)
            {
                Rock r = new Rock(v, Vector3.up * y + new Vector3(1, 0, 1) * 0.5f, rockSize: 1.5f);
                r.SetRandom(genRan);
                r.CreateWorldObject(baseObj.transform);
            }
        }
        for (int x = 1; x < 4; x++)
        {
            for (int z = 1; z < 4; z++)
            {
                new Rock(new Vec2i(x, z), new Vector3(0, 2, 0), rockSize: 2).CreateWorldObject(baseObj.transform);
            }
        }

        return(baseObj);
    }
    public void SetEntityGroup(EntityGroup c)
    {
        Button = GetComponent <Button>();
        Text   = GetComponentInChildren <Text>();
        if (c is EntityGroupCaravan)
        {
            SetCaravan(c as EntityGroupCaravan);
        }
        if (c is EntityGroupVillageTrader)
        {
            switch (c.Type)
            {
            case EntityGroup.GroupType.VillageAnimalExport:
                Text.text = "Animal";
                break;

            case EntityGroup.GroupType.VillageFoodExport:
                Text.text = "Food";
                break;

            case EntityGroup.GroupType.VillageOreExport:
                Text.text = "Ore";
                break;

            case EntityGroup.GroupType.VillageWoodExport:
                Text.text = "Wood";
                break;
            }
        }
        ColorBlock b = Button.colors;

        float[] col = new GenerationRandom((int)(Time.time * 2052306)).RandomFloatArray(0, 1, 3);
        b.normalColor = new Color(col[0], col[1], col[2]);
        Button.colors = b;
        Group         = c;
        IsMain        = false;
    }
示例#26
0
    /// <summary>
    /// Generates a chunk that has no special land features
    /// </summary>
    /// <param name="x"></param>
    /// <param name="z"></param>
    /// <param name="cb"></param>
    /// <returns></returns>
    private ChunkData GenerateSimpleChunk(int x, int z, ChunkBase cb)
    {
        if (!cb.IsLand)
        {
            return(new ChunkData(x, z, (int[, ])OCEAN.Clone(), cb.IsLand));
        }
        if (cb.Biome == ChunkBiome.dessert)
        {
            return(new ChunkData(x, z, (int[, ])EMPTY_DESERT.Clone(), cb.IsLand));
        }
        int[,] tiles = (int[, ])EMPTY_PLAINS.Clone();

        GenerationRandom genRan = new GenerationRandom(Seed + x << 16 + z);

        //if(genRan.Random() > 0.1f)
        //    return new ChunkData(x, z, tiles, cb.IsLand);

        Dictionary <int, WorldObjectData> obs = new Dictionary <int, WorldObjectData>(256);

        for (int i = 0; i < World.ChunkSize; i++)
        {
            for (int j = 0; j < World.ChunkSize; j++)
            {
                if (genRan.Random() < 0.01f)
                {
                    obs.Add(WorldObject.ObjectPositionHash(i, j), new Tree(new Vec2i(x * World.ChunkSize + i, z * World.ChunkSize + j)));
                }
                else if (genRan.Random() < 0.3f)
                {
                    //obs.Add(WorldObject.ObjectPositionHash(i, j), new Tree(new Vec2i(x * World.ChunkSize + i, z * World.ChunkSize + j)));
                }
            }
        }
        ChunkData cd = new ChunkData(x, z, tiles, cb.IsLand, obs);

        return(cd);
    }
示例#27
0
    public static Tavern GenerateTavern(GenerationRandom genRan, Tavern tavern, out BuildingVoxels vox, BuildingGenerationPlan plan)
    {
        vox = new BuildingVoxels(tavern.Width, World.ChunkHeight, tavern.Height);
        BuildingGenerator.BuildBoundingWallRect(vox, tavern.Width, tavern.Height, 6, Voxel.wood);
        BuildingGenerator.ChooseEntrancePoint(genRan, vox, tavern, plan);

        Tile[,] tileMap = new Tile[tavern.Width, tavern.Height];

        BuildingGenerator.SetTiles(tileMap, 0, 0, tavern.Width, tavern.Height, Tile.WOOD_FLOOR);
        tavern.SetBuilding(tileMap);
        BuildingGenerator.AddWindow(genRan, vox, tavern, autoReattempt: true);
        BuildingGenerator.AddWindow(genRan, vox, tavern, autoReattempt: true);
        BuildingGenerator.AddWindow(genRan, vox, tavern, autoReattempt: true);
        BuildingGenerator.AddWindow(genRan, vox, tavern, autoReattempt: false);
        BuildingGenerator.AddWindow(genRan, vox, tavern, autoReattempt: false);
        FirePlace fp = new FirePlace();

        BuildingGenerator.PlaceObjectAgainstWall(genRan, fp, 0, vox, tavern, 0, true, 4, true, 20);
        BuildingGenerator.PlaceObjectAgainstWall(genRan, new WallTorch(), 1.5f, vox, tavern, 0, true, 2);
        NPCJob[] jobs = new NPCJob[] { new NPCJobMerchant(tavern, "Tavern Keep"), new NPCJobMerchant(tavern, "Tavern Keep") };
        tavern.SetWorkBuildingData(new WorkBuildingData(jobs));
        BuildingGenerator.AddRoof(genRan, vox, tavern, Voxel.thatch);
        return(tavern);
    }
示例#28
0
 public abstract Dungeon Generate(DungeonEntrance entr, GenerationRandom ran = null);
    public List <ChunkData> Generate(GenerationRandom genRan)
    {
        Vec2i tilebase = Shell.Position * World.ChunkSize;

        if (Shell.BanditCampLevel > 1 && Shell.Size.x > 3 && Shell.Size.z > 3)
        {
            //If this camp is large enough, generate a dungeon entrance.

            Vec2i localPos = new Vec2i(2, TileSize.z / 2 - 2);

            CaveDungeonEntrance entr = new CaveDungeonEntrance(tilebase + localPos, null, new WorldObjectMetaData(direction: new Vec2i(1, 0)));
            IMultiTileObjectChild[,] children = entr.GetChildren();
            Objects[localPos.x, localPos.z]   = entr;
            for (int x = 0; x < entr.Size.x; x++)
            {
                for (int z = 0; z < entr.Size.z; z++)
                {
                    if (x == 0 && z == 0)
                    {
                        continue;
                    }
                    Objects[localPos.x + x, localPos.z + z] = children[x, z] as WorldObjectData;
                }
            }
            Debug.Log("Generated Bandit Camp with Dungeon at " + this.Shell.Position, Debug.CHUNK_STRUCTURE_GENERATION);

            Shell.SetDungeonEntrance(entr);
            entr.SetChunkStructure(Shell);
        }
        else
        {
            Debug.Log("Generated Bandit Camp no Dungeon at " + this.Shell.Position, Debug.CHUNK_STRUCTURE_GENERATION);
        }

        Objects[11, 11] = new LootSack(tilebase + new Vec2i(11, 11));
        FinalLootChest  = Objects[11, 11] as IInventoryObject;

        for (int x = 0; x < TileSize.x; x++)
        {
            for (int z = 0; z < TileSize.z; z++)
            {
                if (x == 0)
                {
                    Objects[x, z] = new WoodSpikeWall(tilebase + new Vec2i(x, z));
                }
                if (z == 0)
                {
                    Objects[x, z] = new WoodSpikeWall(tilebase + new Vec2i(x, z));
                }
                if (x == TileSize.x - 1 && z < TileSize.z / 2 - 2 && z > TileSize.z / 2 + 2)
                {
                    Objects[x, z] = new WoodSpikeWall(tilebase + new Vec2i(x, z));
                }
                if (z == TileSize.z - 1)
                {
                    Objects[x, z] = new WoodSpikeWall(tilebase + new Vec2i(x, z));
                }
                Tiles[x, z] = Tile.DIRT.ID;
            }
        }

        EntityFaction banditFaction = new EntityFaction("Bandit_Camp");

        for (int x = 0; x < Shell.Size.x; x++)
        {
            for (int z = 0; z < Shell.Size.z; z++)
            {
                //Entity e = new Bandit();
                //e.SetPosition(tilebase + new Vec2i(x * World.ChunkSize + 5, z * World.ChunkSize + z + 3));
                //Shell.AddEntity(x, z, e);
                //e.SetEntityFaction(banditFaction);
            }
        }
        Entity e = new Bandit();

        e.SetPosition(tilebase + new Vec2i(2 * World.ChunkSize + 5, 2 * World.ChunkSize + 2 + 3));
        Shell.AddEntity(0, 0, e);
        e.SetEntityFaction(banditFaction);



        return(ToChunkData());
    }
 public ChunkStructureGenerator(GameGenerator gameGen)
 {
     GameGenerator    = gameGen;
     GenerationRandom = new GenerationRandom(gameGen.Seed * 13 + 29535);
 }