예제 #1
0
 public Area(string nameOfArea, AreaBiome setBiome, Vector2 seed)
 {
     name = nameOfArea;
     biome = setBiome;
     structuresInArea = new List<Structure>();
     this.seed = seed;
 }
예제 #2
0
        /// <summary>
        /// This will build a structure that fits within the dimensions
        /// based on the seed passed in.
        /// </summary>
        /// <returns>The structure.</returns>
        /// <param name="dimensions">Dimensions.</param>
        /// <param name="seed">Seed.</param>
        /// <param name="theme">Theme.</param>
        public static GameObject buildStructure(Vector2 dimensions, int seed, AreaBiome theme, float civValue)
        {
            // First we begin by determining how many blocks we can fit in the x and y dimensions
            // plotDimensions is how many modules you can fit in the structure.
            float blockDimension = 3.0f;
            Vector2 plotDimensions = new Vector2( Mathf.FloorToInt( dimensions.x / blockDimension ), Mathf.FloorToInt( dimensions.y / blockDimension ));

            // Create random blueprints
            int[][] blueprints = generateBoringBlueprints (plotDimensions, seed, civValue);

            // If there are no blue prints don't go any further
            if(blueprints == null){
                return null;
            }

            // Build from the blueprints
            GameObject structure = new GameObject ("Structure: "+seed+", "+dimensions.ToString());

            for(int x = 0; x < blueprints.Length; x ++){

                for(int y = 0; y < blueprints[x].Length; y ++){

                    // Get the number of floors wanted from this module's position.
                    int floors = blueprints[x][y];

                    // Move to the next portion if there's nothin to build here.
                    if(floors <= 0){
                        continue;
                    }

                    int[][] wallInformation = wallsModuleIsTouching(blueprints, x, y);

                    // Build a module for each floor
                    for(int f = 0; f < floors; f ++){

                        // Whether or not to create a turret on this floor
                        bool createTurret = false;

                        // Just use a cube for now
                        GameObject module = null;

                        // The number of walls that are touching this floor
                        int numOfWallsTouchingThisFloor = 0;

                        List<int> neighboringWallDirections = new List<int>();

                        // Find the walls touching this floor
                        for(int w = 0; w < wallInformation.Length; w ++){

                            if(wallInformation[w][1]  >= f + 1){

                                numOfWallsTouchingThisFloor ++;
                                neighboringWallDirections.Add(wallInformation[w][0]);

                            }

                        }

                        if(numOfWallsTouchingThisFloor == 0){

                            module = Resources.Load("Structures/Civilization/Basic/0STop") as GameObject;
                            module = GameObject.Instantiate(module);

                        } else if(numOfWallsTouchingThisFloor == 1){

                            if(f == floors-1){
                                module = Resources.Load("Structures/Civilization/Basic/1STop") as GameObject;
                            } else {
                                module = Resources.Load("Structures/Civilization/Basic/1SMid") as GameObject;
                            }

                            module = GameObject.Instantiate(module);

                            // Find the correct rotation.
                            switch(neighboringWallDirections[0]){

                            // East
                            case 0:
                                module.transform.Rotate(new Vector3(0,270,0));
                                break;

                            // West
                            case 1:
                                module.transform.Rotate(new Vector3(0,90,0));
                                break;

                            // North
                            case 2:
                                module.transform.Rotate(new Vector3(0,180,0));
                                break;

                            }

                        } else if(numOfWallsTouchingThisFloor == 2){

                            // Grab the correct type of 2 sided wall
                            string typeOfWall = "I";

                            float chancesOfTurret = .05f;

                            // Don't think about it just roll w/ it
                            int nwd = neighboringWallDirections[0] + neighboringWallDirections[1];
                            if(nwd > 1 && nwd < 5){

                                typeOfWall = "L";

                            }

                            // Instantiate the correct module
                            if(f == floors-1){

                                module = Resources.Load("Structures/Civilization/Basic/2S"+typeOfWall+"Top") as GameObject;

                                if(Random.Range(0f,1f) < chancesOfTurret && typeOfWall == "L"){
                                    createTurret = true;
                                }

                            } else {
                                module = Resources.Load("Structures/Civilization/Basic/2S"+typeOfWall+"Mid") as GameObject;
                            }

                            module = GameObject.Instantiate(module);

                            // Set the correct rotation
                            if(typeOfWall.Equals("I")){

                                if(nwd == 5){
                                    module.transform.Rotate(new Vector3(0,90,0));
                                }

                            } else {

                                if(neighboringWallDirections[0] == 0){

                                    if(neighboringWallDirections[1] == 2){

                                        module.transform.Rotate(new Vector3(0,180,0));

                                    } else {

                                        module.transform.Rotate(new Vector3(0,-90,0));

                                    }

                                } else if( nwd == 3) {

                                    module.transform.Rotate(new Vector3(0,90,0));

                                } else {

                                    module.transform.Rotate(new Vector3(0,-0,0));

                                }

                            }

                        } else if(numOfWallsTouchingThisFloor == 3){

                            if(f == floors-1){
                                module = Resources.Load("Structures/Civilization/Basic/3STop") as GameObject;
                            } else {
                                module = Resources.Load("Structures/Civilization/Basic/3SMid") as GameObject;
                            }

                            module = GameObject.Instantiate(module);

                            // rotate appropriately

                            // find wall it's not touching
                            int direction = 1234;
                            for(int w = 0; w < neighboringWallDirections.Count; w ++){
                                if(neighboringWallDirections[w] == 0){
                                    direction -= 1000;
                                }
                                if(neighboringWallDirections[w] == 1){
                                    direction -= 200;
                                }
                                if(neighboringWallDirections[w] == 2){
                                    direction -= 30;
                                }
                                if(neighboringWallDirections[w] == 3){
                                    direction -= 4;
                                }
                            }

                            switch(direction){

                            case 1000:
                                module.transform.Rotate(new Vector3(0,90,0));
                                break;

                            case 200:
                                module.transform.Rotate(new Vector3(0,-90,0));
                                break;

                            case 30:
                                module.transform.Rotate(new Vector3(0,0,0));
                                break;

                            case 4:
                                module.transform.Rotate(new Vector3(0,180,0));
                                break;

                            }

                        } else if(numOfWallsTouchingThisFloor == 4){

                            if(f == floors-1){
                                module = Resources.Load("Structures/Civilization/Basic/4STop") as GameObject;
                                module = GameObject.Instantiate(module);
                            }

                        } else {

                            module = GameObject.CreatePrimitive(PrimitiveType.Cube);
                            module.transform.localScale = Vector3.one*blockDimension;

                        }

                        if(module != null){

                            // Make sure the cube is apart of the parent
                            module.transform.SetParent(structure.transform);

                            Vector3 positionForModule = (new Vector3(x,f,y))*blockDimension;

                            // Set the appropriate position nd scale
                            module.transform.localPosition = positionForModule;

                            // Spawn a turret
                            if(createTurret){

                                GameObject turret = EliDavis.Characters.Enemy.EnemyFactory.CreateTurret(positionForModule + new Vector3(0, 1.5f, 0));
                                turret.transform.SetParent(module.transform);

                            }

                        }

                    }

                }

            }

            return structure;
        }