Пример #1
0
 private void OnTriggerEnter(Collider other)
 {
     //Debug.Log("digger hit " + other.gameObject.name);
     if (other.gameObject.name.Contains("voxel") || other.gameObject.name.Contains("Voxel"))
     {
         CaveEntrance test = master as CaveEntrance;
         //if ( other.gameObject.GetComponent<Voxel>().layer>0)
         if ((test != null) || other.gameObject.GetComponent <Voxel>().layer > 1)
         {//only cave entrances can destroy surface level voxels
             Voxel v = other.gameObject.GetComponent <Voxel>();
             if ((CaveManager.manager.caveWalls == null || CaveManager.manager.caveFloors == null || CaveManager.manager.caveCeilings == null) || (!(CaveManager.manager.caveWalls.Contains(v) || CaveManager.manager.caveFloors.Contains(v) || CaveManager.manager.caveCeilings.Contains(v))) || master is CaveTunnel)
             {//cave body cannot destroy existing cave components but tunnels can
                 var hit = other.gameObject;
                 hitObject(hit);
             }
         }
     }
 }
Пример #2
0
    public static void digTierZeroCaves()
    {
        try
        {
            //new UIMessage("digging caves 1/2", 3f);
            NetworkMessagePasser.singleton.addSyncUIMessage("digging caves 1/2", true, 5);
        }
        catch { }

        float estimatedEntranceDistance = 0.5f * MapManager.mapSize / (float)Math.Pow(2, MapManager.splits);

        rand = new System.Random();
        //Debug.Log("cave manager digging caves");
        shatters = MapManager.manager.shatters;
        MapManager.manager.shatters = 0;
        for (int i = 0; i < MapManager.noSurfaceCaves; i++)
        {
            CaveEntrance entrance  = new CaveEntrance();
            int          colID     = rand.Next(0, MapManager.manager.voxels[0].Count - 1);
            bool         farEnough = false;

            int remainingTries = 100;

            while (!farEnough && remainingTries > 0)
            {
                farEnough = true;
                foreach (CaveEntrance ent in entrances)
                {//checks if proposed position of new cave entrance is too close to any existing cave entrance or an estimated position of a cave body
                    if (Vector3.Distance(MapManager.manager.getPositionOf(0, colID), MapManager.manager.getPositionOf(0, ent.columnID)) < 160 ||
                        Vector3.Distance(MapManager.manager.getPositionOf(0, colID), MapManager.manager.getPositionOf(0, ent.columnID) + ent.direction.normalized * estimatedEntranceDistance * 0.7f) < 130
                        )
                    {
                        farEnough = false;
                        //Debug.Log("found another entrance too close: " + dist);
                    }
                }
                if (farEnough)//the new cave entrance is far enough away from all other cave entrances
                {
                    Vector3 dir           = Vector3.zero;
                    int     dropOffFactor = 100;

                    int count = 0; //number of other cave entrances there are
                    foreach (CaveEntrance ent in entrances)
                    {              //points the dir of the new cave entrance away from nearby entrances and cave bodies
                        Vector3 estimatedCavePosition = MapManager.manager.getPositionOf(0, ent.columnID) + ent.direction.normalized * estimatedEntranceDistance * 0.7f;
                        float   dist = Vector3.Distance(MapManager.manager.getPositionOf(0, colID), estimatedCavePosition);

                        dir += 0.5f * (MapManager.manager.getPositionOf(0, colID) - estimatedCavePosition).normalized / (float)Math.Pow(Vector3.Distance(MapManager.manager.getPositionOf(0, colID), estimatedCavePosition) / dropOffFactor, 2);                                                  //the closer the cave body the more repelling effect it has
                        dir += (MapManager.manager.getPositionOf(0, colID) - MapManager.manager.getPositionOf(0, ent.columnID)).normalized / (float)Math.Pow(Vector3.Distance(MapManager.manager.getPositionOf(0, colID), MapManager.manager.getPositionOf(0, ent.columnID)) / dropOffFactor, 2); //the closer the cave body the more repelling effect it has

                        //Debug.Log("adding " + 0.5f * (MapManager.manager.getPositionOf(0, colID) - estimatedCavePosition).normalized+  " divided by "+ (float)Math.Pow(Vector3.Distance(MapManager.manager.getPositionOf(0, colID), estimatedCavePosition) / dropOffFactor, 2));
                        //Debug.Log("and " + (MapManager.manager.getPositionOf(0, colID) - MapManager.manager.getPositionOf(0, ent.columnID)).normalized + " divided by " + (float)Math.Pow(Vector3.Distance(MapManager.manager.getPositionOf(0, colID), MapManager.manager.getPositionOf(0, ent.columnID)) / dropOffFactor, 2));
                        count++;
                    }
                    if (dir.magnitude != 1 && count > 0)
                    {
                        //Debug.LogError("created dir with mag !=1 : " + dir);
                    }
                    dir = planariseDir(colID, dir);
                    if (dir.magnitude != 1 && count > 0)
                    {
                        //Debug.LogError("created planarised dir with mag !=1 : " + dir);
                    }
                    //dir is now a direction which is pointing away from all other


                    foreach (CaveEntrance ent in entrances)
                    {
                        double dist = Vector3.Distance(MapManager.manager.getPositionOf(0, colID), MapManager.manager.getPositionOf(0, ent.columnID));
                        if (Vector3.Distance(MapManager.manager.getPositionOf(0, ent.columnID), MapManager.manager.getPositionOf(0, colID) + dir.normalized * estimatedEntranceDistance) < 110)
                        {//the projected destination of this cave entrance is too close to another cave entrance
                            farEnough = false;
                        }
                    }

                    //dir = planariseDir(colID, dir);
                    if (farEnough)
                    {
                        if (count > 0)
                        {
                            //Debug.Log("creating cave entrance with direction dervied from surrounding cave bodies");
                            entrance.createEntranceAt(colID, dir);
                        }
                        else
                        {//this is the first cave entrance
                            entrance.createEntranceAt(colID);
                        }
                    }
                    else
                    {
                        remainingTries--;
                    }
                }
                else
                {
                    colID = rand.Next(0, MapManager.manager.voxels[0].Count - 1);
                    remainingTries--;
                }
            }
            if (remainingTries == 0)
            {
                Debug.LogError("cave manager failed to place a cave entrance");
            }
        }
    }