/// <summary>
        /// Generates meshes for a cave.
        /// </summary>
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.ArgumentNullException"></exception>
        public static CaveMeshes GenerateCaveMeshes(WallGrid grid, CaveType type, IHeightMap floorHeightMap, IHeightMap ceilingHeightMap)
        {
            var generator = new MeshGenerator();

            generator.Generate(grid, type, floorHeightMap, ceilingHeightMap);
            return(generator.ExtractMeshes());
        }
Exemple #2
0
    private void ActivateCavePiece()
    {
        float topCavePieceX    = _topPool[_caveIndexTopMid].CaveBody.position.x;
        float bottomCavePieceX = _bottomPool[_caveIndexBottomMid].CaveBody.position.x;

        if (_caveEntrance.bIsActive)
        {
            topCavePieceX    = _caveEntrance.CaveBody.position.x;
            bottomCavePieceX = topCavePieceX;
        }
        float CavePieceY = 0f;
        float cavePieceZ = _caveZPos;

        CaveType nextTopCave    = _topPool[_caveIndexTopRight];
        CaveType nextBottomCave = _bottomPool[_caveIndexBottomRight];

        nextTopCave.bIsActive              = true;
        nextTopCave.CaveBody.position      = new Vector3(Toolbox.TileSizeX + topCavePieceX, CavePieceY, cavePieceZ);
        nextTopCave.CaveBody.velocity      = _caveVelocity;
        nextBottomCave.bIsActive           = true;
        nextBottomCave.CaveBody.position   = new Vector3(Toolbox.TileSizeX + bottomCavePieceX, CavePieceY, cavePieceZ);
        nextBottomCave.CaveBody.velocity   = _caveVelocity;
        _topPool[_caveIndexTopRight]       = nextTopCave;
        _bottomPool[_caveIndexBottomRight] = nextBottomCave;
    }
        public Node(int n, GameObject mesh)
        {
            number            = n;
            m_mesh            = mesh;
            position          = mesh.transform.position;
            mass              = mesh.transform.childCount;
            isFloorConnection = DetectFloorConnection();

            //lists
            adjacency = new List <Node>();
            hexsList  = new List <Transform>();
            GetHexes();
            facesList = new List <Transform>();
            GetFaces();
            smallForwardPossibleHoles = new List <Edge>();
            bigForwardPossibleHoles   = new List <Edge>();
            smallDiagPossibleHoles    = new List <Edge>();
            bigDiagPossibleHoles      = new List <Edge>();
            scannedHexsDict           = new Dictionary <Transform, bool>();
            InitializeScannedHexs();
            hexsConnectionDict = new Dictionary <GameObject, GameObject>();
            tunnelList         = new List <GameObject>();
            edgeList           = new List <Edge>();
            tunnelHexDict      = new Dictionary <GameObject, GameObject>();

            m_type = SetCaveType();
            SetCaveName();

            hasTurret = false;
        }
Exemple #4
0
 internal CaveConfiguration()
 {
     caveType      = CaveType.Isometric;
     mapParameters = new MapParameters();
     floorHeight   = new HeightMapProperties(DEFAULT_FLOOR_HEIGHT);
     ceilingHeight = new HeightMapProperties(DEFAULT_CEILING_HEIGHT);
     scale         = DEFAULT_SCALE;
     debugMode     = DEFAULT_DEBUG_MODE;
 }
Exemple #5
0
 public Chunk(CaveType chunkType, int startPos, List <int> heights, List <TerrainObject> terrainFeatures, List <PowerUp> powerUps, List <Mob> mobs)
 {
     this.heights         = heights;
     this.terrainFeatures = terrainFeatures;
     this.powerUps        = powerUps;
     this.mobs            = mobs;
     this.startPos        = startPos + 1;
     this.gameObjects     = new List <Transform>();
 }
Exemple #6
0
    private CaveType GetCaveAttributes(GameObject cave)
    {
        CaveType newCave = new CaveType
        {
            bIsActive = false,
            CaveBody  = cave.GetComponent <Rigidbody2D>()
        };

        return(newCave);
    }
        /// <summary>
        /// Generate the data necessary to produce meshes for a cave. Safe to execute outside the primary thread.
        /// Call ExtractMeshes to build and retrieve the meshes generated by this method.
        /// </summary>
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <param name="grid">Grid specifying walls and floors. Must have length and width at most 200.</param>
        public void Generate(WallGrid grid, CaveType type, IHeightMap floorHeightMap, IHeightMap ceilingHeightMap)
        {
            ValidateInput(grid, floorHeightMap, ceilingHeightMap);
            switch (type)
            {
            case CaveType.Isometric:
                GenerateIsometric(grid, floorHeightMap, ceilingHeightMap);
                break;

            case CaveType.Enclosed:
                GenerateEnclosed(grid, floorHeightMap, ceilingHeightMap);
                break;

            default:
                throw new System.ArgumentException("Unrecognized Cave Type.");
            }
        }
Exemple #8
0
    public Chunk GenerateChunk(Chunk previousChunk, int currentPosition)
    {
        CaveType             caveType       = RollCaveType();
        List <int>           groundHeights  = GenerateHeights(previousChunk);
        List <Mob>           mobs           = new List <Mob>();
        List <PowerUp>       powerUps       = GeneratePowerUps(groundHeights);
        List <TerrainObject> terrainObjects = GenerateTerrainFeatures(groundHeights, caveType);
        Chunk chunk = new Chunk(caveType, currentPosition * chunkSize + 1, groundHeights, terrainObjects, powerUps, mobs);

        if (caveType != CaveType.CAVERN)
        {
            chunk.ceilingHeights = GenerateCeiling(groundHeights, caveType);
        }
        else if (caveType == CaveType.CAVERN)
        {
            chunk.ceilingHeights = GenerateCavern(previousChunk, groundHeights);
        }

        return(chunk);
    }
