コード例 #1
0
ファイル: RogueBase.cs プロジェクト: vrum/roguelike
        /// <summary>
        /// Add a feature to the dungeon. Guarantees an acceptable placement.
        /// Might loop forever if all squares in the dungeon are already taken up
        /// </summary>
        /// <param name="feature"></param>
        /// <param name="level"></param>
        /// <param name="location"></param>
        void AddFeatureToDungeonRandomPoint(Feature feature, MapGeneratorBSP mapGen, int level)
        {
            Point location;

            //Loop until we find an acceptable location and the add works
            do
            {
                location = mapGen.RandomWalkablePoint();
            }while (!dungeon.AddFeature(feature, level, location));
        }
コード例 #2
0
 public MapNode(MapGeneratorBSP parentGen, int x, int y, int width, int height)
 {
     this.parentGenerator = parentGen;
     noSplitChance = parentGen.NoSplitChance;
     this.x = x;
     this.y = y;
     this.width = width;
     this.height = height;
 }
コード例 #3
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        private void SpawnRandomMap(Dungeon dungeon, int level)
        {
            MapGeneratorBSP hallsGen = new MapGeneratorBSP();

            //Clip to 60
            hallsGen.Width = (int)Math.Min(40 + Game.Random.Next(25), 60);
            hallsGen.Height = 25;

            Map hallMap = hallsGen.GenerateMap(hallsExtraCorridorDefinite + Game.Random.Next(hallsExtraCorridorRandom));
            int levelNo = Game.Dungeon.AddMap(hallMap);

            //Store the hallGen
            //Will get sorted in level order
            levelGen.Add(level, hallsGen);

            //Add standard dock triggers (allows map abortion & completion)
            AddStandardEntryExitTriggers(dungeon, hallsGen, levelNo);

            //Place dock bay feature at PC startloc
            Game.Dungeon.AddFeature(new Features.DockBay(), levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation);
        }
