Example #1
0
    public static House GenerateShack(House house)
    {
        BuildingGenerator.GenerateWallsFloorAndEntrance(house.Width, house.Height, house.BuildingObjects, house.BuildingTiles, 0, BuildingStyle.wood);
        //BuildingGenerator.AddObject(house.BuildingObjects, WorldObject.BED, 2, 1);

        return(house);
    }
    public void Generate(Vector3[] surroundingPoints) //Should this take in a reference to the surrounding blocks?
    {
        if (generationDone == false && pointsSet == true)
        {
            //Do generation stuff
            Vector3[] origins;
            Vector3   bottomLeftCorner = new Vector3(-blockSize, 0f, -blockSize);
            Vector3   topRightCorner   = new Vector3(blockSize * 2, 0f, blockSize * 2);
            Mesh[]    buildingBases    = VoroniMeshGenerator.GenerateVoroniIslands(pointList, surroundingPoints, bottomLeftCorner, topRightCorner, blockSize, blockSize, roadWidth, out origins);

            for (int i = 0; i < buildingCount; i++)
            {
                //Create 3 new buildings, one for the base layer, one for bottom side of top layer and one for top side of top layer
                BuildingGenerator newBuilding = Instantiate(buildingGeneratorPrefab);
                newBuilding.transform.SetParent(transform);
                newBuilding.SetBaseMesh(buildingBases[i], origins[i]);
                newBuilding.Generate();

                Vector3 elevatedOrigin = origins[i] + (Vector3.up * topLayerElevation); //Reposition origin of mesh to be on the upper layer plane

                newBuilding = Instantiate(buildingGeneratorPrefab);
                newBuilding.transform.SetParent(transform);
                newBuilding.SetBaseMesh(buildingBases[i], elevatedOrigin);
                newBuilding.Generate(true);

                newBuilding = Instantiate(buildingGeneratorPrefab);
                newBuilding.transform.SetParent(transform);
                newBuilding.SetBaseMesh(buildingBases[i], elevatedOrigin);
                newBuilding.Generate();
            }
        }

        generationDone = true;
    }