Exemple #9
0
    public List <int> GenerateCeiling(List <int> groundHeights, CaveType caveType)
    {
        int[] heightRange;
        if (caveType == CaveType.LOW)
        {
            heightRange = new int[] { 6, 10 };
        }
        else if (caveType == CaveType.MID)
        {
            heightRange = new int[] { 9, 15 };
        }
        else
        {
            heightRange = new int[] { 12, 16 };
        }

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

        for (int i = 0; i < chunkSize; i++)
        {
            int heightDifference = 10;
            if (i % 5 == 0)
            {
                heightDifference = Random.Range(heightRange[0], heightRange[1]);
            }
            ceiling.Add(Random.Range(groundHeights[i] - 1, groundHeights[i] + 2) + heightDifference);
        }
        if (caveType == CaveType.MID)
        {
            return(SmoothHeights(ceiling));
        }
        else
        {
            return(ceiling);
        }
    }
Exemple #10
0
 public CaveRegion(CaveType caveType, int erosinLevel, int geologicIndex)
 {
     CaveType      = caveType;
     ErosinLevel   = erosinLevel;
     GeologicIndex = geologicIndex;
 }
Exemple #11
0
 public CaveValue(CaveType type, int lowheight, int highheight)
 {
     this.type       = type;
     this.lowHeight  = lowheight;
     this.highHeight = highheight;
 }
Exemple #12
0
    /*
     * Generate terrain objects such as chasms, fissures, ore, and gold
     */
    public List <TerrainObject> GenerateTerrainFeatures(List <int> heights, CaveType caveType)
    {
        List <TerrainObject> features = new List <TerrainObject>();
        int chasmChance     = 2;
        int fissureChance   = chasmChance + 2;
        int oreChance       = fissureChance + 3;
        int lavaPoolChance  = oreChance + 5;
        int waterPoolChance = lavaPoolChance + 5;
        int waterFallChance = waterPoolChance + 2;

        for (int i = 0; i < chunkSize; i++)
        {
            if (i < heights.Count - 4)
            {
                int roll = Random.Range(0, 100);
                if (roll < chasmChance)
                {
                    features.AddRange(CreateTerrainObject(3, TerrainObject.CHASM));
                    i += 2;
                }
                else if (roll > chasmChance && roll < fissureChance)
                {
                    features.AddRange(CreateTerrainObject(3, TerrainObject.FISSURE));
                    i += 2;
                }
                else if (roll > fissureChance && roll < oreChance)
                {
                    features.AddRange(CreateTerrainObject(2, TerrainObject.ORE));
                    i += 1;
                }
                else if (roll > oreChance && roll < lavaPoolChance && caveType != CaveType.LOW)
                {
                    try
                    {
                        if (heights[i - 1] == heights[i + 4])
                        {
                            for (int j = i; j < i + 4; j++)
                            {
                                heights[j] = heights[i] - 2;
                            }
                            features.Add(TerrainObject.TERRAIN);
                            features.AddRange(CreateTerrainObject(3, TerrainObject.LAVA_POOL));
                            i += 3;
                        }
                        else
                        {
                            features.Add(TerrainObject.TERRAIN);
                        }
                    }
                    catch (System.ArgumentOutOfRangeException)
                    {
                        features.Add(TerrainObject.TERRAIN);
                    }
                }
                else
                {
                    features.Add(TerrainObject.TERRAIN);
                }
            }
            else
            {
                features.Add(TerrainObject.TERRAIN);
            }
        }
        return(features);
    }
        private CaveType SetCaveType()
        {
            //START / GOAL
            foreach (Transform hex in hexsList)
            {
                if (hex.name.Contains("START"))
                {
                    if (isFloorConnection)
                    {
                        return(CaveType.COMBINED);
                    }
                    else
                    {
                        return(CaveType.START);
                    }
                }
            }

            //FLOOR CONNECTION
            if (isFloorConnection)
            {
                int      numConnectedHexs = 0;
                CaveType type             = CaveType.UPDOWN_CONNECTION;//initialize
                foreach (Transform hex in hexsList)
                {
                    if (hex.name.Contains("UpDown"))
                    {
                        type = CaveType.UPDOWN_CONNECTION;
                        numConnectedHexs++;
                    }
                    else if (hex.name.Contains("Trap"))
                    {
                        type = CaveType.TRAP;
                        numConnectedHexs++;
                    }
                }

                if (numConnectedHexs == 1)
                {
                    return(type);
                }
                else
                {
                    //Debug.Log("COMBINED! "  + m_mesh.name + " " + numConnectedHexs);
                    return(CaveType.COMBINED);
                }
            }

            if (mass > 2)                          //big cave
            {
                if (mass > 4)                      //baixo la possibilitat en coves enormes, impossibles de superar.
                {
                    if (Random.Range(0, 100) < 25) //coves enormes de Ygz
                    {
                        return(CaveType.MINE);
                    }
                }
                else
                {
                    if (Random.Range(0, 100) < 15)//coves enormes de Ygz
                    {
                        return(CaveType.MINE);
                    }
                }
            }
            else //small cave
            {
                if (Random.Range(0, 100) < 25)//25%
                {
                    return(CaveType.MINE);
                }
            }

            int x = Random.Range(1, 3); //normals o rocoses

            return((CaveType)x);
        }