public FloorRun(IReadOnlyList <FloorSelection> floors, BaseMarker marker) { Contract.Requires(floors != null); Selection = floors; Marker = marker; }
/// <summary> /// Select multiple runs of floors, ordered top down. Runs are split when the footprint of the floor changes (i.e. on Footprint Markers) /// </summary> /// <param name="random"></param> /// <param name="metadata"></param> /// <param name="finder"></param> /// <param name="selectors"></param> /// <param name="groundMarker"></param> /// <param name="aboveGround"></param> /// <returns></returns> private static IEnumerable <FloorRun> SelectFloors(Func <double> random, INamedDataCollection metadata, Func <KeyValuePair <string, string>[], Type[], ScriptReference> finder, IEnumerable <BaseFloorSelector> selectors, BaseMarker groundMarker, bool aboveGround) { Contract.Requires(random != null); Contract.Requires(metadata != null); Contract.Requires(finder != null); Contract.Requires(selectors != null); Contract.Requires(groundMarker != null); Contract.Ensures(Contract.Result <IEnumerable <FloorRun> >() != null); var runs = new List <FloorRun>(); var previousMarker = groundMarker; var floors = new List <FloorSelection>(); //Selectors, ordered top to bottom foreach (var selector in selectors) { //Runs, ordered top to bottom var r = selector.Select(random, metadata, finder); foreach (var floorRun in r) { floors.AddRange(floorRun.Selection); if (floorRun.Marker != null) { if (aboveGround) { runs.Add(new FloorRun(floors.ToArray(), floorRun.Marker)); floors.Clear(); } else { runs.Add(new FloorRun(floors.ToArray(), previousMarker)); previousMarker = floorRun.Marker; floors.Clear(); } } } } //Sanity check if (aboveGround && floors.Count > 0) { throw new InvalidOperationException("Leftover floors above ground - no ground marker?"); } //Final below ground run (doesn't have a footprint at the bottom, because udnerground floors have footprints above not below) if (!aboveGround && floors.Count > 0) { runs.Add(new FloorRun(floors.ToArray(), previousMarker)); } return(runs); }
public FootprintSelection(BaseMarker marker, int index) { Marker = marker; Index = index; }