Пример #1
0
 internal CombatEngine(PhysicsEngine engine, Player player, Map map)
 {
     m_player = player;
     m_map = map;
     m_physicsEngine = engine;
     m_random = new Random();
 }
Пример #2
0
 public PathfindingMap(Player player, Map map)
 {
     m_player = player;
     m_map = map;
     m_physicsMap = new PhysicsMap(map.Width, map.Height);
     m_pathFinding = new AStarPathFinder(m_physicsMap, 1.41f);
 }
Пример #3
0
        internal void NewMapPlayerInfo(Player player, Map map)
        {
            m_player = player;
            m_map = map;
            m_combatEngine.NewMapPlayerInfo(player, map);

            // We have a new map, recalc LOS with a new map
            m_fovManager.UpdateNewMap(this, m_map);
            UpdatePlayerVisitedStatus();
        }
Пример #4
0
 public PhysicsEngine(Player player, Map map)
 {
     m_player = player;
     m_map = map;
     m_timingEngine = new CoreTimingEngine();
     m_fovManager = new FOVManager(this, map);
     m_combatEngine = new CombatEngine(this, player, map);
     m_movableHash = new Dictionary<Point, bool>(PointEqualityComparer.Instance);
     m_magicEffects = new MagicEffectsEngine(this, m_combatEngine);
     UpdatePlayerVisitedStatus();
 }
Пример #5
0
        // Doesn't implement all of ICloneable, just copies mapTiles
        internal void CopyMap(Map sourceMap)
        {
            if (m_width != sourceMap.m_width || m_height != sourceMap.m_height)
                throw new InvalidOperationException("CopyMap of different size");

            for (int i = 0; i < m_width; ++i)
            {
                for (int j = 0; j < m_height; ++j)
                {
                    m_map[i, j].Terrain = sourceMap.m_map[i, j].Terrain;
                }
            }
        }
Пример #6
0
        internal Character GetNextActor(Player player, Map map)
        {
            List<Character> actors = new List<Character>();
            actors.Add(player as Player);
            foreach (Monster m in map.Monsters)
            {
                actors.Add(m);
            }

            // Until we find a winner
            while (true)
            {
                // Check all valid actors for ability to go now
                Character actorWhoCanGo = actors.FirstOrDefault(a => a.CT >= TimeConstants.CTNeededForNewTurn);
                if (actorWhoCanGo != null)
                    return actorWhoCanGo;

                // No actors can go now, so incremenet each one's CT
                actors.ForEach(a => a.IncreaseCT((int)(CTPerIteration * a.CTIncreaseModifier)));
            }
        }
Пример #7
0
 // So if we're previewing the position of a blast, and we can't see the wall we're going to bounce
 // off of, don't show the bounce at all...
 internal List<Point> GenerateBlastListOfPointsShowBounceIfSeeWall(Map map, ICharacter caster, Point target)
 {
     Point wallPosition = RangedAttackPathfinder.GetWallHitByBlast(map, caster.Position, target);
     if (m_fovManager.VisibleSingleShot(map, caster.Position, caster.Vision, wallPosition))
         return RangedAttackPathfinder.RangedListOfPoints(map, caster.Position, target, true, true);
     else
         return RangedAttackPathfinder.RangedListOfPoints(map, caster.Position, target, true, false);
 }
Пример #8
0
 internal List<Point> GenerateBlastListOfPoints(Map map, Point caster, Point target, bool bounceOffWalls)
 {
     return RangedAttackPathfinder.RangedListOfPoints(map, caster, target, true, bounceOffWalls);
 }
Пример #9
0
 internal List<Point> GenerateRangedAttackListOfPoints(Map map, Point attcker, Point target)
 {
     return RangedAttackPathfinder.RangedListOfPoints(map, attcker, target, false, false);
 }
