Exemple #1
0
        public GeneratedBranch Generate(ISystemContainer systemContainer, IEntity branchEntity, IProgress <string> progress)
        {
            var branch = branchEntity.Get <Branch>();

            Random = new RNG(systemContainer.Seed + branch.BranchName);

            var generatedBranchMaps = GenerateMaps(systemContainer, branch, branchEntity, progress);

            var generatedBranch = new GeneratedBranch()
            {
                Maps = generatedBranchMaps
            };

            CreateEntities(systemContainer, generatedBranch, branchEntity, progress);
            ExecuteMapGenCommands(systemContainer, generatedBranch, branch);

            IMap previousMap = null;

            foreach (var map in generatedBranch.Maps.OrderBy(m => m.MapKey.Key))
            {
                if (previousMap != null)
                {
                    LinkStairs(systemContainer, previousMap, map);
                }

                previousMap = map;
            }

            AddBranchPortals(systemContainer, generatedBranch, branch);

            branch.Generated = true;

            return(generatedBranch);
        }
Exemple #2
0
        public static void PlaceDefaultExitPortal(ISystemContainer systemContainer, GeneratedBranch generatedBranch, IRandom random)
        {
            var lastLayer = generatedBranch.Maps.Last();

            MapCoordinate emptyPosition = lastLayer.GetEmptyPosition(systemContainer.PositionSystem, random);

            systemContainer.PrototypeSystem.CreateAt("Props:Portal", emptyPosition);
        }
Exemple #3
0
        protected virtual void CreateEntities(ISystemContainer systemContainer, GeneratedBranch generatedBranch, IEntity branchEntity, IProgress <string> progress)
        {
            var entityGenerationSteps = branchEntity.Components.OfType <BaseEntityGenerationStrategy>();

            foreach (var step in entityGenerationSteps)
            {
                step.Generate(systemContainer, generatedBranch, branchEntity, Random, progress);
            }
        }
        public static void GenerateBranch(ISystemContainer systemContainer, IEntity branchEntity)
        {
            var branchGenerator = new BranchGenerator();
            var progress        = new Progress <string>();

            GeneratedBranch branch = branchGenerator.Generate(systemContainer, branchEntity, progress);

            foreach (Map map in branch.Maps)
            {
                systemContainer.MapSystem.MapCollection.AddMap(map);
            }
        }
Exemple #5
0
        protected void ExecuteMapGenCommands(ISystemContainer systemContainer, GeneratedBranch generatedBranch, Branch branch)
        {
            foreach (Map map in generatedBranch.Maps)
            {
                foreach (var command in map.MapGenCommands)
                {
                    var executor = MapGenCommandExecutorFactory.GetExecutor(command.MapGenCommandType);

                    executor.Execute(systemContainer, map, command, new Vector(0, 0));
                }
            }
        }
Exemple #6
0
        public static void PlaceStairs(ISystemContainer systemContainer, GeneratedBranch generatedBranch, IRandom random)
        {
            Map previousMap = null;

            foreach (Map map in generatedBranch.Maps.OrderBy(m => m.MapKey.Key))
            {
                if (previousMap != null)
                {
                    PlaceStairSet(systemContainer, previousMap, map, random);
                }

                previousMap = map;
            }
        }
Exemple #7
0
        protected virtual void AddBranchPortals(ISystemContainer systemContainer, GeneratedBranch generatedBranch, Branch branch)
        {
            var engine          = systemContainer.EntityEngine;
            var prototypeSystem = systemContainer.PrototypeSystem;
            var positionSystem  = systemContainer.PositionSystem;

            var links = engine.GetAll <BranchLink>();

            var relevantLinks = new Dictionary <BranchLinkEnd, BranchLinkEnd>();

            foreach (var link in links)
            {
                if (link.From.Branch == branch.BranchName)
                {
                    relevantLinks.Add(link.From, link.To);
                }

                if (link.To.Branch == branch.BranchName)
                {
                    relevantLinks.Add(link.To, link.From);
                }
            }

            foreach (var link in relevantLinks)
            {
                var thisEnd = link.Key;
                var thatEnd = link.Value;

                var level = Random.Between(thisEnd.LevelFrom, thisEnd.LevelTo);

                var mapKey = new MapKey(branch.LevelName(level));

                var potentialPortals = engine.EntitiesWith <Portal>()
                                       .Where(p => p.Get <Position>().MapCoordinate.Key == mapKey)
                                       .Where(p => string.IsNullOrEmpty(p.Get <Portal>().BranchLink))
                                       .ToList();

                if (!potentialPortals.Any())
                {
                    throw new Exception("No available portals to place branch link");
                }

                var portalEntity = Random.PickOne(potentialPortals);
                var thisPortal   = portalEntity.Get <Portal>();

                thisPortal.BranchLink = thatEnd.Branch;

                var destinationBranch = prototypeSystem.Get(link.Value.Branch).Get <Branch>();

                thisEnd.Location = portalEntity.Get <Position>().MapCoordinate;

                if (thatEnd.Location != null)
                {
                    var thatPortal = positionSystem.EntitiesAt(thatEnd.Location)
                                     .Single(e => e.Has <Portal>())
                                     .Get <Portal>();

                    thisPortal.Destination = thatEnd.Location;
                    thatPortal.Destination = thisEnd.Location;
                }
            }
        }