Ejemplo n.º 1
0
        private void RemoveMainShaft(ShaftBuilder mainShaft)
        {
            foreach (var corridor in _corridorsByShaft[mainShaft])
            {
                _connectionsByCorridor.Remove(corridor);
            }
            _corridorsByShaft.Remove(mainShaft);
            _secondaryShaftsByShaft.Remove(mainShaft);
            _mainShafts.Remove(mainShaft);

            OnSpaceBuilderChanged.Raise(this);
        }
Ejemplo n.º 2
0
        private ShaftBuilder AddShaft(int startingStory, int endingStory, IntVector2 position)
        {
            var shaft = new ShaftBuilder(_chunkBuilder)
                        .SetStartingPoint(position, startingStory < endingStory ? Directions.Up : Directions.Down)
                        .SetWidth(ROOM_SIZE)
                        .SetHeight(STORY_SIZE * (1 + Mathf.Abs((endingStory - startingStory))))
                        .SetMinimumWidth(ROOM_SIZE)
                        .SetMinimumHeight(STORY_SIZE)
                        .SetUncapped(true);

            OnSpaceBuilderChanged.Raise(this);

            return(shaft);
        }
Ejemplo n.º 3
0
        private void GenerateCorridors(ShaftBuilder mainShaft, int numberStories)
        {
            if (_corridorsByShaft.TryGetValue(mainShaft, out var corridors))
            {
                corridors.Clear();
            }
            else
            {
                corridors = new List <CorridorBuilder>();
            }

            var shaftLeftSide  = mainShaft.GetMaximalValue(Directions.Left);
            var shaftRightSide = mainShaft.GetMaximalValue(Directions.Right);

            var shaftY = mainShaft.GetMaximalValue(Directions.Down);

            for (var story = 0; story < Mathf.Abs(numberStories); story++)
            {
                var yPosition = GetYPositionForStory(shaftY, story);

                if (Chance.CoinFlip)
                {
                    var corridor = AddCorridor(new IntVector2(shaftLeftSide, yPosition), Directions.Left);
                    corridor.AddModifier(ModifierTypes.Laboratory);
                    var room = AddRoom(new IntVector2(corridor.GetMaximalValue(Directions.Left), yPosition), Directions.Left);
                    room.AddModifier(ModifierTypes.Laboratory);
                    corridors.Add(corridor);
                    _connectionsByCorridor.Add(corridor, room);
                }
                if (Chance.CoinFlip)
                {
                    var corridor = AddCorridor(new IntVector2(shaftRightSide, yPosition), Directions.Right);
                    corridor.AddModifier(ModifierTypes.Laboratory);
                    var room = AddRoom(new IntVector2(corridor.GetMaximalValue(Directions.Right), yPosition), Directions.Right);
                    room.AddModifier(ModifierTypes.Laboratory);
                    corridors.Add(corridor);
                    _connectionsByCorridor.Add(corridor, room);
                }
            }

            _corridorsByShaft[mainShaft] = corridors;

            OnSpaceBuilderChanged.Raise(this);
        }
Ejemplo n.º 4
0
        private void RegisterNewMainShaft(ShaftBuilder mainShaft, int height)
        {
            if (_allowAdditionalMainShafts)
            {
                _mainShafts.Add(mainShaft);
                mainShaft.AddModifier(ModifierTypes.Laboratory);

                GenerateCorridors(mainShaft, height);
                GenerateSecondaryShafts(mainShaft, height);

                // The more shafts there are, the less likely we are to allow any more
                if (Chance.ChanceOf(_mainShafts.Count / (float)MAX_MAIN_SHAFTS))
                {
                    _allowAdditionalMainShafts = false;
                }
            }

            OnSpaceBuilderChanged.Raise(this);
        }
Ejemplo n.º 5
0
 private int GetMaximalValueForSpacesInShaft(ShaftBuilder shaft, IntVector2 direction)
 {
     if (direction == Directions.Up)
     {
         return(GetSpacesForShaft(shaft).Max(space => space.GetMaximalValue(direction)));
     }
     else if (direction == Directions.Right)
     {
         return(GetSpacesForShaft(shaft).Max(space => space.GetMaximalValue(direction)) + (_maximumCorridorSegments * CORRIDOR_SEGMENT_LENGTH) + METAL_THICKNESS);
     }
     else if (direction == Directions.Down)
     {
         return(GetSpacesForShaft(shaft).Min(space => space.GetMaximalValue(direction)));
     }
     else if (direction == Directions.Left)
     {
         return(GetSpacesForShaft(shaft).Min(space => space.GetMaximalValue(direction)) - (_maximumCorridorSegments * CORRIDOR_SEGMENT_LENGTH));
     }
     else
     {
         throw new System.ArgumentException($" Expected a cardinal direction.  Cannot operate on {direction}.");
     }
 }
