/// <summary> /// Calculates the next affected grid vertices. /// </summary> /// <param name="source">The current flooded grid vertex.</param> public void Flood(GridVertex source, int currentSteps) { if (Range - currentSteps <= 0) { return; } Game game = Unit.Engine3D.Source as Game; foreach (GridVertex target in source.Adjacent()) { if (target.IsInsideBoundaries(game.Terrain.Size)) { double h = Math.Abs(game.Terrain.HeightMap[target.U, target.V] - game.Terrain.HeightMap[source.U, source.V]); if (h <= Unit.Stability) { if (!AffectedPaths.ContainsKey(target)) { AffectedPaths.Add(target, source); Flood(target, currentSteps + 1); } else if (currentSteps < TraceSteps(target)) { AffectedPaths.Remove(target); AffectedPaths.Add(target, source); Flood(target, currentSteps + 1); } } } } }
/// <summary> /// The grid faces occupied by this unit. /// </summary> /// <returns></returns> public HashSet <GridFace> OccupiedFaces(int size, GridVertex pos) { switch (size) { case 1: return(pos.Touches()); case 2: HashSet <GridFace> faces = new HashSet <GridFace>(); foreach (GridVertex vert in pos.Adjacent()) { faces.UnionWith(vert.Touches()); } return(faces); default: return(null); } }