public override string ToString() { var nL = Environment.NewLine + " "; var desc = ForbiddenZones.Aggregate("These system zones contain: ", (current, o) => current + (nL + "" + o)); return(FormationZones.Aggregate(desc, (current, o) => current + (nL + "" + o))); }
//check range width public double GetRangeWidth(double orbit) { foreach (var o in FormationZones.Where(o => o.WithinRange(orbit))) { return(o.Length); } return((from o in ForbiddenZones where o.WithinRange(orbit) select o.Length).FirstOrDefault()); }
public int GetOwnership(double orbital) { foreach (var o in FormationZones.Where(o => o.WithinRange(orbital))) { return(o.OrbitDesc); } return(-9999); //INVALID DATA. }
public bool IsWithinCleanZone(double orbit) { if (FormationZones.Any(o => o.WithinRange(orbit))) { return(true); } //Epistellar check. return(orbit < CreationRange.LowerBound && !IsWithinForbiddenZone(orbit)); }
//gets the range for this public Range GetRange(double orbit) { foreach (var o in FormationZones.Where(o => o.WithinRange(orbit))) { return(new Range(o.LowerBound, o.UpperBound)); } foreach (var o in ForbiddenZones.Where(o => o.WithinRange(orbit))) { return(new Range(o.LowerBound, o.UpperBound)); } return(new Range(0, 0)); }
public void CreateCleanZones(Range fullCreationRange) { UpdateCreationRange(fullCreationRange); var currentPos = CreationRange.LowerBound; //default values var ownershipFlag = StarId; var orbitDesc = StarId; if (ForbiddenZones.Count == 0) { FormationZones.Add(new CleanZone(CreationRange, StarId, StarId)); return; } foreach (var o in ForbiddenZones) { if (currentPos < o.LowerBound && CreationRange.UpperBound <= o.LowerBound) { //CASE 1: Both the current position and outer radius are before the forbidden zone // This clean zone is from currentPos to the outer radius. Is the end of our generation FormationZones.Add(new CleanZone(currentPos, CreationRange.UpperBound, StarId, StarId)); return; } if (currentPos < o.LowerBound && CreationRange.UpperBound > o.UpperBound) { //CASE 2: The current position is below the forbidden zone, and the outer radius is beyond it // This clean zone is from current position to the lower bound of the forbidden zone // We then move the pointer to the end of the higher bound. FormationZones.Add(new CleanZone(currentPos, o.LowerBound, ownershipFlag, orbitDesc)); if (o.PrimaryStar != StarId) { return; //return now if you lose primary status. } ownershipFlag = o.PrimaryStar; orbitDesc = GetNewOrbitDesc(orbitDesc, o.PrimaryStar, o.SecondaryStar); //OwnershipFlag = 99; currentPos = o.UpperBound; } if (currentPos < o.LowerBound && o.LowerBound < CreationRange.UpperBound && CreationRange.UpperBound <= o.UpperBound) { //CASE 3: The current position is below the forbidden zone, and the outer radius is within it. // The clean zone is from the current position to the lower bound of the forbidden zone // We then return, no more clear zones. FormationZones.Add(new CleanZone(currentPos, o.LowerBound, ownershipFlag, orbitDesc)); return; } if (!(currentPos >= o.LowerBound) || !(o.UpperBound < CreationRange.UpperBound)) { continue; } //CASE 4: The current position is within a forbidden zone, and the outer radius is beyond it. //Move forward the pointers, but don't add a clean zone currentPos = o.UpperBound; ownershipFlag = o.PrimaryStar; orbitDesc = GetNewOrbitDesc(orbitDesc, o.PrimaryStar, o.SecondaryStar); //OwnershipFlag = 99; } if (!(currentPos < CreationRange.UpperBound)) { return; } // CASE 5: current position is under the upperBound. Add it, and return. FormationZones.Add(new CleanZone(currentPos, CreationRange.UpperBound, ownershipFlag, orbitDesc)); }
public void SortCleanZones() { FormationZones.Sort((x, y) => x.LowerBound.CompareTo(y.LowerBound)); }
//check -range- function. public double VerifyRange(Range checkRange) { double rangeAvail = 1; var currentPos = checkRange.LowerBound; //escape hatch for this condition if (ForbiddenZones.Count == 0) { return(1); } //Which is.. wat? Still, fixed. if (FormationZones.Any(o => checkRange.LowerBound >= o.LowerBound && checkRange.UpperBound <= o.UpperBound)) { return(1); } foreach (var o in ForbiddenZones) { //CASE 1: The forbidden zone is between here and the end if ((currentPos < checkRange.UpperBound) && (currentPos < o.LowerBound) && (o.UpperBound <= checkRange.UpperBound)) { rangeAvail = rangeAvail - (o.UpperBound - o.LowerBound) / checkRange.Length; if (Math.Abs(rangeAvail) < 0) { return(rangeAvail); } currentPos = o.UpperBound; } //CASE 2: This is within a forbidden zone if ((checkRange.LowerBound >= o.LowerBound) && (checkRange.UpperBound <= o.UpperBound)) { return(0); } //CASE 3: Current Position is within a forbidden zone and it cotnains the end. if ((currentPos < checkRange.UpperBound) && (currentPos > o.LowerBound) && (checkRange.UpperBound <= o.UpperBound)) { rangeAvail = rangeAvail - (o.UpperBound - currentPos) / checkRange.Length; if (Math.Abs(rangeAvail) < 0) { return(rangeAvail); } currentPos = checkRange.UpperBound; } //CASE 4: Current Position is within a forbidden zone and it does not contain the end. if ((currentPos < checkRange.UpperBound) && (currentPos > o.LowerBound) && (checkRange.UpperBound > o.UpperBound)) { rangeAvail = rangeAvail - (o.UpperBound - currentPos) / checkRange.Length; if (rangeAvail == 0) { return(rangeAvail); } currentPos = o.UpperBound; } //CASE 5: The end is within a forbidden zone but the current position is not if (!(currentPos < checkRange.UpperBound) || !(currentPos < o.LowerBound) || !(checkRange.UpperBound >= o.LowerBound) || !(checkRange.UpperBound < o.UpperBound)) { continue; } rangeAvail = rangeAvail - (checkRange.UpperBound - o.LowerBound) / checkRange.Length; if (rangeAvail == 0) { return(rangeAvail); } currentPos = checkRange.UpperBound; //CASE 6: No IF condition if the forbidden zone is entirely to the left or right. } if (rangeAvail >= 0 && rangeAvail <= 1) { return(rangeAvail); } throw new Exception("RangeAvail is " + rangeAvail + " and exceeds 0-100%."); }