Ejemplo n.º 6
0
        private List <SpaceBuilder> GetSpacesForShaft(ShaftBuilder mainShaft)
        {
            var spaces = new List <SpaceBuilder>
            {
                mainShaft
            };

            foreach (var corridorToBuild in _corridorsByShaft[mainShaft])
            {
                spaces.Add(corridorToBuild);

                if (_connectionsByCorridor[corridorToBuild] != null)
                {
                    spaces.Add(_connectionsByCorridor[corridorToBuild]);
                }
            }

            foreach (var shaftToBuild in _secondaryShaftsByShaft[mainShaft])
            {
                spaces.Add(shaftToBuild);
            }

            return(spaces);
        }
Ejemplo n.º 7
0
        private void GenerateSecondaryShafts(ShaftBuilder mainShaft, int height)
        {
            if (_secondaryShaftsByShaft.TryGetValue(mainShaft, out var shafts))
            {
                shafts.Clear();
            }
            else
            {
                shafts = new List <ShaftBuilder>();
            }

            var shaftY = mainShaft.GetMaximalValue(Directions.Down);
            var shaftX = mainShaft.GetMaximalValue(Directions.Left);

            for (var corridorSegment = -_maximumCorridorSegments; corridorSegment < _maximumCorridorSegments; corridorSegment++)
            {
                if (corridorSegment == 0)
                {
                    continue;                       // Main shaft...
                }
                var xPosition = (CORRIDOR_SEGMENT_LENGTH * corridorSegment) + shaftX;

                var validStories = new List <int>();

                for (var story = 0; story < Mathf.Abs(height); story++)
                {
                    var yPosition = GetYPositionForStory(shaftY, story);

                    var corridorPosition = new IntVector2(xPosition, yPosition);

                    if (_corridorsByShaft[mainShaft].Any(corridor => corridor.Contains(corridorPosition)))
                    {
                        validStories.Add(story);
                    }
                }

                if (validStories.Count > 0)
                {
                    if (corridorSegment == -_maximumCorridorSegments ||
                        corridorSegment == _maximumCorridorSegments)
                    {
                        var storyStartForShaft = validStories.RandomItem();
                        var yPosition          = GetYPositionForStory(shaftY, storyStartForShaft);
                        var newShaftHeight     = Chance.Range(-10, 10);

                        var shaft = AddShaft(storyStartForShaft, storyStartForShaft + newShaftHeight, new IntVector2(xPosition, yPosition));
                        RegisterNewMainShaft(shaft, newShaftHeight);

                        validStories.Remove(storyStartForShaft);
                    }
                    else if (validStories.Contains(0))
                    {
                        var newShaftHeight = Chance.Range(-10, -4);

                        var shaft = AddShaft(0, newShaftHeight, new IntVector2(xPosition, shaftY));
                        RegisterNewMainShaft(shaft, newShaftHeight);
                        validStories.Remove(0);
                    }
                    else if (validStories.Contains(height))
                    {
                        var yPosition      = GetYPositionForStory(shaftY, height);
                        var newShaftHeight = Chance.Range(4, 10);

                        var shaft = AddShaft(height, height + newShaftHeight, new IntVector2(xPosition, yPosition));
                        RegisterNewMainShaft(shaft, newShaftHeight);
                        validStories.Remove(height);
                    }

                    // At least two stories we can reach...
                    while (validStories.Count > 1)
                    {
                        var firstStory  = validStories.RandomItem();
                        var secondStory = validStories.RandomItem(firstStory);

                        var shaftPosition = new IntVector2(xPosition, GetYPositionForStory(shaftY, firstStory));

                        var shaft = AddShaft(Mathf.Min(firstStory, secondStory), Mathf.Max(firstStory, secondStory), shaftPosition);

                        if (!shafts.Any(otherShaft => otherShaft.IntersectsWith(shaft)))
                        {
                            shaft.AddModifier(ModifierTypes.Laboratory);
                            shafts.Add(shaft);
                        }

                        foreach (var corridor in _corridorsByShaft[mainShaft])
                        {
                            if (shaft.IntersectsWith(_connectionsByCorridor[corridor]))
                            {
                                _connectionsByCorridor[corridor] = null;
                            }
                        }

                        validStories.Remove(firstStory);
                        validStories.Remove(secondStory);
                    }
                }
            }

            _secondaryShaftsByShaft[mainShaft] = shafts;
            OnSpaceBuilderChanged.Raise(this);
        }