コード例 #4
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        private void SpawnMapFlatline(List<int> dungeonLevelsToSpawn, bool useOldSeed)
        {
            Dungeon dungeon = Game.Dungeon;

            //Fixed and random levels
            foreach (int level in dungeonLevelsToSpawn)
            {

                switch (level)
                {

                    case 0:
                        {
                            //Make level 0 rather small

                            MapGeneratorBSP hallsGen = new MapGeneratorBSP();

                            hallsGen.Width = 40;
                            hallsGen.Height = 80;

                            Map hallMap = hallsGen.GenerateMap(hallsExtraCorridorDefinite + Game.Random.Next(hallsExtraCorridorRandom));
                            int levelNo = Game.Dungeon.AddMap(hallMap);

                            //Store the hallGen so we can use it for monsters
                            levelGen.Add(level, hallsGen);

                            //Add standard dock triggers
                            AddStandardEntryExitTriggers(dungeon, hallsGen, levelNo);

                            //Add first level entry trigger
                            Game.Dungeon.AddTrigger(levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation, new Triggers.FirstLevelEntry());

                            //Place dock bay feature at PC startloc
                            Game.Dungeon.AddFeature(new Features.DockBay(), levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation);

                        }
                        break;

                    case 1:
                        {
                            //Make level 1 rather small

                            MapGeneratorBSP hallsGen = new MapGeneratorBSP();

                            hallsGen.Width = 40;
                            hallsGen.Height = 25;

                            Map hallMap = hallsGen.GenerateMap(hallsExtraCorridorDefinite + Game.Random.Next(hallsExtraCorridorRandom));
                            int levelNo = Game.Dungeon.AddMap(hallMap);

                            //Store the hallGen so we can use it for monsters
                            levelGen.Add(level, hallsGen);

                            //Add standard dock triggers
                            AddStandardEntryExitTriggers(dungeon, hallsGen, levelNo);

                            //Add level entry trigger
                            Game.Dungeon.AddTrigger(levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation, new Triggers.Mission1Entry());

                            //Place dock bay feature at PC startloc
                            Game.Dungeon.AddFeature(new Features.DockBay(), levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation);

                        }
                        break;

                    case 2:
                        {
                            //Make level 2 rather small

                            MapGeneratorBSP hallsGen = new MapGeneratorBSP();

                            hallsGen.Width = 40;
                            hallsGen.Height = 25;

                            Map hallMap = hallsGen.GenerateMap(hallsExtraCorridorDefinite + Game.Random.Next(hallsExtraCorridorRandom));
                            int levelNo = Game.Dungeon.AddMap(hallMap);

                            //Store the hallGen so we can use it for monsters
                            levelGen.Add(level, hallsGen);

                            //Add standard dock triggers
                            AddStandardEntryExitTriggers(dungeon, hallsGen, levelNo);

                            //Add level entry trigger
                            Game.Dungeon.AddTrigger(levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation, new Triggers.Mission2Entry());

                            //Place dock bay feature at PC startloc
                            Game.Dungeon.AddFeature(new Features.DockBay(), levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation);

                        }
                        break;

                    case 3:
                        {
                            //Make level 3 rather small

                            MapGeneratorBSP hallsGen = new MapGeneratorBSP();

                            hallsGen.Width = 40;
                            hallsGen.Height = 25;

                            Map hallMap = hallsGen.GenerateMap(hallsExtraCorridorDefinite + Game.Random.Next(hallsExtraCorridorRandom));
                            int levelNo = Game.Dungeon.AddMap(hallMap);

                            //Store the hallGen so we can use it for monsters
                            levelGen.Add(level, hallsGen);

                            //Add standard dock triggers
                            AddStandardEntryExitTriggers(dungeon, hallsGen, levelNo);

                            //Add level entry trigger
                            Game.Dungeon.AddTrigger(levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation, new Triggers.Mission3Entry());

                            //Place dock bay feature at PC startloc
                            Game.Dungeon.AddFeature(new Features.DockBay(), levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation);

                        }
                        break;

                    case 4:
                        {
                            //Make level 4 rather small
                            MapGeneratorBSP hallsGen = new MapGeneratorBSP();

                            hallsGen.Width = 40;
                            hallsGen.Height = 25;

                            Map hallMap = hallsGen.GenerateMap(hallsExtraCorridorDefinite + Game.Random.Next(hallsExtraCorridorRandom));
                            int levelNo = Game.Dungeon.AddMap(hallMap);

                            //Store the hallGen so we can use it for monsters
                            levelGen.Add(level, hallsGen);

                            //Add standard dock triggers
                            AddStandardEntryExitTriggers(dungeon, hallsGen, levelNo);

                            //Add level entry trigger
                            Game.Dungeon.AddTrigger(levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation, new Triggers.Mission4Entry());

                            //Place dock bay feature at PC startloc
                            Game.Dungeon.AddFeature(new Features.DockBay(), levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation);

                        }
                        break;
                    case 5:
                        {
                            //Make level 5 rather small

                            MapGeneratorBSP hallsGen = new MapGeneratorBSP();

                            hallsGen.Width = 40;
                            hallsGen.Height = 25;

                            Map hallMap = hallsGen.GenerateMap(hallsExtraCorridorDefinite + Game.Random.Next(hallsExtraCorridorRandom));
                            int levelNo = Game.Dungeon.AddMap(hallMap);

                            //Store the hallGen so we can use it for monsters
                            levelGen.Add(level, hallsGen);

                            //Add standard dock triggers
                            AddStandardEntryExitTriggers(dungeon, hallsGen, levelNo);

                            //Add level entry trigger
                            Game.Dungeon.AddTrigger(levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation, new Triggers.Mission5Entry());

                            //Place dock bay feature at PC startloc
                            Game.Dungeon.AddFeature(new Features.DockBay(), levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation);

                        }
                        break;

                    case 6:
                        {
                            //Make level 6 test level

                            MapGeneratorBSP hallsGen = new MapGeneratorBSP();

                            hallsGen.Width = 40;
                            hallsGen.Height = 25;

                            Map hallMap = hallsGen.GenerateMap(hallsExtraCorridorDefinite + Game.Random.Next(hallsExtraCorridorRandom));
                            int levelNo = Game.Dungeon.AddMap(hallMap);

                            //Store the hallGen so we can use it for monsters
                            levelGen.Add(level, hallsGen);

                            //Add standard dock triggers
                            AddStandardEntryExitTriggers(dungeon, hallsGen, levelNo);

                            //Add level entry trigger
                            Game.Dungeon.AddTrigger(levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation, new Triggers.Mission6Entry());

                            //Place dock bay feature at PC startloc
                            Game.Dungeon.AddFeature(new Features.DockBay(), levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation);

                        }
                        break;

                    case 11:
                        SpawnRandomMap(dungeon, level);
                        //Add level entry trigger
                        Game.Dungeon.AddTrigger(level, Game.Dungeon.Levels[level].PCStartLocation, new Triggers.Mission11Entry());

                        break;

                    case 14:
                        SpawnRandomMap(dungeon, level);
                        //Add level entry trigger
                        Game.Dungeon.AddTrigger(level, Game.Dungeon.Levels[level].PCStartLocation, new Triggers.Mission14Entry());
                        break;

                    default:
                        //Use random dungeon generator
                        {
                            SpawnRandomMap(dungeon, level);
                        }

                        break;
                }

            }

            //Build TCOD maps
            //Necessary so connectivity checks on items and monsters can work
            //Only place where this happens now
            CalculateWalkableAndTCOD();
        }