Example #3
0
    public static Barracks GenerateBarracks(GenerationRandom genRan, Barracks barr, out BuildingVoxels vox, BuildingGenerationPlan plan)
    {
        vox = new BuildingVoxels(barr.Width, World.ChunkHeight, barr.Height);
        ChooseWallBounds(genRan, barr);
        BuildingGenerator.ConnectBoundingWall(vox, barr.BoundingWall, Voxel.stone);
        Tile[,] tileMap = new Tile[barr.Width, barr.Height];
        BuildingGenerator.ChooseEntrancePoint(genRan, vox, barr, plan);
        BuildingGenerator.SetTiles(tileMap, 0, 0, barr.Width / 2, barr.Height - 1, Tile.STONE_FLOOR);
        BuildingGenerator.SetTiles(tileMap, barr.Width / 2, 0, barr.Width / 2 - 1, barr.Height - 1, Tile.DIRT);

        List <NPCJob> jobs = new List <NPCJob>();

        for (int x = 2; x < barr.Height; x += 3)
        {
            Vector3       pos      = new Vector3(barr.Width - 2, 0, x);
            float         rotation = Vec2i.Angle(Vec2i.Forward, BuildingGenerator.GetWallPointDirection(barr, new Vec2i(barr.Width - 2, x)));
            TrainingDummy obj      = new TrainingDummy().SetPosition(pos).SetRotation(rotation) as TrainingDummy;
            if (BuildingGenerator.AddObject(barr, vox, obj))
            {
                jobs.Add(new NPCJobSoldier(barr));
            }
        }



        WorkBuildingData wbd = new WorkBuildingData(jobs.ToArray());

        barr.SetWorkBuildingData(wbd);
        barr.SetBuilding(tileMap);

        return(barr);
    }
    public void LoadBuilding(GameObject spawnPoint, BuildingSettings settings)
    {
        Building b = BuildingGenerator.Generate(settings);

        GetComponent <BuildingRenderer>().Render(b, spawnPoint);
        //Debug.Log(b.ToString());
    }
    public static Blacksmith GenerateBlacksmith(GenerationRandom genRan, Blacksmith smith, out BuildingVoxels vox, BuildingGenerationPlan plan)
    {
        vox = new BuildingVoxels(smith.Width, World.ChunkHeight, smith.Height);
        ChooseWallBounds(genRan, smith);
        BuildingGenerator.ConnectBoundingWall(vox, smith.BoundingWall, Voxel.stone);
        Tile[,] tileMap = new Tile[smith.Width, smith.Height];
        //Make the whole floor stone
        BuildingGenerator.SetTiles(tileMap, 0, 0, smith.Width - 1, smith.Height - 1, Tile.STONE_FLOOR);

        Vec2i outSideMin = null;
        Vec2i outSideMax = null;

        //Find the outdoor part and make the floor dirt
        for (int i = 0; i < smith.BoundingWall.Length; i++)
        {
            Vec2i p = smith.BoundingWall[i];
            //If this boundry point does not lie on any of the edges, then it is indented into the
            //building. This means this point defines the outside region of the building.
            if ((p.x != 0 && p.x != smith.Width - 1) && (p.z != 0 && p.z != smith.Height - 1))
            {
                //We get the 2 neigboring wall points, as these define the outside region
                Vec2i nm1 = smith.BoundingWall[(i - 1 + smith.BoundingWall.Length) % smith.BoundingWall.Length];
                Vec2i np1 = smith.BoundingWall[(i + 1) % smith.BoundingWall.Length];

                int minX = Mathf.Min(p.x, nm1.x, np1.x);
                int minZ = Mathf.Min(p.z, nm1.z, np1.z);
                int maxX = Mathf.Max(p.x, nm1.x, np1.x);
                int maxZ = Mathf.Max(p.z, nm1.z, np1.z);
                BuildingGenerator.SetTiles(tileMap, minX, minZ, maxX - minX, maxZ - minZ, Tile.DIRT);
                outSideMin = new Vec2i(minX, minZ);
                outSideMax = new Vec2i(maxX, maxZ);
                break;
            }
        }
        smith.SetBuilding(tileMap);
        PlaceOutsideObjects(genRan, smith, vox, outSideMin, outSideMax);



        BuildingGenerator.ChooseEntrancePoint(genRan, vox, smith, plan);
        BuildingGenerator.AddWindow(genRan, vox, smith);
        BuildingGenerator.AddWindow(genRan, vox, smith);
        BuildingGenerator.AddWindow(genRan, vox, smith, autoReattempt: false);
        BuildingGenerator.AddWindow(genRan, vox, smith, autoReattempt: false);

        BuildingGenerator.PlaceObjectAgainstWall(genRan, new Chest(), 0, vox, smith, .1f, attemptsCount: 20, distToEntr: 4);
        BuildingGenerator.PlaceObjectAgainstWall(genRan, new WeaponStand(), 0, vox, smith, 0.1f, distToEntr: 4);
        BuildingGenerator.PlaceObjectAgainstWall(genRan, new ArmourStand(), 0, vox, smith, .1f, distToEntr: 4);

        WorkBuildingData wbd = new WorkBuildingData(new NPCJob[] { new NPCJobMerchant(smith), new NPCJobBlackSmith(smith), new NPCJobBlackSmith(smith) });

        smith.SetWorkBuildingData(wbd);

        for (int i = 0; i < 10; i++)
        {
            smith.Inventory.AddItem(new Shirt(new ItemMetaData().SetColor(Color.blue)));
        }

        return(smith);
    }
