Example #1
0
        public static DungeonTile.Index GetAdjacentIndex(Dungeon dungeon, int2 key, BuilderDirection direction)
        {
            var adjacentKey = key;

            switch (direction)
            {
            case BuilderDirection.North:
                adjacentKey = new int2(key.x, key.y - 1);
                break;

            case BuilderDirection.East:
                adjacentKey = new int2(key.x + 1, key.y);
                break;

            case BuilderDirection.South:
                adjacentKey = new int2(key.x, key.y + 1);
                break;

            case BuilderDirection.West:
                adjacentKey = new int2(key.x - 1, key.y);
                break;
            }
            if (dungeon.ValueMap.ContainsKey(adjacentKey))
            {
                return(dungeon.ValueMap[adjacentKey].Index);
            }

            return(DungeonTile.Index.Void);
        }
Example #2
0
 public DungeonDomainBuilder ChangeBuilderDirection(BuilderDirection direction)
 {
     Action($"Change builder direction");
     {
         Do((context) =>
         {
             Debug.Log($"Change build direction {direction}\n");
             context.CurrentBuilderDirection = direction;
             return(TaskStatus.Success);
         });
     }
     End();
     return(this);
 }
Example #3
0
        /// <summary>
        /// The higher the count of tiles in a direction with the same index, the higher the chance is to covert
        private bool TryConvertIndexAtoB(Dungeon dungeon, int2 key, BuilderDirection direction, DungeonTile.Index a, DungeonTile.Index b, int maxCount)
        {
            var count = 0;

            CountIndexInDirection(dungeon, key, direction, a, ref count);
            count = Mathf.Min(count, maxCount);
            var chance = Mathf.Max((count / (float)maxCount) - 0.1f, 0);

            if (Random.value < chance)
            {
                dungeon.ValueMap[key].Theme = _meta.Theme;
                dungeon.ValueMap[key].Index = b;
                return(true);
            }

            return(false);
        }
Example #4
0
        public static void CountIndexInDirection(Dungeon dungeon, int2 key, BuilderDirection direction, DungeonTile.Index indexType, ref int count)
        {
            if (dungeon.ValueMap.ContainsKey(key) == false)
            {
                return;
            }

            var index = dungeon.ValueMap[key].Index;

            if (index != indexType)
            {
                return;
            }

            count++;

            var adjacentKey = key;

            switch (direction)
            {
            case BuilderDirection.North:
                adjacentKey = new int2(key.x, key.y - 1);
                break;

            case BuilderDirection.East:
                adjacentKey = new int2(key.x + 1, key.y);
                break;

            case BuilderDirection.South:
                adjacentKey = new int2(key.x, key.y + 1);
                break;

            case BuilderDirection.West:
                adjacentKey = new int2(key.x - 1, key.y);
                break;
            }

            if (adjacentKey.x == key.x && adjacentKey.y == key.y)
            {
                return;
            }

            CountIndexInDirection(dungeon, adjacentKey, direction, indexType, ref count);
        }
Example #5
0
        private BuilderDirection Opposite(BuilderDirection direction)
        {
            switch (direction)
            {
            case BuilderDirection.North:
                return(BuilderDirection.South);

            case BuilderDirection.East:
                return(BuilderDirection.West);

            case BuilderDirection.South:
                return(BuilderDirection.North);

            case BuilderDirection.West:
                return(BuilderDirection.East);
            }

            return(BuilderDirection.Portal);
        }
Example #6
0
        private static bool FloodFillInDirection(Dungeon dungeon, DungeonTheme theme, int2 start, int2 end, List <int2> closed,
                                                 BuilderDirection dir)
        {
            var key = DungeonRoom.GetAdjacentKey(dungeon, start, dir);

            if (key.x == end.x && key.y == end.y)
            {
                return(true);
            }

            if (closed.Contains(key))
            {
                return(false);
            }

            closed.Add(key);

            if (IsValid(dungeon, theme, key))
            {
                return(Floodfill(dungeon, theme, key, end, closed));
            }

            return(false);
        }
