コード例 #1
0
ファイル: PathingManager.cs プロジェクト: DaDevFox/KCMods
        public static bool BlockedCompletely(Cell cell)
        {
            bool blocked = false;

            if (cell != null)
            {
                CellMark mark = ElevationManager.GetCellMark(cell);
                if (mark != null)
                {
                    if (mark.blockers.Count == 4)
                    {
                        blocked = true;
                    }
                }

                if (BlockedTilePruner.Pruned)
                {
                    if (BlockedTilePruner.Unreachable.Contains(cell))
                    {
                        blocked = true;
                    }
                }

                if (BlocksForBuilding(cell))
                {
                    blocked = true;
                }
            }
            return(blocked);
        }
コード例 #2
0
        public static void ApplySmoothing()
        {
            Dictionary <Cell, CellData> newData = new Dictionary <Cell, CellData>();

            foreach (Cell cell in cellsData.Keys)
            {
                CellData data = cellsData[cell];
                if (data.valid && cell != null)
                {
                    CellMark mark        = ElevationManager.GetCellMark(cell);
                    float[]  surrounding = GetSurroundingTiles(data);
                    if (mark != null)
                    {
                        List <float> list = new List <float>();
                        foreach (float f in surrounding)
                        {
                            if (f >= 0f)
                            {
                                list.Add(f);
                            }
                        }
                        list.Add(data.yValue);

                        newData.Add(cell, new CellData {
                            valid  = true,
                            yValue = Average(list),
                            cell   = cell
                        });
                    }
                }
            }
            cellsData = newData;

            Mod.helper.Log("Smoothing Applied");
        }
コード例 #3
0
        public static void Generate()
        {
            Mod.Log("--- Generating ---");

            SRand.SetSeed(World.inst.seed);

            generatorSeededState = SRand.value;
            try
            {
                GenerateBase();
                if (doSmoothing)
                {
                    ApplySmoothing();
                }
                Apply();

                ElevationManager.RefreshTerrain();

                BlockedTilePruner.DoRegionSearch(ElevationManager.GetAll());
            }
            catch (Exception ex)
            {
                DebugExt.HandleException(ex);
            }

            Mod.Log("--- Generation Complete ---");
        }
コード例 #4
0
            public CellData GetCardinal(Direction direction)
            {
                Dictionary <Direction, Vector3> dirs = new Dictionary <Direction, Vector3>()
                {
                    { Direction.East, new Vector3(1f, 0f, 0f) },
                    { Direction.South, new Vector3(0f, 0f, 1f) },
                    { Direction.West, new Vector3(-1f, 0f, 0f) },
                    { Direction.North, new Vector3(0f, 0f, -1f) },
                };

                if (dirs.ContainsKey(direction))
                {
                    Cell cardinal = World.inst.GetCellData(cell.Center + dirs[direction]);
                    if (cardinal != null)
                    {
                        string id = ElevationManager.GetCellMarkID(cardinal);
                        if (!string.IsNullOrEmpty(id))
                        {
                            if (cellsData.ContainsKey(id))
                            {
                                return(cellsData[id]);
                            }
                        }
                    }
                }
                return(new CellData()
                {
                    empty = true
                });
            }
コード例 #5
0
 public static int GetTileRegion(Cell cell)
 {
     if (cellsData.ContainsKey(ElevationManager.GetCellMarkID(cell)))
     {
         return(cellsData[ElevationManager.GetCellMarkID(cell)].region);
     }
     return(-1);
 }
コード例 #6
0
 static void Apply()
 {
     foreach (CellData data in cellsData.Values)
     {
         if (data.valid)
         {
             ElevationManager.TrySetElevation(data.cell, Clamp(data.yValue));
         }
     }
 }
コード例 #7
0
ファイル: CellMark.cs プロジェクト: DaDevFox/KCMods
        public void UpdatePathing()
        {
            if (!ElevationManager.ValidTileForElevation(cell))
            {
                return;
            }

            UpdatePathfinderCost();
            UpdateBlockers();
        }