Example #6
0
    public override void OnInspectorGUI()
    {
        BuildingGenerator buildingGenerator = (BuildingGenerator)target;

        EditorGUILayout.LabelField("Cubes Collected:", buildingGenerator.cubeHouses.Length.ToString());
        EditorGUILayout.LabelField("Cubes Stored:", buildingGenerator.storedCubes.Length.ToString());
        EditorGUILayout.LabelField("Homes Stored:", buildingGenerator.storedHomes.Length.ToString());

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Collect CubeHouses", GUILayout.Width(130f)))
        {
            buildingGenerator.CollectAllCubes();
        }
        if (GUILayout.Button("Clear Selection", GUILayout.Width(130f)))
        {
            buildingGenerator.ClearSelectedCubes();
        }
        GUILayout.EndHorizontal();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Generate Houses", GUILayout.Width(130f)))
        {
            buildingGenerator.ConvertToBuilding();
        }

        if (GUILayout.Button("Destroy Homes", GUILayout.Width(130f)))
        {
            buildingGenerator.DeleteGeneratedHouses();
        }
        GUILayout.EndHorizontal();
        if (GUILayout.Button("Finalize Construction *PERMANENT*", GUILayout.Width(265f)))
        {
            buildingGenerator.FinalizeConstruction();
        }
        base.OnInspectorGUI();
    }
    // Start is called before the first frame update
    void Start()
    {
        Building building = BuildingGenerator.Generate();

        GetComponent <BuildingRenderer>().Render(building);
        Debug.Log(building.ToString());
    }
    private void Start()
    {
        coordGen    = gameObject.GetComponent <CoordinateGenerator>();
        roadGen     = gameObject.GetComponent <RoadGenerator>();
        buildingGen = gameObject.GetComponent <BuildingGenerator>();

        GenerateRoads();
    }
Example #9
0
    void Awake()
    {
        buildingGenerator = FindObjectOfType <BuildingGenerator>();
        Instantiate(audioSetPrefab);

        fireAudioSource      = GameObject.Find("Fire Sound").GetComponent <AudioSource>();
        waterAudioSource     = GameObject.Find("Water Sound").GetComponent <AudioSource>();
        cockroachAudioSource = GameObject.Find("Cockroach Sound").GetComponent <AudioSource>();
    }
Example #10
0
        private static BuildingGenerator GenerateBuilding(int buildingIndex, BuildingGenerator.Config config, out Transform generatedBuild)
        {
            var builds = GameObject.Find("Builds");

            if (builds == null)
            {
                builds = new GameObject("Builds");
            }

            var build = new GameObject("Build");

            build.transform.parent = builds.transform;

            var building = MapGenerator.CityModel.buildings.ElementAt(buildingIndex);
            var height   = BuildingPlanner.Instance.buildHeightCurve.GetBuildHeight(building.GetWeight());

            if (config == City.DefaultBuildConfig)
            {
                City.DefaultBuildConfig.floors = (int)height;
            }
            var generator = new BuildingGenerator();

            {
                generator.SetFacadeConstructor(BuildingPlanner.Instance.proceduralFacadeConstructor);
                generator.SetFacadePlanner(BuildingPlanner.Instance.proceduralFacadePlanner);
                generator.SetRoofConstructor(BuildingPlanner.Instance.proceduralRoofConstructor);
                generator.SetRoofPlanner(BuildingPlanner.Instance.proceduralRoofPlanner);

                var foundationPoints = building.Pol.Edges.Select(x => CityGenerator.SConv.ConvertVector(x));
                var orientation      = Geometry.GetOrientation(foundationPoints.ToList());
                if (orientation == Orientation.CounterClockwise)
                {
                    foundationPoints = foundationPoints.Reverse();
                }
                var foundationList = foundationPoints.ToList();

                generatedBuild = generator.Generate(foundationList, config,
                                                    build.transform);

                var roof   = generatedBuild.GetChild(0);
                var facade = generatedBuild.GetChild(1);

                var roofMesh   = roof.gameObject.GetComponent <MeshFilter>().sharedMesh;
                var facadeMesh = facade.gameObject.GetComponent <MeshFilter>().sharedMesh;

                var roofCollider = roof.gameObject.AddComponent <MeshCollider>();
                roofCollider.sharedMesh = roofMesh;

                var facadeCollider = facade.gameObject.AddComponent <MeshCollider>();
                facadeCollider.sharedMesh = facadeMesh;
            }

            build.transform.position = City.GetBuildingCenter(building);

            return(generator);
        }