Example #7
0
        public static int2 GetAdjacentKey(Dungeon dungeon, int2 key, BuilderDirection direction)
        {
            var adjacentKey = key;

            switch (direction)
            {
            case BuilderDirection.North:
                adjacentKey = new int2(key.x, key.y - 1);
                break;

            case BuilderDirection.East:
                adjacentKey = new int2(key.x + 1, key.y);
                break;

            case BuilderDirection.South:
                adjacentKey = new int2(key.x, key.y + 1);
                break;

            case BuilderDirection.West:
                adjacentKey = new int2(key.x - 1, key.y);
                break;
            }
            return(adjacentKey);
        }
Example #8
0
        private void ExtendFOV(Dungeon.Dungeon dungeon, CharacterContext context, int2 key, BuilderDirection dir, ref List <int2> extensions)
        {
            var adjacentKey = DungeonRoom.GetAdjacentKey(dungeon, key, dir);

            if (context.FieldOfView.ContainsKey(adjacentKey) || (extensions != null && extensions.Contains(adjacentKey)))
            {
                return;
            }

            if (dungeon.ValueMap.ContainsKey(adjacentKey))
            {
                if (dungeon.ValueMap[adjacentKey].Index == DungeonTile.Index.Wall)
                {
                    if (extensions == null)
                    {
                        extensions = new List <int2>();
                    }

                    extensions.Add(adjacentKey);
                }
            }
        }
Example #9
0
        private static void TryWallIn(Dungeon dungeon, DungeonRoom room, DungeonTheme theme, int2 key, BuilderDirection direction)
        {
            var value = dungeon.ValueMap[key];

            if (value.Theme != theme)
            {
                return;
            }

            var adjacentKey = GetAdjacentKey(dungeon, key, direction);

            if (dungeon.ValueMap.ContainsKey(adjacentKey) == false)
            {
                var tile = new Dungeon.MapValue
                {
                    Theme = theme,
                    Index = DungeonTile.Index.Wall,
                    Room  = room,
                };
                dungeon.ValueMap.Add(adjacentKey, tile);
                room.ValueMap.Add(adjacentKey, value);
            }

            var adjacent = dungeon.ValueMap[adjacentKey];

            if (adjacent.Theme != theme)
            {
                // If we're at a forest tile and the adjacent tile is already a wall, we don't always want to place a forest wall tile.
                if (adjacent.Index == DungeonTile.Index.Wall && value.Theme == DungeonTheme.Forest)
                {
                    if (Random.value < 0.4f)
                    {
                        dungeon.ValueMap[key].Index = DungeonTile.Index.Wall;
                    }
                }
                else
                {
                    dungeon.ValueMap[key].Index = DungeonTile.Index.Wall;
                }

                if (room.ConnectionMap.ContainsKey(key) == false)
                {
                    var adjacentRoom = dungeon.GetRoom(adjacentKey);
                    if (adjacentRoom != null)
                    {
                        room.ConnectionMap.Add(key, new Tuple <int2, DungeonRoom>(
                                                   adjacentKey,
                                                   adjacentRoom));

                        if (adjacentRoom.ConnectionMap.ContainsKey(adjacentKey) == false)
                        {
                            adjacentRoom.ConnectionMap.Add(adjacentKey, new Tuple <int2, DungeonRoom>(
                                                               key,
                                                               room));
                        }
                    }
                }
            }
        }
Example #10
0
        private static void TryWallOutTheVoid(Dungeon dungeon, DungeonRoom room, int2 key, Dungeon.MapValue origin, BuilderDirection direction)
        {
            var value = dungeon.ValueMap[key];

            var adjacentKey = GetAdjacentKey(dungeon, key, direction);

            if (dungeon.ValueMap.ContainsKey(adjacentKey) == false)
            {
                var tile = new Dungeon.MapValue
                {
                    Theme = origin.Theme,
                    Index = DungeonTile.Index.Wall,
                    Room  = room,
                };
                dungeon.ValueMap.Add(adjacentKey, tile);
                room.ValueMap.Add(adjacentKey, value);
            }
        }