コード例 #5
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        private void SpawnItemsRandomly(int levelIndex, MapGeneratorBSP mapGen)
        {
            //Item catalogue

            List<Item> meleeRelatedItems = new List<Item>();
            meleeRelatedItems.Add(new Items.Vibroblade());
            meleeRelatedItems.Add(new Items.Pistol());
            meleeRelatedItems.Sort((x,y) => x.ItemCost().CompareTo(y.ItemCost()));

            List<Item> rangedRelatedItems = new List<Item>();
            rangedRelatedItems.Add(new Items.Shotgun());
            rangedRelatedItems.Add(new Items.Laser());
            rangedRelatedItems.Add(new Items.Pistol());
            rangedRelatedItems.Sort((x,y) => x.ItemCost().CompareTo(y.ItemCost()));

            List<Item> grenadeRelatedItems = new List<Item>();
            grenadeRelatedItems.Add(new Items.SoundGrenade());
            grenadeRelatedItems.Add(new Items.FragGrenade());
            grenadeRelatedItems.Add(new Items.StunGrenade());
            grenadeRelatedItems.Sort((x,y) => x.ItemCost().CompareTo(y.ItemCost()));

            List<Item> healingRelatedItems = new List<Item>();
            healingRelatedItems.Add(new Items.NanoRepair());
            healingRelatedItems.Add(new Items.TacticalOverlay());
            healingRelatedItems.Add(new Items.StealthCloak());
            healingRelatedItems.Sort((x,y) => x.ItemCost().CompareTo(y.ItemCost()));

            List<List<Item>> itemCatalogue = new List<List<Item>>();
            itemCatalogue.Add(meleeRelatedItems);
            itemCatalogue.Add(rangedRelatedItems);
            itemCatalogue.Add(healingRelatedItems);
            //Grenades go in last to suck up any left-over budget
            itemCatalogue.Add(grenadeRelatedItems);

            //Calculate the budget we have to spend
            int itemBudget = 60 + (levelIndex - 5) * 10;

            //Divide between different types

            List<double> budgetRatios = new List<double>();

            double meleeRelatedBudgetRatio = Game.Random.NextDouble();
            budgetRatios.Add(meleeRelatedBudgetRatio);

            double firingRelatedBudgetRatio = 1 - meleeRelatedBudgetRatio;
            budgetRatios.Add(firingRelatedBudgetRatio);

            double grenadeRelatedBudgeRadio = Game.Random.NextDouble();
            budgetRatios.Add(grenadeRelatedBudgeRadio);

            double healingRelatedBudgeRadio = Game.Random.NextDouble();
            budgetRatios.Add(healingRelatedBudgeRadio);

            //Calculate budget split
            double totalRatio = 0.0;
            foreach(double d in budgetRatios) {
                totalRatio += d;
            }

            double ratioToTotalBudget = itemBudget / totalRatio;

            double remainder = 0.0;

            //To hold all the items to place
            List<Item> itemsToPlace = new List<Item>();

            //Spend budget on each catalogue, depending upon ratio
            for (int i = 0; i < itemCatalogue.Count; i++)
            {
                double categoryBudget = budgetRatios[i] * ratioToTotalBudget + remainder;
                remainder = (double)SpendItemBudget((int)categoryBudget, itemCatalogue[i], itemsToPlace);
            }

            LogFile.Log.LogEntryDebug("SpawnItemsRandomly: level: " + levelIndex + " total budget: " + itemBudget + " remainder: " + remainder, LogDebugLevel.High);

            //Add any standard items

            //1 healing kit
            itemsToPlace.Add(new Items.NanoRepair());

            //Actually add the items
            List<RoomCoords> allRooms = mapGen.GetAllRooms();

            AddItemsEqualDistribution(itemsToPlace, levelIndex, mapGen);

            //Pistol at start location
            AddItemAtLocation(new Items.Pistol(), levelIndex, mapGen.GetPlayerStartLocation());
        }
コード例 #6
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        private void SpawnItemsLevel6(int levelIndex, MapGeneratorBSP mapGen)
        {
            List<RoomCoords> allRooms = mapGen.GetAllRooms();

            //Pistol at start location
            AddItemAtLocation(new Items.Laser(), levelIndex, mapGen.GetPlayerStartLocation());
            AddItemAtLocation(new Items.StealthCloak(), levelIndex, mapGen.GetPlayerStartLocation());

            //Spawn some items

            List<Item> itemsToPlace = new List<Item>();

            itemsToPlace.Add(new Items.TacticalOverlay());
            itemsToPlace.Add(new Items.StealthCloak());

            AddItemsEqualDistribution(itemsToPlace, levelIndex, mapGen);
        }