Example #11
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        BuildingGenerator buildingGenerator = (BuildingGenerator)target;

        if (GUILayout.Button("Generate a house"))
        {
            buildingGenerator.GeneratePreviewHouse();
        }
    }
        public Transform Generate()
        {
            var generator = new BuildingGenerator();

            generator.SetFacadePlanner(facadePlanner);
            generator.SetFacadeConstructor(facadeConstructor);
            generator.SetRoofPlanner(roofPlanner);
            generator.SetRoofConstructor(roofConstructor);
            return(generator.Generate(foundationPolygon.vertices, config));
        }
        private void Awake()
        {
            var generator = new BuildingGenerator();

            generator.SetFacadePlanner(facadePlanner);
            generator.SetFacadeConstructor(facadeConstructor);
            generator.SetRoofPlanner(roofPlanner);
            generator.SetRoofConstructor(roofConstructor);
            generator.Generate(foundationPolygon.vertices, config, transform);
        }
Example #14
0
    void Start()
    {
        this.mapWidth  = WorldBuilder.CHUNK_SIZE + 1;
        this.mapHeight = WorldBuilder.CHUNK_SIZE + 1;

        terrainGenerator  = GameObject.Find("Level").GetComponent <TerrainGenerator>();
        buildingGenerator = GameObject.Find("Buildings").GetComponent <BuildingGenerator>();

        parentObject = GameObject.Find("CityPoints");
    }
Example #15
0
 // Start is called before the first frame update
 void Start()
 {
     randomNumber      = Random.Range(1, 5);
     buildingGenerator = GetComponentInParent <BuildingGenerator>();
     for (int i = 10; i < buildingGenerator.instantiatedBlocks.Count; i++)
     {
         if (this.gameObject == buildingGenerator.instantiatedBlocks[i])
         {
             InstantiateFractal();
         }
     }
 }
Example #16
0
    public void LoadBuilding()
    {
        settings = settingsArray[Random.Range(0, settingsArray.Length)];
        SetSize(new Vector2Int(width, depth));
        SetHeight(height);
        Building b = BuildingGenerator.Generate(settings);

        GetComponent <BuildingRenderer>().Render(b, spawnPoint);
        explosionSystem.Play();
        currentCoroutine = LoadAnimation();
        StartCoroutine(currentCoroutine);
        //Debug.Log(b.ToString());
    }
Example #17
0
 public void Initialise(BuildingGenerator bg)
 {
     gridGenerator     = bg.gridGenerator;
     edgelength        = gridGenerator.cellSize;
     generationAllowed = true;   //Temporary
     cellCollider      = gridGenerator.getCellCollider();
     mainCam           = Camera.main;
     camTransform      = mainCam.gameObject.transform;
     groundCursor      = GlobalInformation.groundCursor.transform;
     viewDistance      = GlobalInformation.viewDistance;
     buildingGenerator = bg;
     localSeed         = GlobalInformation.hash((int)transform.position.x ^ GlobalInformation.hash(GlobalInformation.worldSeed ^ (int)transform.position.z));
     initialised       = true;
 }
Example #18
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);
    }
