Exemple #1
0
        public IEnumerable <IEnumerable <FloorSelection> > Select(BaseFloorSelector selector, Func <double> random, INamedDataCollection metadata, Func <KeyValuePair <string, string>[], Type[], ScriptReference> finder)
        {
            Contract.Requires(selector != null);
            Contract.Requires(random != null);
            Contract.Requires(metadata != null);
            Contract.Requires(finder != null);
            Contract.Ensures(Contract.Result <IEnumerable <IEnumerable <FloorSelection> > >() != null);

            //How many items to emit?
            var amount = _count.SelectIntValue(random, metadata);

            //Result to emit
            var emit = new List <List <FloorSelection> >();

            //Create a selection function which either always returns the same value or doesn't, depending upon Vary
            Func <FloorSelection> selectFloor;

            if (Vary)
            {
                selectFloor = () => SelectSingle(selector, random, _tags, finder, Height.SelectFloatValue(random, metadata), Id);
            }
            else
            {
                var node = SelectSingle(selector, random, _tags, finder, Height.SelectFloatValue(random, metadata), Id);
                selectFloor = () => node == null ? null : node.Clone();
            }

            if (Continuous)
            {
                var l = new List <FloorSelection>();
                for (int i = 0; i < amount; i++)
                {
                    var f = selectFloor();
                    if (f != null)
                    {
                        l.Add(f);
                    }
                }
                emit.Add(l);
            }
            else
            {
                for (int i = 0; i < amount; i++)
                {
                    var f = selectFloor();
                    if (f != null)
                    {
                        emit.Add(new List <FloorSelection> {
                            f
                        });
                    }
                }
            }

            return(emit);
        }
Exemple #2
0
        private static FloorSelection SelectSingle(BaseFloorSelector selector, Func <double> random, IEnumerable <KeyValuePair <float, KeyValuePair <string, string>[]> > tags, Func <KeyValuePair <string, string>[], Type[], ScriptReference> finder, float height, string id)
        {
            Contract.Requires(selector != null);
            Contract.Requires(random != null);
            Contract.Requires(tags != null);
            Contract.Requires(finder != null);

            var result = tags.SelectScript(random, finder, typeof(IFloor));

            if (result == null)
            {
                return(null);
            }

            return(new FloorSelection(id, result.Tags, result.Script, height));
        }