コード例 #7
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        /// <summary>
        /// Adds levels and interconnecting staircases
        /// </summary>
        private void SetupMapsGraphingDemoCycles()
        {
            Dungeon dungeon = Game.Dungeon;

            MapGeneratorBSP hallsGen = new MapGeneratorBSP();

            //Clip to 60
            hallsGen.Width = 50;
            hallsGen.Height = 25;

            hallsGen.NoSplitChance = 3;
            Map hallMap = hallsGen.GenerateMap(3);

            //Optionally add door locks

            //Firstly find the node in the reduced map that corresponds to the player start location
            var connectivityModel = hallsGen.GraphModel;

            LogFile.Log.LogEntryDebug("PC start vertex: " + connectivityModel.StartVertex, LogDebugLevel.High);

            DoorClueGraphvizExport visualiser = new DoorClueGraphvizExport(connectivityModel);
            visualiser.OutputClueDoorGraph("bsptree-door");
            visualiser.OutputDoorDependencyGraph("bsptree-dep");

            //We've altered the map now, so get a new copy before we store it
            hallMap = hallsGen.GetOriginalMap();
            int levelNo = Game.Dungeon.AddMap(hallMap);

            //Store the hallGen
            //Will get sorted in level order
            levelGen.Add(0, hallsGen);

            //Place the player, so monster placing can be checked against it
            //Game.Dungeon.Player.LocationLevel = 0; //on reload, don't reset this
            //needs to be done before placing items
            Game.Dungeon.Player.LocationMap = Game.Dungeon.Levels[Game.Dungeon.Player.LocationLevel].PCStartLocation;

            //Run graphviz to png the output then display
            try
            {
                var graphVizLocation = Game.Config.Entries[Config.GraphVizLocation];

                GraphVizUtils.RunGraphVizPNG(graphVizLocation, "bsptree-base");
                GraphVizUtils.RunGraphVizPNG(graphVizLocation, "bsptree-nocycles");

                GraphVizUtils.DisplayPNGInChildWindow("bsptree-base");
                GraphVizUtils.DisplayPNGInChildWindow("bsptree-nocycles");
            }
            catch (Exception)
            {
                LogFile.Log.LogEntryDebug("Can't find graphViz in config file", LogDebugLevel.High);
            }

            //Add standard dock triggers (allows map abortion & completion)
            //AddStandardEntryExitTriggers(dungeon, hallsGen, levelNo);

            //Place dock bay feature at PC startloc
            Game.Dungeon.AddFeature(new Features.DockBay(), levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation);
        }
コード例 #8
0
ファイル: RogueBase.cs プロジェクト: vrum/roguelike
        private void SetupDungeon()
        {
            //Create dungeon and set it as current in Game
            dungeon      = new Dungeon();
            Game.Dungeon = dungeon;

            //Randomer
            Random rand = new Random();

            //Create dungeon map (at least level 1)
            MapGeneratorBSP mapGen1 = new MapGeneratorBSP();

            //MapGeneratorRogue mapGen = new MapGeneratorRogue();
            mapGen1.Width  = 80;
            mapGen1.Height = 25;
            int extraCorridors = rand.Next(10);

            Map level1 = mapGen1.GenerateMap(extraCorridors);

            MapGeneratorBSP mapGen2 = new MapGeneratorBSP();

            mapGen2.Width  = 80;
            mapGen2.Height = 25;
            Map level2 = mapGen2.GenerateMap(extraCorridors);

            MapGeneratorCave cave1 = new MapGeneratorCave();

            cave1.Width  = 80;
            cave1.Height = 25;

            Map cave = cave1.GenerateMap();


            //KeyPress userKey = Keyboard.WaitForKeyPress(true);


            //Test
            //for (int i = 0; i < 10000; i++)
            //{
            //    mapGen.GenerateMap();
            //}

            //Give map to dungeon
            dungeon.AddMap(level1); //level 1
            //dungeon.AddMap(level2); //level 2

            int caveLevel = dungeon.AddMap(cave);

            cave1.AddStaircases(caveLevel);


            //Load level 3 from file
            try
            {
                MapGeneratorFromASCIIFile mapGen3 = new MapGeneratorFromASCIIFile();
                mapGen3.LoadASCIIFile("test1.txt");
                mapGen3.AddMapToDungeon();
            }
            catch (Exception ex)
            {
                MessageBox.Show("failed to add level 3: " + ex.Message);
            }
            //Setup PC
            Player player = dungeon.Player;

            player.Representation = '@';
            player.LocationMap    = level1.PCStartLocation;

            player.Hitpoints    = 100;
            player.MaxHitpoints = 100;

            //Give the player some items
            //player.PickUpItem(new Items.Potion());

            //Add a down staircase where the player is standing
            AddFeatureToDungeon(new Features.StaircaseDown(), 0, new Point(player.LocationMap.x, player.LocationMap.y));

            //Add a test short sword
            dungeon.AddItem(new Items.ShortSword(), 0, new Point(player.LocationMap.x, player.LocationMap.y));

            //Create creatures and start positions

            //Add some random creatures



            int noCreatures = rand.Next(10) + 215;

            for (int i = 0; i < noCreatures; i++)
            {
                Monster creature = new Creatures.Rat();
                creature.Representation = Convert.ToChar(65 + rand.Next(26));

                //int level = rand.Next(2);
                int   level    = 0;
                Point location = new Point(0, 0);

                //Loop until we find an acceptable location and the add works
                do
                {
                    if (level == 0)
                    {
                        location = mapGen1.RandomWalkablePoint();
                    }
                    else if (level == 1)
                    {
                        location = mapGen2.RandomWalkablePoint();
                    }
                    LogFile.Log.LogEntryDebug("Creature " + i.ToString() + " pos x: " + location.x + " y: " + location.y, LogDebugLevel.Low);
                }while (!dungeon.AddMonster(creature, level, location));
            }

            //Create features

            //Add some random features

            /*
             * int noFeatures = rand.Next(5) + 2;
             *
             * for (int i = 0; i < noFeatures; i++)
             * {
             *  Features.StaircaseUp feature = new Features.StaircaseUp();
             *
             *  feature.Representation = Convert.ToChar(58 + rand.Next(6));
             *  AddFeatureToDungeon(feature, mapGen1, 0);
             * }*/

            //Add staircases to dungeons level 1 and 2
            AddFeatureToDungeonRandomPoint(new Features.StaircaseDown(), mapGen1, 0);
            //AddFeatureToDungeonRandomPoint(new Features.StaircaseUp(), mapGen2, 1);


            //Create objects and start positions

            //Add some random objects

            int noItems = rand.Next(10) + 5;

            for (int i = 0; i < noItems; i++)
            {
                Item item;

                if (rand.Next(2) < 1)
                {
                    item = new Items.Potion();
                }
                else
                {
                    item = new Items.ShortSword();
                }

                //item.Representation = Convert.ToChar(33 + rand.Next(12));

                int   level = 0;
                Point location;

                //Loop until we find an acceptable location and the add works
                do
                {
                    location = mapGen1.RandomWalkablePoint();
                }while (!dungeon.AddItem(item, level, location));
            }
        }
