// TODO: DRY

        protected override UnrealMap _Mix(MapMixParams mixParams)
        {
            var destMap = new UnrealMap();

            // Get all actors
            var allActors = new List <UnrealActor>();

            foreach (var map in maps)
            {
                var offset = mixParams.MapOffsets[map.FilePath];

                allActors.AddRange(map.Actors.Select(a => UnrealActorFactory.Duplicate(a, offset)));
            }

            // Pick actors randomly
            var mixActors = new List <UnrealActor>();

            foreach (var actor in allActors)
            {
                // Check exclusions
                if (mixParams.ExcludeZoneInfo && ZoneInfoNames.Contains(actor.Class))
                {
                    continue;
                }
                if (mixParams.ExcludeMore && mixParams.ExcludeMoreNames.Contains(actor.Class))
                {
                    continue;
                }

                // TODO: check brush probabilities

                // Get probability
                double prob;
                if (actor.Class.Contains("Light"))
                {
                    prob = mixParams.LightProb;
                }
                else
                {
                    prob = mixParams.OtherProb;
                }

                if (RandExp(prob))
                {
                    mixActors.Add(actor);
                }
            }

            // Shuffle
            Shuffle(mixActors);

            // Add selected actors
            foreach (var actor in mixActors)
            {
                destMap.AddActor(actor);
            }

            // Remove trapped PlayerStarts
            if (mixParams.RemoveTrappedPlayerStarts)
            {
                destMap.RemoveTrappedPlayerStarts();
            }

            return(destMap);
        }
Beispiel #2
0
        // TODO: DRY

        protected override UnrealMap _Mix(MapMixParams mixParams)
        {
            var destMap = new UnrealMap();

            // Get brush-rank pairs, actors and other features
            var brushRanks = new List <Tuple <UnrealBrush, double> >();
            var allActors  = new List <UnrealActor>(); // excluding brushes

            foreach (var map in maps)
            {
                var offset = mixParams.MapOffsets[map.FilePath];

                brushRanks.AddRange(map.Brushes
                                    .Select(
                                        (b, i) => new Tuple <UnrealBrush, double>
                                            (UnrealActorFactory.Duplicate(b, offset), (double)i / map.BrushCount)));

                allActors.AddRange(map.Actors
                                   .Where(a => !(a is UnrealBrush))
                                   .Select(a => UnrealActorFactory.Duplicate(a, offset)));
            }

            // Merge all brushes
            var allBrushes = brushRanks.OrderBy(t => t.Item2).Select(t => t.Item1);

            // Pick brushes randomly
            var mixBrushes = new List <UnrealBrush>();

            mixBrushes.Add(maps.First().Brushes.First()); // add builder brush
            foreach (var brush in allBrushes)
            {
                // Check exclusions
                if (mixParams.ExcludeInvisible && brush.IsInvisible)
                {
                    continue;
                }
                if (mixParams.ExcludePortal && brush.IsPortal)
                {
                    continue;
                }

                // TODO: bug with exclusions?
                // TODO: add tests!

                // Get probability
                double prob;
                switch (brush.Operation)
                {
                case BrushOperation.Solid: prob = mixParams.SolidProb; break;

                case BrushOperation.SemiSolid: prob = mixParams.SemiSolidProb; break;

                case BrushOperation.NonSolid: prob = mixParams.NonSolidProb; break;

                case BrushOperation.Subtract: prob = mixParams.SubtractProb; break;

                case BrushOperation.Mover: prob = mixParams.MoverProb; break;

                default: prob = 0.0; break;     // probably a builder brush, which is already included
                }

                if (RandExp(prob))
                {
                    mixBrushes.Add(brush);
                }
            }

            // Pick actors randomly
            var mixActors = new List <UnrealActor>();

            foreach (var actor in allActors)
            {
                // Check exclusions
                if (mixParams.ExcludeZoneInfo && ZoneInfoNames.Contains(actor.Class))
                {
                    continue;
                }
                if (mixParams.ExcludeMore && mixParams.ExcludeMoreNames.Contains(actor.Class))
                {
                    continue;
                }

                // Get probability
                double prob;
                if (actor.Class.Contains("Light"))
                {
                    prob = mixParams.LightProb;
                }
                else
                {
                    prob = mixParams.OtherProb;
                }

                if (RandExp(prob))
                {
                    mixActors.Add(actor);
                }
            }

            // Add selected brushes & actors
            foreach (var brush in mixBrushes)
            {
                destMap.AddActor(brush);
            }
            foreach (var actor in mixActors)
            {
                destMap.AddActor(actor);
            }

            // Remove trapped PlayerStarts
            if (mixParams.RemoveTrappedPlayerStarts)
            {
                destMap.RemoveTrappedPlayerStarts();
            }

            return(destMap);
        }