Example #19
0
    /// <summary>
    /// Attempts to place generate a building based on <paramref name="bp"/> in the plot specified
    /// </summary>
    /// <param name="bp"></param>
    /// <param name="plot"></param>
    private bool GenBuildingInPlot(BuildingPlan bp, Plot plot)
    {
        Vec2i entrance = GenerationRandom.RandomFromArray(plot.EntranceSides);
        BuildingGenerationPlan bpPlan = new BuildingGenerationPlan()
        {
            BuildingPlan = bp,
            EntranceSide = entrance,
            MaxHeight    = plot.Bounds.Height,
            MaxWidth     = plot.Bounds.Width
        };

        if (bp.MinSize > plot.Bounds.Width || bp.MinSize > plot.Bounds.Height)
        {
            return(false);
        }



        Building b = BuildingGenerator.CreateBuilding(GenerationRandom, out BuildingVoxels vox, bpPlan);

        Vec2i pos = new Vec2i(plot.Bounds.X, plot.Bounds.Y);

        if (entrance.x == -1)
        {
            pos = new Vec2i(plot.Bounds.X, plot.Bounds.Y + GenerationRandom.RandomIntFromSet(0, plot.Bounds.Height - b.Height));
        }
        else if (entrance.x == 1)
        {
            pos = new Vec2i(plot.Bounds.X + (plot.Bounds.Width - b.Width), plot.Bounds.Y + GenerationRandom.RandomIntFromSet(0, plot.Bounds.Height - b.Height));
        }
        else if (entrance.z == -1)
        {
            pos = new Vec2i(plot.Bounds.X + GenerationRandom.RandomIntFromSet(0, plot.Bounds.Width - b.Width), plot.Bounds.Y);
        }
        else if (entrance.z == 1)
        {
            pos = new Vec2i(plot.Bounds.X + GenerationRandom.RandomIntFromSet(0, plot.Bounds.Width - b.Width), plot.Bounds.Y + (plot.Bounds.Height - b.Height));
        }
        Recti r = AddBuilding(b, vox, pos);

        if (r != null)
        {
            BuildingPlots.Add(r);
            return(true);
        }
        return(false);
    }
        public FrmMain()
        {
            InitializeComponent();
            GlobalVariables.Interface_Size = graphicInterface.Size;
            graphicInterface.Size          = GlobalVariables.Interface_Size;

            timer.Tick    += new EventHandler(graphicInterface.OnTick);
            timer.Interval = GlobalVariables.TIMER_INTERVAL;
            TimeManager.Init();
            buildingGenerator = new BuildingGenerator();
            dummyVehicle      = GenerateDummyVehicle(1000);
            dummyPersons      = GenerateDummyPersons(1000);
            busLineGenerator  = new BusLineGenerator(buildingGenerator.CenterZoneTopLeft, buildingGenerator.CenterZoneBottomRight,
                                                     buildingGenerator.PerimeterZoneTopLeft, buildingGenerator.PerimeterZoneBottomRight);

            dummyBus = busLineGenerator.Buses;
            graphicInterface.Generate(dummyPersons, buildingGenerator.Buildings, dummyVehicle, dummyBus);
            SetClockTime();

            // ⚠️
            dummyDataChart = new List <LineSeries>();
            dummyDataChart.Add(new LineSeries {
                Title = "Infecté(s)", Values = new ChartValues <double>()
                {
                    0, 1, 2, 4, 2, 1, 0
                }
            });
            crtChart.SetData(dummyDataChart);

            List <PieSeries> dummyDataPie = new List <PieSeries>();

            dummyDataPie.Add(new PieSeries {
                Title = "Sain(s)", Values = new ChartValues <double>()
                {
                    30
                }
            });
            dummyDataPie.Add(new PieSeries {
                Title = "Infecté(s)", Values = new ChartValues <double>()
                {
                    1
                }
            });
            pieChart.SetData(dummyDataPie);
            // ⚠️
        }
    public override void OnInspectorGUI()
    {
        BuildingGenerator building = target as BuildingGenerator;

        if (DrawDefaultInspector())
        {
            building.GenerateBuilding();
        }
        if (GUILayout.Button("Generate building"))
        {
            building.GenerateBuilding();
        }
        if (GUILayout.Button("Generate randomized building"))
        {
            building.GenerateRandomizedBuilding();
        }
    }