コード例 #9
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        private void SpawnItemsLevel1(int levelIndex, MapGeneratorBSP mapGen)
        {
            List<RoomCoords> allRooms = mapGen.GetAllRooms();

            //Spawn some items
            List<Item> itemsToPlace = new List<Item>();
            itemsToPlace.Add(new Items.Pistol());

            AddItemsEqualDistribution(itemsToPlace, levelIndex, mapGen);
        }
コード例 #10
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        private void SpawnCreaturesRandomly(int levelIndex, MapGeneratorBSP mapGen)
        {
            //Monster catalogue

            //Type of monster : typical group size

            //Melee monsters

            List<KeyValuePair<Monster, int>> meleeMonsters = new List<KeyValuePair<Monster, int>>();
            meleeMonsters.Add(new KeyValuePair<Monster, int>(new Creatures.Swarmer(), 6));
            meleeMonsters.Add(new KeyValuePair<Monster, int>(new Creatures.Juggernaut(), 1));

            //Patrolling catalogue

            List<KeyValuePair<Monster, int>> patrolMonsters = new List<KeyValuePair<Monster, int>>();
            patrolMonsters.Add(new KeyValuePair<Monster, int>(new Creatures.PatrolBot(), 3));
            patrolMonsters.Add(new KeyValuePair<Monster, int>(new Creatures.PatrolBotArea(), 3));

            //Rotating catalogue

            List<KeyValuePair<Monster, int>> staticMonsters = new List<KeyValuePair<Monster, int>>();
            staticMonsters.Add(new KeyValuePair<Monster, int>(new Creatures.RotatingTurret(), 2));
            staticMonsters.Add(new KeyValuePair<Monster, int>(new Creatures.CombatBot(), 3));

            //Special monsters
            List<KeyValuePair<Monster, int>> specialMonsters = new List<KeyValuePair<Monster, int>>();
            specialMonsters.Add(new KeyValuePair<Monster, int>(new Creatures.AlertBot(), 2));
            specialMonsters.Add(new KeyValuePair<Monster, int>(new Creatures.RollingBomb(), 2));

            List<List<KeyValuePair<Monster, int>>> monsterCatalogue = new List<List<KeyValuePair<Monster, int>>>();
            monsterCatalogue.Add(meleeMonsters);
            monsterCatalogue.Add(patrolMonsters);
            monsterCatalogue.Add(staticMonsters);
            //Grenades go in last to suck up any left-over budget
            monsterCatalogue.Add(specialMonsters);

            //Calculate the budget we have to spend

            //An 10 cost item (pistol) is good for 30 - 40 points of monster

            //Item budget: 50 + (levelIndex - 5) * 10;

            int creatureBudget = (50 + (levelIndex - 5) * 10) * 3;

            //Divide between different types

            List<double> budgetRatios = new List<double>();

            //Initialize

            budgetRatios.Add(Game.Random.NextDouble());
            budgetRatios.Add(Game.Random.NextDouble());
            budgetRatios.Add(Game.Random.NextDouble());
            budgetRatios.Add(Game.Random.NextDouble());

            //Try to spend 2/3 of our budget on one type
            //(+3 was too much at present)

            //exclude special
            budgetRatios[Game.Random.Next(budgetRatios.Count - 1)] += 1.5;

            //Calculate budget split
            double totalRatio = 0.0;
            foreach (double d in budgetRatios)
            {
                totalRatio += d;
            }

            double ratioToTotalBudget = creatureBudget / totalRatio;

            double remainder = 0.0;

            //To hold all the items to place
            List<Monster> monstersToPlaceEvenly = new List<Monster>();
            List<MonsterFightAndRunAI> monstersToPlaceLinearPatrol = new List<MonsterFightAndRunAI>();
            List<MonsterFightAndRunAI> monstersToPlaceSquarePatrol = new List<MonsterFightAndRunAI>();

            //Spend budget on each catalogue, depending upon ratio
            for (int i = 0; i < monsterCatalogue.Count; i++)
            {
                double categoryBudget = budgetRatios[i] * ratioToTotalBudget + remainder;
                remainder = (double)SpendMonsterBudget((int)categoryBudget, monsterCatalogue[i], monstersToPlaceEvenly, monstersToPlaceLinearPatrol, monstersToPlaceSquarePatrol);
            }

            LogFile.Log.LogEntryDebug("SpawnCreaturesRandomly: level: " + levelIndex + " total budget: " + creatureBudget + " remainder: " + remainder, LogDebugLevel.High);

            //Actually add the monsters
            List<RoomCoords> allRooms = mapGen.GetAllRooms();

            AddMonstersEqualDistribution(monstersToPlaceEvenly, levelIndex, mapGen);
            foreach (MonsterFightAndRunAI m in monstersToPlaceLinearPatrol)
                AddMonsterLinearPatrol(m, levelIndex, mapGen);

            foreach (MonsterFightAndRunAI m in monstersToPlaceSquarePatrol)
                AddMonsterSquarePatrol(m, levelIndex, mapGen);

            //This sets light level in the creatures
            SetLightLevelUniversal(levelIndex, levelIndex, 5);
        }