Пример #10
0
        // This is a slow operation. It should not be called multiple times in a row!
        // Call CalculateMoveablePointGrid instead~!
        public bool IsMovablePointSingleShot(Map map, Point p)
        {
            // If it's not a floor, it's not movable
            if (map.GetTerrainAt(p) != TerrainType.Floor)
                return false;

            // If there's a map object there that is solid, it's not movable
            if (map.MapObjects.SingleOrDefault(m => m.Position == p && m.IsSolid) != null)
                return false;

            // If there's a monster there, it's not movable
            if (map.Monsters.SingleOrDefault(m => m.Position == p) != null)
                return false;

            // If the player is there, it's not movable
            if (m_player.Position == p)
                return false;

            return true;
        }
Пример #11
0
        public void ReadXml(XmlReader reader)
        {
            reader.ReadStartElement();

            reader.ReadStartElement();
            string versionString = reader.ReadElementContentAsString();

            if (versionString != SaveVersion.ToString())
                throw new System.InvalidOperationException("Attemping to load bad savefile.");

            CoreGameEngine.Instance.TurnCount = reader.ReadElementContentAsInt();

            int numberOfLevelsToLoad = reader.ReadElementContentAsInt();

            int currentLevel = reader.ReadElementContentAsInt();

            Dictionary<int, Map> loadingDungeon = new Dictionary<int, Map>();
            
            for (int i = 0; i < numberOfLevelsToLoad; i++)
            {
                Map loadMap = new Map();

                reader.ReadStartElement();
                loadMap.ReadXml(reader);
                reader.ReadEndElement();
                loadingDungeon[i] = loadMap;
            }

            StairsMapping.Instance.ReadXml(reader);
            
            Player loadPlayer = new Player();
            loadPlayer.ReadXml(reader);

            CoreGameEngine.Instance.SetWithSaveData(loadPlayer, loadingDungeon, currentLevel);

            reader.ReadEndElement();
        }
Пример #12
0
 internal static Point GetWallHitByBlast(Map map, Point caster, Point target)
 {
     Point firstWall = Point.Invalid;
     RangedListOfPointsCore(map, caster, target, true, false, ref firstWall);
     return firstWall;
 }
Пример #13
0
        internal bool PlayerMoveDownStairs(Player player, Map map)
        {
            Stairs s = map.MapObjects.OfType<Stairs>().Where(x => x.Type == MapObjectType.StairsDown && x.Position == player.Position).SingleOrDefault();
            if (s != null)
            {
                if (CoreGameEngine.Instance.CurrentLevel == CoreGameEngine.Instance.NumberOfLevels - 1)
                    throw new InvalidOperationException("Win dialog should have come up instead.");
                
                // The position must come first, as changing levels checks FOV
                m_player.Position = StairsMapping.Instance.GetMapping(s.UniqueID);
                CoreGameEngine.Instance.CurrentLevel++;

                m_timingEngine.ActorMadeMove(m_player);
                return true;
            }
            return false;
        }
Пример #14
0
 // New maps might have new height/width
 public void UpdateNewMap(PhysicsEngine physicsEngine, Map map)
 {
     m_physicsMap = new PhysicsMap(map.Width, map.Height);
 }
Пример #15
0
 internal FOVManager(PhysicsEngine physicsEngine, Map map)
 {
     m_physicsMap = new PhysicsMap(map.Width, map.Height);
     m_lastCalculatedViewPoint = Point.Invalid;
     m_lastCalculatedVision = -1;
 }
Пример #16
0
        private static List<Point> GenerateListOfPointsSinglePass(Map map, Point caster, Point target, ref Point firstWall)
        {
            List<Point> returnList = new List<Point>();
            BresenhamLine lineGenerator = new BresenhamLine(caster, target);

            Point p = lineGenerator.Step();
            while (p != Point.Invalid)
            {
                if (!ValidPoint(map, p))
                {
                    firstWall = p;
                    break;
                }
                returnList.Add(p);
                p = lineGenerator.Step();
            }

            return returnList;
        }
Пример #17
0
 private static List<Point> GenerateListOfPointsSinglePass(Map map, Point caster, Point target)
 {
     Point firstWall = Point.Invalid;
     return GenerateListOfPointsSinglePass(map, caster, target, ref firstWall);
 }
