예제 #1
0
        public Map(int width, int height)
        {
            this.width = width;
            this.height = height;

            mapSquares = new MapSquare[width, height];
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    mapSquares[i, j] = new MapSquare();
                }
            }

            Clear();
        }
예제 #2
0
파일: Dungeon.cs 프로젝트: vrum/roguelike
        /// <summary>
        /// Displays the creature FOV on the map. Note that this clobbers the FOV map
        /// </summary>
        /// <param name="creature"></param>
        public void ShowCreatureFOVOnMap(Creature creature)
        {
            //Only do this if the creature is on a visible level
            if (creature.LocationLevel != Player.LocationLevel)
            {
                return;
            }

            Map     currentMap = levels[creature.LocationLevel];
            TCODFov tcodFOV    = levelTCODMaps[creature.LocationLevel];

            //Calculate FOV
            tcodFOV.CalculateFOV(creature.LocationMap.x, creature.LocationMap.y, creature.SightRadius);

            //Only check sightRadius around the creature

            int xl = creature.LocationMap.x - creature.SightRadius;
            int xr = creature.LocationMap.x + creature.SightRadius;

            int yt = creature.LocationMap.y - creature.SightRadius;
            int yb = creature.LocationMap.y + creature.SightRadius;

            //If sight is infinite, check all the map
            if (creature.SightRadius == 0)
            {
                xl = 0;
                xr = currentMap.width;
                yt = 0;
                yb = currentMap.height;
            }

            if (xl < 0)
            {
                xl = 0;
            }
            if (xr >= currentMap.width)
            {
                xr = currentMap.width - 1;
            }
            if (yt < 0)
            {
                yt = 0;
            }
            if (yb >= currentMap.height)
            {
                yb = currentMap.height - 1;
            }

            for (int i = xl; i <= xr; i++)
            {
                for (int j = yt; j <= yb; j++)
                {
                    MapSquare thisSquare = currentMap.mapSquares[i, j];
                    bool      inFOV      = tcodFOV.CheckTileFOV(i, j);
                    if (inFOV)
                    {
                        thisSquare.InMonsterFOV = true;
                    }
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Adds the complete map to the dungeon. Throw exception on failure, but shouldn't fail
        /// </summary>
        /// <returns></returns>
        public void AddMapToDungeon()
        {
            if (!fileLoaded)
            {
                LogFile.Log.LogEntry("MapGeneratorFromASCIIFile::AddMapToDungeon: No map loaded");
                throw new ApplicationException("No map loaded");
            }

            baseMap = new Map(width, height);

            baseMap.LightLevel = 0;

            int row = 0;

            //Sort out the terrain first
            //Features and special areas are empty

            foreach (string mapRow in storedMapRows)
            {
                for (int i = 0; i < width; i++)
                {
                    char mapChar = mapRow[i];

                    MapTerrain thisTerrain;
                    MapSquare  thisSquare = baseMap.mapSquares[i, row];

                    //if this square is terrain
                    if (terrainMapping.ContainsKey(mapChar))
                    {
                        thisTerrain = terrainMapping[mapChar];
                    }
                    else
                    {
                        //if this square is a feature or special
                        //hack
                        if (mapFilename.Contains("last"))
                        {
                            thisTerrain = MapTerrain.Grass;
                        }
                        else
                        {
                            thisTerrain = MapTerrain.Empty;
                        }
                    }

                    //Set terrain and features
                    thisSquare.Terrain = thisTerrain;

                    //This should be done in the map gen functions - right now dungeon does a bit of it too
                    switch (thisTerrain)
                    {
                    case MapTerrain.Wall:
                    case MapTerrain.Void:
                        thisSquare.Walkable    = false;
                        thisSquare.BlocksLight = true;
                        break;

                    case MapTerrain.Empty:
                        thisSquare.Walkable    = true;
                        thisSquare.BlocksLight = false;
                        break;

                    case MapTerrain.Mountains:
                        thisSquare.Walkable    = false;
                        thisSquare.BlocksLight = true;
                        break;

                    case MapTerrain.Trees:
                        thisSquare.Walkable    = true;
                        thisSquare.BlocksLight = false;
                        break;

                    case MapTerrain.River:
                        thisSquare.Walkable    = false;
                        thisSquare.BlocksLight = false;
                        break;

                    case MapTerrain.Road:
                        thisSquare.Walkable    = true;
                        thisSquare.BlocksLight = false;
                        break;

                    case MapTerrain.Grass:
                        thisSquare.Walkable    = true;
                        thisSquare.BlocksLight = false;
                        break;

                    case MapTerrain.Gravestone:
                        thisSquare.Walkable    = true;
                        thisSquare.BlocksLight = false;
                        break;

                    case MapTerrain.Forest:
                        thisSquare.Walkable    = false;
                        thisSquare.BlocksLight = true;
                        break;
                    }
                }

                row++;
            }

            //Add the (terrain complete) map to the dungeon before adding features and specials
            int levelNo = Game.Dungeon.AddMap(baseMap);

            //Sort out features

            row = 0;

            foreach (string mapRow in storedMapRows)
            {
                for (int i = 0; i < width; i++)
                {
                    char mapChar = mapRow[i];

                    if (featureChars.Contains(mapChar))
                    {
                        bool featureAddSuccess = false;
                        switch (mapChar)
                        {
                        case '~':
                            //featureAddSuccess = Game.Dungeon.AddFeature(new Features.StaircaseEntry(Game.Dungeon.DungeonInfo Dungeon1StartLevel), levelNo, new Point(i, row));
                            break;

                        case '/':
                            //featureAddSuccess = Game.Dungeon.AddFeature(new Features.StaircaseEntry(Game.Dungeon.Dungeon2StartLevel), levelNo, new Point(i, row));
                            break;

                        case '<':
                            //featureAddSuccess = Game.Dungeon.AddFeature(new Features.StaircaseUp(), levelNo, new Point(i, row));
                            break;
                        }

                        if (!featureAddSuccess)
                        {
                            LogFile.Log.LogEntry("MapGeneratorFromASCIIFile::AddMapToDungeon: Failed to add terrain feature");
                            throw new ApplicationException("Failed to add feature");
                        }
                    }
                }

                row++;
            }

            //Sort out special characters

            row = 0;

            foreach (string mapRow in storedMapRows)
            {
                for (int i = 0; i < width; i++)
                {
                    char mapChar = mapRow[i];

                    if (specialChars.Contains(mapChar))
                    {
                        bool addingSuccess = true;

                        switch (mapChar)
                        {
                        //PC start location is meaningless for everything except the first level
                        case 'x':
                            baseMap.PCStartLocation = new Point(i, row);
                            break;

                        case '1':
                            Game.Dungeon.AddTrigger(levelNo, new Point(i, row), new Triggers.BackToSchool());
                            break;

                        case '2':
                            addingSuccess = Game.Dungeon.AddFeature(new Features.StaircaseEntry(0, Game.Dungeon.DungeonInfo.GetDungeonStartLevel(0)), levelNo, new Point(i, row));
                            break;

                        case '3':
                            addingSuccess = Game.Dungeon.AddFeature(new Features.StaircaseEntry(1, Game.Dungeon.DungeonInfo.GetDungeonStartLevel(1)), levelNo, new Point(i, row));
                            break;

                        case '4':
                            addingSuccess = Game.Dungeon.AddFeature(new Features.StaircaseEntry(2, Game.Dungeon.DungeonInfo.GetDungeonStartLevel(2)), levelNo, new Point(i, row));
                            break;

                        case '5':
                            addingSuccess = Game.Dungeon.AddFeature(new Features.StaircaseEntry(3, Game.Dungeon.DungeonInfo.GetDungeonStartLevel(3)), levelNo, new Point(i, row));
                            break;

                        case '6':
                            addingSuccess = Game.Dungeon.AddFeature(new Features.StaircaseEntry(4, Game.Dungeon.DungeonInfo.GetDungeonStartLevel(4)), levelNo, new Point(i, row));
                            break;

                        case '7':
                            addingSuccess = Game.Dungeon.AddFeature(new Features.StaircaseEntry(5, Game.Dungeon.DungeonInfo.GetDungeonStartLevel(5)), levelNo, new Point(i, row));
                            break;

                        case '8':
                            addingSuccess = Game.Dungeon.AddFeature(new Features.StaircaseEntry(6, Game.Dungeon.DungeonInfo.GetDungeonStartLevel(6)), levelNo, new Point(i, row));
                            break;

                        case 'A':
                            Game.Dungeon.AddTrigger(levelNo, new Point(i, row), new Triggers.TerrainFlipTrigger(MapTerrain.Road, "river"));
                            baseMap.mapSquares[i, row].Terrain = MapTerrain.River;
                            break;

                        case 'B':
                            Game.Dungeon.AddTrigger(levelNo, new Point(i, row), new Triggers.TerrainFlipTrigger(MapTerrain.Trees, "forest"));
                            baseMap.mapSquares[i, row].Terrain = MapTerrain.Forest;
                            break;

                        case 'C':
                            Game.Dungeon.AddTrigger(levelNo, new Point(i, row), new Triggers.TerrainFlipTrigger(MapTerrain.Empty, "grave"));
                            baseMap.mapSquares[i, row].Terrain = MapTerrain.Mountains;
                            break;

                        case 'D':
                            Game.Dungeon.AddTrigger(levelNo, new Point(i, row), new Triggers.TerrainFlipTrigger(MapTerrain.Empty, "final"));
                            baseMap.mapSquares[i, row].Terrain = MapTerrain.Mountains;
                            break;

                        //case '%':
                        //  Game.Dungeon.AddDecorationFeature(new Features.Corpse(), levelNo, new Point(i, row));
                        //break;
                        case 'Y':
                            //Game.Dungeon.AddMonster(new Creatures.Lich(), levelNo, new Point(i, row));
                            break;

                        case 'G':
                            Game.Dungeon.AddMonster(new Creatures.Friend(), levelNo, new Point(i, row));
                            break;
                        }

                        if (!addingSuccess)
                        {
                            LogFile.Log.LogEntry("MapGeneratorFromASCIIFile::AddMapToDungeon: Failed to add special terrain feature");
                            throw new ApplicationException("Failed to add feature");
                        }
                    }
                }

                row++;
            }
        }
예제 #4
0
        /// <summary>
        /// Adds the complete map to the dungeon. Throw exception on failure, but shouldn't fail
        /// </summary>
        /// <returns></returns>
        public void AddMapToDungeon()
        {
            if (!fileLoaded)
            {
                LogFile.Log.LogEntry("MapGeneratorFromASCIIFile::AddMapToDungeon: No map loaded");
                throw new ApplicationException("No map loaded");
            }

            baseMap = new Map(width, height);

            int row = 0;

            //Sort out the terrain first
            //Features and special areas are empty

            foreach (string mapRow in storedMapRows)
            {
                for (int i = 0; i < width; i++)
                {
                    char mapChar = mapRow[i];

                    MapTerrain thisTerrain;
                    MapSquare  thisSquare = baseMap.mapSquares[i, row];

                    //if this square is terrain
                    if (terrainMapping.ContainsKey(mapChar))
                    {
                        thisTerrain = terrainMapping[mapChar];
                    }
                    else
                    {
                        //if this square is a feature or special
                        thisTerrain = MapTerrain.Empty;
                    }

                    //Set terrain and features
                    thisSquare.Terrain = thisTerrain;

                    //This should be done in the map gen functions - right now dungeon does a bit of it too
                    switch (thisTerrain)
                    {
                    case MapTerrain.Wall:
                    case MapTerrain.Void:
                        thisSquare.Walkable    = false;
                        thisSquare.BlocksLight = true;
                        break;

                    case MapTerrain.Empty:
                        thisSquare.Walkable    = true;
                        thisSquare.BlocksLight = false;
                        break;
                    }
                }

                row++;
            }

            //Add the (terrain complete) map to the dungeon before adding features and specials
            int levelNo = Game.Dungeon.AddMap(baseMap);

            //Sort out features

            row = 0;

            foreach (string mapRow in storedMapRows)
            {
                for (int i = 0; i < width; i++)
                {
                    char mapChar = mapRow[i];

                    if (featureChars.Contains(mapChar))
                    {
                        bool featureAddSuccess = false;
                        switch (mapChar)
                        {
                        case '>':
                            featureAddSuccess = Game.Dungeon.AddFeature(new Features.StaircaseDown(), levelNo, new Point(i, row));
                            break;

                        case '<':
                            featureAddSuccess = Game.Dungeon.AddFeature(new Features.StaircaseUp(), levelNo, new Point(i, row));
                            break;
                        }

                        if (!featureAddSuccess)
                        {
                            LogFile.Log.LogEntry("MapGeneratorFromASCIIFile::AddMapToDungeon: Failed to add terrain feature");
                            throw new ApplicationException("Failed to add feature");
                        }
                    }
                }

                row++;
            }

            //Sort out special characters
            foreach (string mapRow in storedMapRows)
            {
                for (int i = 0; i < width; i++)
                {
                    char mapChar = mapRow[i];

                    if (specialChars.Contains(mapChar))
                    {
                        switch (mapChar)
                        {
                        //PC start location is meaningless for everything except the first level
                        case 'x':
                            baseMap.PCStartLocation = new Point(i, row);
                            break;
                        }
                    }
                }

                row++;
            }
        }