Example #1
0
        public override void Apply(T map)
        {
            Grid.LocTest checkGround = (Loc testLoc) =>
            {
                if (!Collision.InBounds(map.Width, map.Height, testLoc))
                {
                    return(false);
                }
                return(map.Tiles[testLoc.X][testLoc.Y].TileEquivalent(map.RoomTerrain) && !map.HasTileEffect(testLoc));
            };
            Grid.LocTest checkBlock = (Loc testLoc) =>
            {
                if (!Collision.InBounds(map.Width, map.Height, testLoc))
                {
                    return(false);
                }
                return(map.Tiles[testLoc.X][testLoc.Y].TileEquivalent(map.WallTerrain));
            };

            List <LocRay4> rays = Detection.DetectWalls(((IViewPlaceableGenContext <MapGenEntrance>)map).GetLoc(0), new Rect(0, 0, map.Width, map.Height), checkBlock, checkGround);

            EffectTile    effect = new EffectTile(LockedTile, true);
            TileListState state  = new TileListState();

            effect.TileStates.Set(state);

            List <Loc> freeTiles = new List <Loc>();
            LocRay4?   ray       = PlaceRoom(map, rays, effect, freeTiles);

            if (ray != null)
            {
                PlaceEntities(map, freeTiles);
            }
        }
Example #2
0
        protected override void PlaceBorders(T map, Dictionary <Loc, SealType> sealList)
        {
            List <Loc> keyList  = new List <Loc>();
            List <Loc> lockList = new List <Loc>();

            foreach (Loc loc in sealList.Keys)
            {
                switch (sealList[loc])
                {
                //lay down the blocks
                case SealType.Blocked:
                    map.Tiles[loc.X][loc.Y] = (Tile)map.UnbreakableTerrain.Copy();
                    break;

                case SealType.Locked:
                    lockList.Add(loc);
                    break;

                case SealType.Key:
                    keyList.Add(loc);
                    break;
                }
            }


            //choose the key tile
            int keyIndex = map.Rand.Next(keyList.Count - 1);
            Loc keyLoc   = keyList[keyIndex];

            keyList.RemoveAt(keyIndex);


            lockList.AddRange(keyList);

            //seal the tiles that are gated
            foreach (Loc loc in lockList)
            {
                map.Tiles[loc.X][loc.Y] = (Tile)map.UnbreakableTerrain.Copy();
                EffectTile newEffect = new EffectTile(LockedTile, true, loc);
                ((IPlaceableGenContext <EffectTile>)map).PlaceItem(loc, newEffect);
            }

            //finally, seal with a locked door
            {
                map.Tiles[keyLoc.X][keyLoc.Y] = (Tile)map.UnbreakableTerrain.Copy();
                EffectTile    newEffect = new EffectTile(KeyTile, true, keyLoc);
                TileListState state     = new TileListState();
                state.Tiles = lockList;
                newEffect.TileStates.Set(state);
                ((IPlaceableGenContext <EffectTile>)map).PlaceItem(keyLoc, newEffect);
            }
        }