Пример #18
0
        // Since c# 3.5 doens't have optional paramters, we have to wrap the method in two callers, one which uses the optional, 
        // and one that throws it away.
        private static List<Point> RangedListOfPointsCore(Map map, Point caster, Point target, bool continuePastTarget, bool bounceOffWalls, ref Point firstWall)
        {
            if (caster == target)
                return null;

            List<Point> returnList = GenerateListOfPointsSinglePass(map, caster, target);

            // The calcualted list might have caster as element 0
            if (returnList.Count > 0 && returnList[0] == caster)
                returnList.RemoveAt(0);

            if (!returnList.Contains(target))
                return null;

            if (continuePastTarget)
            {
                // { is for scoping variables
                {
                    Point delta = target - caster;
                    Point startingPoint = target;
                    Point endingPoint = target + delta;
                    while (true)
                    {
                        List<Point> listExtension = GenerateListOfPointsSinglePass(map, startingPoint, endingPoint, ref firstWall);
                        if (listExtension.Count == 0)
                            break;
                        returnList.AddRange(listExtension);
                        
                        // If our extension didn't reach the ending point, we must have hit a wall.
                        if (!listExtension.Contains(endingPoint))
                            break;

                        startingPoint = endingPoint;
                        endingPoint = endingPoint + delta;
                    }
                }

                // At this point, we know that the target was passed (we didn't return null)
                // and that we won't still till we hit a wall. To reflect, we can just bounce the last few cells
                if (bounceOffWalls)
                {
                    const int BounceLength = 3;

                    Point lastPointInList = returnList.Last();

                    // "Bounce" towards caster, but we have to be a square past past us
                    Direction directionOfBounce = PointDirectionUtils.ConvertTwoPointsToDirection(lastPointInList, caster);
                    Point spotToAimBounce = caster;
                    for (int i = 0; i < BounceLength; i++)
                    {
                        Point newSpot = PointDirectionUtils.ConvertDirectionToDestinationPoint(spotToAimBounce, directionOfBounce);
                        if (ValidPoint(map, newSpot))
                            spotToAimBounce = newSpot;
                        else
                            break;
                    }

                    List<Point> bounceList = GenerateListOfPointsSinglePass(map, lastPointInList, spotToAimBounce);
                    bounceList.Insert(0, lastPointInList);  // The starting point gets hit twice
                    for (int i = 0; i < BounceLength && bounceList.Count > i; ++i)
                        returnList.Add(bounceList[i]);
                }
            }

            return returnList;
        }
Пример #19
0
 internal static List<Point> RangedListOfPoints(Map map, Point caster, Point target, bool continuePastTarget, bool bounceOffWalls)
 {
     Point firstWall = Point.Invalid;
     return RangedListOfPointsCore(map, caster, target, continuePastTarget, bounceOffWalls, ref firstWall);
 }
Пример #20
0
        internal bool PlayerMoveUpStairs(Player player, Map map)
        {
            Stairs s = map.MapObjects.OfType<Stairs>().Where(x => x.Type == MapObjectType.StairsUp && x.Position == player.Position).SingleOrDefault();

            if (s != null)
            {
                // The position must come first, as changing levels checks FOV
                m_player.Position = StairsMapping.Instance.GetMapping(s.UniqueID);
                CoreGameEngine.Instance.CurrentLevel--;
                
                m_timingEngine.ActorMadeMove(m_player);
                return true;
            }
            return false;
        }
Пример #21
0
 internal void NewMapPlayerInfo(Player player, Map map)
 {
     m_player = player;
     m_map = map;        
 }
Пример #22
0
 // Calculate FOV for multipe Visible calls
 public void CalculateForMultipleCalls(Map map, Point viewPoint, int viewableDistance)
 {
     m_lastCalculatedViewPoint = viewPoint;
     m_lastCalculatedVision = viewableDistance;
     CalculateCore(map, viewPoint, viewableDistance);
 }
Пример #23
0
 private static bool ValidPoint(Map map, Point p)
 {
     return map.IsPointOnMap(p) && !(map.GetTerrainAt(p) == TerrainType.Wall || map.MapObjects.Where(mapObj => mapObj.IsSolid && mapObj.Position == p).Count() > 0);
 }