Example #22
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);
    }
        public void Generate(bool randomizeConfig = true)
        {
            if (constantSeed)
            {
                Random.InitState(0);
            }

            if (randomizeConfig)
            {
                GeneratePalette();
                config.palette.wallColor = GetMainColor();
            }

            if (generator == null)
            {
                generator = new BuildingGenerator();
            }

            if (building != null)
            {
                if (Application.isPlaying)
                {
                    Destroy(building);
                }
                else
                {
                    DestroyImmediate(building);
                }
            }
            generator.SetFacadePlanner(facadePlanner);
            generator.SetFacadeConstructor(facadeConstructor);
            generator.SetRoofPlanner(roofPlanner);
            generator.SetRoofConstructor(roofConstructor);
            var foundationPolygon = foundationPolygons[currentPolygon];

            config.roofConfig.type = roofTypes[currentRoofType];
            building = generator.Generate(foundationPolygon.vertices, config).gameObject;

            var   rect           = Geometry.GetRect(foundationPolygon.vertices);
            float platformRadius = Geometry.GetCircumradius(rect) + platformRadiusOffset;
            var   platformDraft  = Platform(platformRadius, platformHeight);

            AssignDraftToMeshFilter(platformDraft, platformMeshFilter, ref platformMesh);
        }
Example #24
0
    public void Regenerate()
    {
        Debug.Log("Regenerating buildings");

        //find all the buildings in the scene

        foreach (GameObject building in GameObject.FindGameObjectsWithTag("Building"))
        {
            buildings.Add(building);
        }



        Debug.Log("There are " + buildings.Count + " buildings.");

        //regenerate blocks in each building
        foreach (GameObject building in buildings)
        {
            BuildingGenerator buildGen = building.GetComponent <BuildingGenerator>();

            //first, remove all blocks from each building
            if (buildGen.temp.Count > 0)
            {
                for (int i = buildGen.temp.Count - 1; i >= 0; i--)
                {
                    GameObject t = buildGen.temp[i];
                    buildGen.temp.RemoveAt(i);
                    Destroy(t);
                }
            }


            //then generate new blocks for each building
            buildGen.StartCoroutine("Generate");

            //activate car lanes
            foreach (GameObject carLane in GameObject.FindGameObjectsWithTag("CarLane"))
            {
                carLanes.Add(carLane);
                carLane.GetComponent <CarLane>().spawnActive = true;
                carLane.GetComponent <CarLane>().StartCoroutine("Spawner");
            }
        }
    }
Example #25
0
    void GenerateBuilding(int x, int z)
    {
        BuildingGenerator building = GetComponent <BuildingGenerator>();

        building.GenerateRandomizedBuilding();

        string buildingName = "Building: " + buildingCounter;

        GameObject.Find("Building").name = buildingName;

        SetPositionOfBuilding(buildingName, x, z);
        try {
            buildings[buildingCounter] = building;
        } catch (IndexOutOfRangeException) {
            Debug.LogError("Not enough buildings");
        }

        buildingCounter++;
    }
