Exemplo n.º 1
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");
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        private bool isPathable(Cell cell)
        {
            CellMark mark = ElevationManager.GetCellMark(cell);

            if (mark != null)
            {
                if (Math.Abs(mark.elevationTier - elevationTier) <= 1)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 4
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);
                 }
             }
         }
     }
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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();
            }
        }
Exemplo n.º 7
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");
        }