コード例 #11
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        private void SpawnCreaturesLevel6(int level, MapGeneratorBSP mapGen)
        {
            //Level 2 just Swarmers (but lots of them)
            List<Monster> monstersToPlace = new List<Monster>();

            for (int i = 0; i < 5; i++)
            {
                Creatures.CombatBot patrolBot = new Creatures.CombatBot();
                monstersToPlace.Add(patrolBot);
            }

            for (int i = 0; i < 6; i++)
            {
                Creatures.PatrolBotArea patrolBot = new Creatures.PatrolBotArea();
                AddMonsterSquarePatrol(patrolBot, level, mapGen);
            }

            monstersToPlace.Add(new Creatures.AlertBot());

               // AddMonsterLinearPatrol(new Creatures.Juggernaut(), level, mapGen);

            AddMonstersEqualDistribution(monstersToPlace, level, mapGen);

            //This sets light level in the creatures
            SetLightLevelUniversal(level, level, 5);
        }
コード例 #12
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        private void SpawnCreaturesLevel5(int level, MapGeneratorBSP mapGen)
        {
            //Level 2 just Swarmers (but lots of them)
            List<Monster> monstersToPlace = new List<Monster>();

            for (int i = 0; i < 5; i++)
            {
                Creatures.Swarmer patrolBot = new Creatures.Swarmer();
                monstersToPlace.Add(patrolBot);
            }

            for (int i = 0; i < 3; i++)
            {
                Creatures.PatrolBot patrolBot = new Creatures.PatrolBot();
                AddMonsterLinearPatrol(patrolBot, level, mapGen);

            }
            for (int i = 0; i < 3; i++)
            {
                Creatures.RollingBomb patrolBot = new Creatures.RollingBomb();
                monstersToPlace.Add(patrolBot);
            }

            AddMonstersEqualDistribution(monstersToPlace, level, mapGen);

            //This sets light level in the creatures
            SetLightLevelUniversal(level, level, 5);
        }
コード例 #13
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        private void SpawnCreaturesLevel1(int level, MapGeneratorBSP mapGen)
        {
            //Level 1 just Linear Patrol Bots

            for (int i = 0; i < 6; i++)
            {
                Creatures.PatrolBot patrolBot = new Creatures.PatrolBot();
                AddMonsterLinearPatrol(patrolBot, level, mapGen);
            }

            //This sets light level in the creatures
            SetLightLevelUniversal(level, level, 5);
        }
コード例 #14
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        private static void AddStandardEntryExitTriggers(Dungeon dungeon, MapGeneratorBSP hallsGen, int levelNo)
        {
            List<Point> surroundingDock = hallsGen.GetEntryDoor();
            foreach(Point p in surroundingDock)
                Game.Dungeon.AddTrigger(levelNo, p, new Triggers.DockDoor());

            //Add exit trigger
            Game.Dungeon.AddTrigger(levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation, new Triggers.LeaveByDock());
        }
コード例 #15
0
ファイル: RogueBase.cs プロジェクト: Sinellil/roguelike-cs
        /// <summary>
        /// Add a feature to the dungeon. Guarantees an acceptable placement.
        /// Might loop forever if all squares in the dungeon are already taken up
        /// </summary>
        /// <param name="feature"></param>
        /// <param name="level"></param>
        /// <param name="location"></param>
        void AddFeatureToDungeonRandomPoint(Feature feature, MapGeneratorBSP mapGen, int level)
        {
            Point location;
            //Loop until we find an acceptable location and the add works
            do
            {
                location = mapGen.RandomWalkablePoint();

            }
            while (!dungeon.AddFeature(feature, level, location));
        }