Example #3
0
        public override void Apply(T map)
        {
            //first get all free tiles suitable for the switch
            List <Loc> freeSwitchTiles = ((IPlaceableGenContext <EffectTile>)map).GetAllFreeTiles();

            if (freeSwitchTiles.Count == 0)
            {
                return;
            }

            Grid.LocTest checkGround = (Loc testLoc) =>
            {
                if (!Collision.InBounds(map.Width, map.Height, testLoc))
                {
                    return(false);
                }
                return(map.Tiles[testLoc.X][testLoc.Y].TileEquivalent(map.RoomTerrain) && !map.HasTileEffect(testLoc));
            };
            Grid.LocTest checkBlock = (Loc testLoc) =>
            {
                if (!Collision.InBounds(map.Width, map.Height, testLoc))
                {
                    return(false);
                }
                return(map.Tiles[testLoc.X][testLoc.Y].TileEquivalent(map.WallTerrain));
            };

            List <LocRay4> rays = Detection.DetectWalls(((IViewPlaceableGenContext <MapGenEntrance>)map).GetLoc(0), new Rect(0, 0, map.Width, map.Height), checkBlock, checkGround);

            EffectTile effect = new EffectTile(SealedTile, true);

            List <Loc>     freeTiles        = new List <Loc>();
            List <LocRay4> createdEntrances = new List <LocRay4>();

            int amount = EntranceCount.Pick(map.Rand);

            for (int ii = 0; ii < amount; ii++)
            {
                LocRay4?ray = PlaceRoom(map, rays, effect, freeTiles);

                if (ray != null)
                {
                    createdEntrances.Add(ray.Value);
                }
            }

            if (createdEntrances.Count > 0)
            {
                PlaceEntities(map, freeTiles);

                EffectTile switchTile = new EffectTile(SwitchTile, true);

                if (TimeLimit)
                {
                    switchTile.Danger = true;
                }

                TileListState state = new TileListState();
                for (int mm = 0; mm < createdEntrances.Count; mm++)
                {
                    state.Tiles.Add(new Loc(createdEntrances[mm].Loc));
                }
                switchTile.TileStates.Set(state);

                int randIndex = map.Rand.Next(freeSwitchTiles.Count);

                ((IPlaceableGenContext <EffectTile>)map).PlaceItem(freeSwitchTiles[randIndex], switchTile);
            }
        }
Example #4
0
        protected override void PlaceBorders(T map, Dictionary <Loc, SealType> sealList)
        {
            List <Loc> freeSwitchTiles = new List <Loc>();

            for (int ii = 0; ii < map.RoomPlan.RoomCount; ii++)
            {
                FloorRoomPlan plan = map.RoomPlan.GetRoomPlan(ii);
                if (!BaseRoomFilter.PassesAllFilters(plan, this.SwitchFilters))
                {
                    continue;
                }
                freeSwitchTiles.AddRange(((IPlaceableGenContext <EffectTile>)map).GetFreeTiles(plan.RoomGen.Draw));
            }
            for (int ii = 0; ii < map.RoomPlan.HallCount; ii++)
            {
                FloorHallPlan plan = map.RoomPlan.GetHallPlan(ii);
                if (!BaseRoomFilter.PassesAllFilters(plan, this.SwitchFilters))
                {
                    continue;
                }
                freeSwitchTiles.AddRange(((IPlaceableGenContext <EffectTile>)map).GetFreeTiles(plan.RoomGen.Draw));
            }

            //if there's no way to open the door, there cannot be a door; give the player the treasure unguarded
            if (freeSwitchTiles.Count == 0)
            {
                return;
            }

            List <Loc> lockList = new List <Loc>();

            foreach (Loc loc in sealList.Keys)
            {
                switch (sealList[loc])
                {
                case SealType.Blocked:
                    map.Tiles[loc.X][loc.Y] = (Tile)map.UnbreakableTerrain.Copy();
                    break;

                default:
                    lockList.Add(loc);
                    break;
                }
            }

            foreach (Loc loc in lockList)
            {
                map.Tiles[loc.X][loc.Y] = (Tile)map.UnbreakableTerrain.Copy();
                EffectTile newEffect = new EffectTile(SealedTile, true, loc);
                ((IPlaceableGenContext <EffectTile>)map).PlaceItem(loc, newEffect);
            }


            EffectTile switchTile = new EffectTile(SwitchTile, true);

            if (TimeLimit)
            {
                switchTile.Danger = true;
            }

            TileListState state = new TileListState();

            state.Tiles = lockList;
            switchTile.TileStates.Set(state);

            int randIndex = map.Rand.Next(freeSwitchTiles.Count);

            ((IPlaceableGenContext <EffectTile>)map).PlaceItem(freeSwitchTiles[randIndex], switchTile);
        }