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"); }
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); }
private bool isPathable(Cell cell) { CellMark mark = ElevationManager.GetCellMark(cell); if (mark != null) { if (Math.Abs(mark.elevationTier - elevationTier) <= 1) { return(true); } } return(false); }
public static bool TrySetElevation(Cell cell, int elevationTier) { CellMark mark = GetCellMark(cell); bool valid = ValidElevation(elevationTier) && ValidTileForElevation(cell); if (valid) { mark.elevationTier = elevationTier; } return(valid); }
public static bool TryProcessElevationChange(Cell cell, int tierChange) { CellMark mark = GetCellMark(cell); bool valid = ValidElevation(mark.elevationTier + tierChange) && ValidTileForElevation(cell); if (valid) { mark.elevationTier += tierChange; RefreshTerrain(); } return(valid); }
public static void SetupCellMarks() { Reset(); for (int i = 0; i < World.inst.NumLandMasses; i++) { foreach (Cell cell in World.inst.cellsToLandmass[i].data) { if (cell != null) { CellMark mark = new CellMark(cell); cellMarkLookup.Add(GetCellMarkID(cell), mark); } } } Mod.dLog("Cell marking setup"); }
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); } } } } }
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); }
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"); }