コード例 #16
0
ファイル: RogueBase.cs プロジェクト: Sinellil/roguelike-cs
        private void SetupDungeon()
        {
            //Create dungeon and set it as current in Game
            dungeon = new Dungeon();
            Game.Dungeon = dungeon;

            //Randomer
            Random rand = new Random();

            //Create dungeon map (at least level 1)
            MapGeneratorBSP mapGen1 = new MapGeneratorBSP();
            //MapGeneratorRogue mapGen = new MapGeneratorRogue();
            mapGen1.Width = 80;
            mapGen1.Height = 25;
            int extraCorridors = rand.Next(10);

            Map level1 = mapGen1.GenerateMap(extraCorridors);

            MapGeneratorBSP mapGen2 = new MapGeneratorBSP();
            mapGen2.Width = 80;
            mapGen2.Height = 25;
            Map level2 = mapGen2.GenerateMap(extraCorridors);

            MapGeneratorCave cave1 = new MapGeneratorCave();
            cave1.Width = 80;
            cave1.Height = 25;

            Map cave = cave1.GenerateMap();

            //KeyPress userKey = Keyboard.WaitForKeyPress(true);

            //Test
            //for (int i = 0; i < 10000; i++)
            //{
            //    mapGen.GenerateMap();
            //}

            //Give map to dungeon
            dungeon.AddMap(level1); //level 1
            //dungeon.AddMap(level2); //level 2

            int caveLevel = dungeon.AddMap(cave);
            cave1.AddStaircases(caveLevel);

            //Load level 3 from file
            try
            {
                MapGeneratorFromASCIIFile mapGen3 = new MapGeneratorFromASCIIFile();
                mapGen3.LoadASCIIFile("test1.txt");
                mapGen3.AddMapToDungeon();
            }
            catch (Exception ex)
            {
                MessageBox.Show("failed to add level 3: " + ex.Message);
            }
            //Setup PC
            Player player = dungeon.Player;

            player.Representation = '@';
            player.LocationMap = level1.PCStartLocation;

            player.Hitpoints = 100;
            player.MaxHitpoints = 100;

            //Give the player some items
            //player.PickUpItem(new Items.Potion());

            //Add a down staircase where the player is standing
            AddFeatureToDungeon(new Features.StaircaseDown(), 0, new Point(player.LocationMap.x, player.LocationMap.y));

            //Add a test short sword
            dungeon.AddItem(new Items.ShortSword(), 0, new Point(player.LocationMap.x, player.LocationMap.y));

            //Create creatures and start positions

            //Add some random creatures

            int noCreatures = rand.Next(10) + 215;

            for (int i = 0; i < noCreatures; i++)
            {
                Monster creature = new Creatures.Rat();
                creature.Representation = Convert.ToChar(65 + rand.Next(26));

                //int level = rand.Next(2);
                int level = 0;
                Point location = new Point(0, 0);

                //Loop until we find an acceptable location and the add works
                do
                {
                    if (level == 0)
                        location = mapGen1.RandomWalkablePoint();
                    else if (level == 1)
                        location = mapGen2.RandomWalkablePoint();
                    LogFile.Log.LogEntryDebug("Creature " + i.ToString() + " pos x: " + location.x + " y: " + location.y, LogDebugLevel.Low);
                }
                while (!dungeon.AddMonster(creature, level, location));
            }

            //Create features

            //Add some random features
            /*
            int noFeatures = rand.Next(5) + 2;

            for (int i = 0; i < noFeatures; i++)
            {
                Features.StaircaseUp feature = new Features.StaircaseUp();

                feature.Representation = Convert.ToChar(58 + rand.Next(6));
                AddFeatureToDungeon(feature, mapGen1, 0);
            }*/

            //Add staircases to dungeons level 1 and 2
            AddFeatureToDungeonRandomPoint(new Features.StaircaseDown(), mapGen1, 0);
            //AddFeatureToDungeonRandomPoint(new Features.StaircaseUp(), mapGen2, 1);

            //Create objects and start positions

            //Add some random objects

            int noItems = rand.Next(10) + 5;

            for (int i = 0; i < noItems; i++)
            {
                Item item;

                if (rand.Next(2) < 1)
                {
                    item = new Items.Potion();
                }
                else
                {
                    item = new Items.ShortSword();
                }

                //item.Representation = Convert.ToChar(33 + rand.Next(12));

                int level = 0;
                Point location;

                //Loop until we find an acceptable location and the add works
                do
                {
                    location = mapGen1.RandomWalkablePoint();
                }
                while (!dungeon.AddItem(item, level, location));
            }
        }
コード例 #17
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        private void SpawnItemsLevel2(int levelIndex, MapGeneratorBSP mapGen)
        {
            List<RoomCoords> allRooms = mapGen.GetAllRooms();

            //Spawn some items

            List<Item> itemsToPlace = new List<Item>();

            //Tempt the player with the shotgun
            //AddItemCloseToLocation(new Items.Shotgun(), 0, mapGen.GetPlayerStartLocation());
            AddItemAtLocation(new Items.Shotgun(), levelIndex, mapGen.GetPlayerStartLocation());

            //Vibroblade is a better choice
            itemsToPlace.Add(new Items.Vibroblade());
            //Another shotty
            itemsToPlace.Add(new Items.Shotgun());

            AddItemsEqualDistribution(itemsToPlace, levelIndex, mapGen);
        }
コード例 #18
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        private void SpawnItemsLevel4(int levelIndex, MapGeneratorBSP mapGen)
        {
            List<RoomCoords> allRooms = mapGen.GetAllRooms();

            //Pistol at start location
            AddItemAtLocation(new Items.Pistol(), levelIndex, mapGen.GetPlayerStartLocation());

            //Spawn some items

            List<Item> itemsToPlace = new List<Item>();

            itemsToPlace.Add(new Items.SoundGrenade());
            itemsToPlace.Add(new Items.SoundGrenade());
            itemsToPlace.Add(new Items.SoundGrenade());
            itemsToPlace.Add(new Items.SoundGrenade());
            itemsToPlace.Add(new Items.FragGrenade());
            itemsToPlace.Add(new Items.FragGrenade());

            itemsToPlace.Add(new Items.NanoRepair());

            AddItemsEqualDistribution(itemsToPlace, levelIndex, mapGen);
        }