Example #26
0
    private void attemptPlaceHouses(Edge e)
    {
        //we try to place a house on both sides of the edge
        Vector2 edgeMiddle    = Vector2.Lerp(e.n1.pos, e.n2.pos, 0.5f);
        float   edgePop       = CoordinateHelper.worldToPop(edgeMiddle.x, edgeMiddle.y);
        float   edgeLength    = (e.n2.pos - e.n1.pos).magnitude;
        Vector2 edgeDirection = e.n2.pos - e.n1.pos;
        Vector2 edgePerpen    = new Vector2(edgeDirection.y, -edgeDirection.x);

        //make sure we place houses only in low pop areas
        if (edgePop < CityGenerator.skyscraperPopThreshold)
        {
            //two iterations (both sides of road), we have -1 and 1 for i
            for (int i = -1; i <= 1; i += 2)
            {
                float   width      = Mathf.Min(Random.Range(0.65f * edgeLength, 0.87f * edgeLength), CityGenerator.maxHouseWidth);
                float   depth      = Random.Range(width / 2.5f, width);
                int     nrOfFloors = (edgePop < (CityGenerator.skyscraperPopThreshold / 2)) ? 1 : 2;
                Vector2 position   = edgeMiddle + (i * edgePerpen.normalized * ((depth / 2) + (CityGenerator.streetWidth / 2) + 4));
                Vector2 direction  = -i * edgePerpen.normalized;

                int layerMask1 = 1 << LayerMask.NameToLayer("Edge");
                int layerMask2 = 1 << LayerMask.NameToLayer("Building");
                int layerMask  = layerMask1 | layerMask2;                       //or operator

                Vector3 halfExtends = new Vector3((depth / 2) - 1, (nrOfFloors * CityGenerator.floorHeight) / 2, (width / 2) - 1);
                Vector3 position3D  = new Vector3(position.x, CoordinateHelper.worldToTerrainHeight(position), position.y);

                // not underwater
                if (position3D.y < 0)
                {
                    continue;
                }
                Vector3 edgeMiddle3D = position3D - new Vector3(edgeMiddle.x, position3D.y, edgeMiddle.y);

                if (!Physics.CheckBox(position3D, halfExtends, Quaternion.LookRotation(edgeMiddle3D, Vector3.up), layerMask))
                {
                    //place the house
                    BuildingGenerator.generateHouse(position, direction, width, depth, nrOfFloors);
                }
            }
        }
    }
        public void Generate()
        {
            targetPalette = RandomE.TetradicPalette(0.25f, 0.75f);
            targetPalette.Add(ColorHSV.Lerp(targetPalette[2], targetPalette[3], 0.5f));

            var buildingDraft = BuildingGenerator.BuildingDraft(width, length, floorCount, hasAttic,
                                                                targetPalette[0].WithS(0.8f).WithV(0.8f).ToColor());

            var buildingMesh = buildingDraft.ToMesh();

            buildingMesh.RecalculateBounds();
            buildingMeshFilter.mesh = buildingMesh;

            float buildingRadius = Mathf.Sqrt(length / 2f * length / 2f + width / 2f * width / 2f);
            float platformRadius = buildingRadius + platformRadiusOffset;

            var platformMesh = Platform(platformRadius, platformBaseOffset, platformSegments, platformHeight).ToMesh();

            platformMesh.RecalculateBounds();
            platformMeshFilter.mesh = platformMesh;
        }
Example #28
0
 private void PlaceBuildings(List <BuildingPlan> buildings)
 {
     foreach (BuildingPlan bp in buildings)
     {
         Building b = BuildingGenerator.CreateBuilding(bp);
         Recti    r = null;
         int      i = 0;
         while (r == null && i < 5)
         {
             r = AddBuilding(b);
             i++;
         }
         if (r == null)
         {
             continue;
         }
         this.Buildings.Add(b);
         //SurroundByPath(r.X, r.Y, r.Width, r.Height, 2);
         SettlementPathNode[] nodes = AddPlot(r);
     }
 }
        private void Awake()
        {
            var generator = new BuildingGenerator();

            generator.SetFacadePlanner(facadePlanner);
            generator.SetFacadeConstructor(facadeConstructor);
            generator.SetRoofPlanner(roofPlanner);
            generator.SetRoofConstructor(roofConstructor);

            float xOffset = (xCount - 1) * 0.5f * cellSize;
            float zOffset = (zCount - 1) * 0.5f * cellSize;

            for (int z = 0; z < zCount; z++)
            {
                for (int x = 0; x < xCount; x++)
                {
                    config.roofConfig.type = RandomE.GetRandom(RoofType.Flat, RoofType.Hipped, RoofType.Gabled);
                    var building = generator.Generate(foundationPolygon.vertices, config);
                    building.position = new Vector3(x * cellSize - xOffset, 0, z * cellSize - zOffset);
                }
            }
        }
    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;
            }
        }
    }