コード例 #8
0
ファイル: CellMark.cs プロジェクト: DaDevFox/KCMods
        private bool isPathable(Cell cell)
        {
            CellMark mark = ElevationManager.GetCellMark(cell);

            if (mark != null)
            {
                if (Math.Abs(mark.elevationTier - elevationTier) <= 1)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #9
0
ファイル: Mod.cs プロジェクト: DaDevFox/KCMods
 static void Postfix()
 {
     try
     {
         Mod.Log("--- Preperation ---");
         ColorManager.Setup();
         ElevationManager.SetupCellMarks();
         Mod.Log("--- Preperation Complete ---");
     }
     catch (Exception ex)
     {
         DebugExt.HandleException(ex);
     }
 }
コード例 #10
0
ファイル: CellMark.cs プロジェクト: DaDevFox/KCMods
        public void UpdateMesh(bool forced = false)
        {
            if (!ElevationManager.ValidTileForElevation(cell))
            {
                return;
            }

            if (mesh != null)
            {
                mesh.UpdateMesh(forced);
            }
            else
            {
                mesh = CellElevationMesh.Make(cell).GetComponent <CellElevationMesh>();
                mesh.UpdateMesh(forced);
            }
        }
コード例 #11
0
 public static void DoTerrainFeatureEffects()
 {
     foreach (TerrainFeature feature in placedFeatures)
     {
         foreach (Cell cell in feature.affected)
         {
             if (ElevationManager.ValidTileForElevation(cell))
             {
                 CellMark mark = ElevationManager.GetCellMark(cell);
                 if (mark != null)
                 {
                     mark.elevationTier = feature.Get(cell);
                 }
             }
         }
     }
 }
コード例 #12
0
ファイル: CellElevationMesh.cs プロジェクト: DaDevFox/KCMods
        public static GameObject Make(Cell cell)
        {
            CellMark mark = ElevationManager.GetCellMark(cell);

            if (mark != null)
            {
                GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);

                CellElevationMesh script = obj.AddComponent <CellElevationMesh>();
                script.cell     = cell;
                script.cellMark = mark;

                obj.transform.SetPositionAndRotation(new Vector3(cell.Center.x, 0f, cell.Center.z), Quaternion.identity);
                obj.transform.SetParent(World.inst.caveContainer.transform, true);

                script.Init();

                return(obj);
            }
            return(null);
        }
コード例 #13
0
        public static void GenerateBase()
        {
            Reset();
            for (int landmass = 0; landmass < World.inst.NumLandMasses; landmass++)
            {
                foreach (Cell cell in World.inst.cellsToLandmass[landmass].data)
                {
                    CellData data = new CellData
                    {
                        valid = false
                    };
                    if (cell != null && ElevationManager.ValidTileForElevation(cell))
                    {
                        try
                        {
                            data.valid = true;
                            data.cell  = cell;
                            float yValue     = 0f;
                            float noiseValue = Mathf.PerlinNoise(cell.x / scale + generatorSeededState, cell.z / scale + generatorSeededState) * amplitude;

                            float weightage = GetFertilityDistanceWeightage(cell);
                            yValue = noiseValue * weightage * (ElevationManager.maxElevation - ElevationManager.minElevation) + ElevationManager.minElevation;

                            data.yValue = yValue;

                            int y = Clamp(yValue);

                            ElevationManager.TrySetElevation(cell, y);

                            cellsData.Add(cell, data);
                        }
                        catch (Exception ex)
                        {
                            DebugExt.HandleException(ex);
                        }
                    }
                }
            }
            Mod.helper.Log("Base Noise Generated");
        }
コード例 #14
0
        public static void TryPlaceTerrainFeatures()
        {
            foreach (TerrainFeature terrainFeature in TerrainFeatures)
            {
                for (int landmass = 0; landmass < World.inst.NumLandMasses; landmass++)
                {
                    for (int place = 0; place < featurePlaceTriesPerLandmass; place++)
                    {
                        Cell rand = World.inst.cellsToLandmass[landmass].data[SRand.Range(0, World.inst.cellsToLandmass[landmass].Count)];

                        if (!ElevationManager.ValidTileForElevation(rand))
                        {
                            return;
                        }

                        if (terrainFeature.TestPlacement(rand))
                        {
                            placedFeatures.Add(terrainFeature.Create(rand));
                        }
                    }
                }
            }
        }
コード例 #15
0
 private static void OnRegenerateButtonClicked()
 {
     ElevationManager.SetupCellMarks();
     MapGenerator.Generate();
 }
コード例 #16
0
        public static void DoRegionSearch(List <CellMark> data)
        {
            Pruned = false;
            regionData.Clear();
            cellsData.Clear();

            List <CellMark> groundLevel = new List <CellMark>();

            for (int landmass = 0; landmass < World.inst.NumLandMasses; landmass++)
            {
                foreach (Cell cell in World.inst.cellsToLandmass[landmass].data)
                {
                    if (cell != null)
                    {
                        CellMark mark = ElevationManager.GetCellMark(cell);
                        if (mark != null)
                        {
                            if (mark.elevationTier == 0)
                            {
                                groundLevel.Add(mark);
                            }
                        }
                    }
                }
            }


            // Preperation
            foreach (CellMark node in data)
            {
                CellData nodeData = new CellData()
                {
                    cell   = node.cell,
                    mark   = node,
                    region = -1
                };

                cellsData.Add(ElevationManager.GetCellMarkID(node.cell), nodeData);
            }



            // First Pass: Assigning all ground-level tiles their own region
            regionData.Add(0, new List <CellData>());
            foreach (CellData node in cellsData.Values)
            {
                if (node.mark.elevationTier == 0)
                {
                    node.region = 0;
                }
            }

            // Second Pass: Iterate on all ground-level nodes.
            foreach (CellData node in cellsData.Values)
            {
                IterateNode(node);
            }

            ReformatRegions();
            MarkPruned();
            Mod.Log("Blocked Regions Pruned");
        }
コード例 #17
0
ファイル: InputManager.cs プロジェクト: DaDevFox/KCMods
        public static void Update()
        {
            Cell selected = GameUI.inst.GetCellSelected();

            if (Settings.debug)
            {
                if (Input.GetKeyDown(Settings.keycode_raise))
                {
                    try
                    {
                        if (ElevationManager.TryProcessElevationChange(selected, 1))
                        {
                            DebugExt.dLog("Elevation raise succesful");
                        }
                    }
                    catch (Exception ex)
                    {
                        DebugExt.HandleException(ex);
                    }
                }
                else if (Input.GetKeyDown(Settings.keycode_lower))
                {
                    try
                    {
                        if (ElevationManager.TryProcessElevationChange(selected, -1))
                        {
                            DebugExt.dLog("Elevation lower succesful");
                        }
                    }
                    catch (Exception ex)
                    {
                        DebugExt.HandleException(ex);
                    }
                }



                if (Input.GetKeyDown(Settings.keycode_sampleCell))
                {
                    string text = "";

                    text += "Cell at " + selected.Center.ToString() + ": ";
                    text += Environment.NewLine;
                    text += "has mark: " + (ElevationManager.GetCellMark(selected) != null).ToString();
                    text += Environment.NewLine;
                    text += (ElevationManager.GetCellMark(selected) != null) ? ("Blockers: " + ElevationManager.GetCellMark(selected).blockers.Count.ToString()) +
                            Environment.NewLine : "";
                    text += BlockedTilePruner.GetTileRegion(selected) != -1 ? BlockedTilePruner.GetTileRegion(selected).ToString() +
                            Environment.NewLine : "";
                    text += BlockedTilePruner.Unreachable.Contains(selected) ? "<color=red> Pruned from pathfinding; unreachable </color>" : "";

                    DebugExt.dLog(text);
                }
                if (Input.GetKeyDown(KeyCode.H))
                {
                    BlockedTilePruner.DoRegionSearch(ElevationManager.GetAll());
                }
            }
            if (Input.GetKeyDown(Settings.keycode_topDownView))
            {
                TopDownModeCamera.ToggleTopDownView();
            }
        }
コード例 #18
0
 public static void Update()
 {
     BakeElevationMap();
     SetTerrainMat();
     ElevationManager.PushMeshUpdate();
 }