public static Structure createStructure(StructureType structure, Area area, Vector3 position, float civValue)
        {
            GameObject obj = buildStructure (structureDimensions (structure), area.getFlatSeed() + area.getStructuresInArea().Length, area.getBiome (), civValue);
            obj.transform.position = position;

            return new Structure(structure, obj, area);
        }
Example #2
0
 public Structure(StructureType structureType, GameObject structureObject,Area areaStructureLocatedIn)
 {
     type = structureType;
     structureInRealSpace = structureObject;
     areaLocatedIn = areaStructureLocatedIn;
 }
        /// <summary>
        /// Generates terrain and the buildings that occupy the terrain.
        /// </summary>
        /// <param name="sectionsInXDirection">Sections in X direction.</param>
        /// <param name="sectionsInYDirection">Sections in Y direction.</param>
        /// <param name="border">Border of sections passed in.  if you pass in 10*10 sections
        /// and a border of 2, your final result will be a 14*14
        /// </param>
        void CreateArea(int sectionsInXDirection, int sectionsInYDirection, int border)
        {
            // Clear what we have defined as 'free area', array of area that AI can move through
            freeArea.Clear ();

            // Choose the maps dimensions
            int mapHeight = 1025;
            int mapWidth = 1025;

            // Create a seed for our generation, useful for generating the same map over and over if we so choose to
            Vector2 civSeed = new Vector2 (Random.Range (0, 10000), Random.Range (0, 10000));

            // Produce a civilization map, with alpha being civilization
            Texture2D civMap = MapGen.GetInstance ().CreateMap (mapWidth, mapHeight, (int)civSeed.x, (int)civSeed.y);
            civMap = MapGen.GetInstance ().SmoothEdges (civMap);
            guiMapRenderOne = civMap;//for guiPurposes.

            // Create our terrain object and position and scale it correctely
            GameObject terrain = GameObject.CreatePrimitive(PrimitiveType.Plane);
            terrain.transform.position = new Vector3 ( (dimensionOfSection*(sectionsInXDirection))/2, 0, (dimensionOfSection*(sectionsInYDirection))/2);
            terrain.transform.Rotate (new Vector3 (0, 180, 0));
            terrain.transform.localScale = new Vector3 ( (dimensionOfSection*(sectionsInXDirection))/10, 1, (dimensionOfSection*(sectionsInYDirection))/10);

            // Set the material on the terrain that will make it look like terain
            Material material = new Material(Shader.Find("MyShaders/TerrainTwoLayer"));

            // Set the texture on the terrain that will represent civilization
            material.SetTexture ("_MainTex", civArea);
            material.SetTextureScale ("_MainTex", new Vector2(70,70));

            // Set the texture on the terrain that will represent the wild.
            material.SetTexture ("_PathTex", uncivArea);
            material.SetTextureScale ("_PathTex", new Vector2(70,70));

            // Set the alpha that determines whether or not to render the wild or the civilization texture.
            material.SetTexture ("_PathMask", civMap);

            // Set the material to the terrain
            terrain.GetComponent<Renderer> ().material = material;

            // Create the area object
            currentArea = new Area ("Civ Seed: "+civSeed.ToString(), AreaBiome.Test, civSeed);

            // Create structures by splitting up the civilization map into multiple sections to be generated.
            for (int curXSec = 0; curXSec < sectionsInXDirection; curXSec++) {

                for (int curYSec = 0; curYSec < sectionsInYDirection; curYSec++) {

                    int sectionMapWidth = mapWidth / sectionsInXDirection;
                    int sectionMapHeight = mapHeight / sectionsInYDirection;

                    Texture2D sectionMap = new Texture2D (sectionMapWidth, sectionMapHeight);

                    sectionMap.SetPixels (civMap.GetPixels (curXSec * sectionMapWidth,
                                                            curYSec * sectionMapHeight,
                                                            sectionMapWidth, sectionMapHeight));

                    sectionMap.Apply ();

                    createSection (curXSec, curYSec, sectionMap);

                }

            }

            // Spawn trees to make things look more full
            spawnUncivilizedObjects (sectionsInXDirection, sectionsInYDirection, civMap);
        }