コード例 #19
0
ファイル: DungeonMaker.cs プロジェクト: Sinellil/roguelike-cs
        /// <summary>
        /// Adds levels and interconnecting staircases
        /// </summary>
        private void SetupMapsGraphingDemo(bool doLocks, int noLocks)
        {
            Dungeon dungeon = Game.Dungeon;

            MapGeneratorBSP hallsGen = new MapGeneratorBSP();
            hallsGen.NoSplitChance = 3;
            //Clip to 60
            hallsGen.Width = 40;
            if(doLocks)
                hallsGen.Width = 50;
            hallsGen.Height = 25;

            hallsGen.GenerateMap(0);

            MapModel connectivityModel = null;

            if (doLocks)
            {
                //Optionally add door locks

                //Firstly find the node in the reduced map that corresponds to the player start location
                connectivityModel = hallsGen.GraphModel;

                int startNode = connectivityModel.StartVertexNoCycleMap;
                LogFile.Log.LogEntryDebug("PC start vertex: " + startNode, LogDebugLevel.High);

                connectivityModel.LockRandomEdgeRandomClue("red");

                if (noLocks > 1)
                {
                    connectivityModel.LockRandomEdgeRandomClue("green");
                    connectivityModel.LockRandomEdgeRandomClue("blue");
                    connectivityModel.LockRandomEdgeRandomClue("yellow");
                }

                var visualiser = new DoorClueGraphvizExport(connectivityModel);
                visualiser.OutputClueDoorGraph("bsptree-door");
                visualiser.OutputDoorDependencyGraph("bsptree-dep");

                //Find the doors corresponding to locked connections and lock them
                foreach (var door in connectivityModel.DoorAndClueManager.DoorMap)
                {
                    //The door knows its location in the full map, so this should work with cycles
                    hallsGen.LockConnection(door.Value);
                }
            }

            //Add map to dungeon
            int levelNo = Game.Dungeon.AddMap(hallsGen.BaseMap);
            //Add locks to dungeon as simple doors
            foreach (var locksInLocation in hallsGen.MapSquareLocks)
            {
                var lockLocation = locksInLocation.Key;
                foreach(var thisLock in locksInLocation.Value) {
                    var lockedDoor = new Locks.SimpleLockedDoor(thisLock);

                    lockedDoor.LocationLevel = levelNo;
                    lockedDoor.LocationMap = lockLocation;
                    Game.Dungeon.AddLock(lockedDoor);
                }
            }

            //Place the player, so monster placing can be checked against it
            //Game.Dungeon.Player.LocationLevel = 0; //on reload, don't reset this
            //needs to be done before placing items
            Game.Dungeon.Player.LocationMap = Game.Dungeon.Levels[Game.Dungeon.Player.LocationLevel].PCStartLocation;
            if (doLocks)
            {
                //Find a random room corresponding to a vertex with a clue and place a clue there
                foreach (var cluesAtVertex in connectivityModel.DoorAndClueManager.ClueMap)
                {
                    foreach (var clue in cluesAtVertex.Value)
                    {
                        var possibleRooms = clue.PossibleClueRoomsInFullMap;
                        var randomRoom = possibleRooms[Game.Random.Next(possibleRooms.Count)];

                        var pointInRoom = hallsGen.RandomPointInRoomById(randomRoom);

                        Game.Dungeon.AddItem(new Items.Clue(clue), 0, pointInRoom.GetPointInRoomOnly());
                    }

                }
            }

            //Run graphviz to png the output then display
            try {
                var graphVizLocation = Game.Config.Entries[Config.GraphVizLocation];

                GraphVizUtils.RunGraphVizPNG(graphVizLocation, "bsptree-base");

                GraphVizUtils.DisplayPNGInChildWindow("bsptree-base");

                if (doLocks)
                {
                    GraphVizUtils.RunGraphVizPNG(graphVizLocation, "bsptree-door");
                    GraphVizUtils.RunGraphVizPNG(graphVizLocation, "bsptree-dep");
                    GraphVizUtils.DisplayPNGInChildWindow("bsptree-door");
                    GraphVizUtils.DisplayPNGInChildWindow("bsptree-dep");
                }
            }
            catch(Exception) {
                LogFile.Log.LogEntryDebug("Can't find graphViz in config file", LogDebugLevel.High);
            }

            //Add standard dock triggers (allows map abortion & completion)
            //AddStandardEntryExitTriggers(dungeon, hallsGen, levelNo);

            //Setup pathfinding
            CalculateWalkableAndTCOD();

            //Place dock bay feature at PC startloc
            Game.Dungeon.AddFeature(new Features.DockBay(), levelNo, Game.Dungeon.Levels[levelNo].PCStartLocation);
        }