Ejemplo n.º 1
0
        public bool SetSquareUnwalkableIfDoorPathingIsPreserved(Point p)
        {
            if (p.x < 0 || p.y < 0 || p.x >= template.Width || p.y >= template.Height)
            {
                return(false);
            }

            //Set square unwalkable to test
            var originalTerrain = pathingMap.getCell(p.x, p.y);

            pathFinding.updateMap(0, p, PathingTerrain.Unwalkable);

            //Check all doors are pathable to each other
            bool pathable = true;

            var doors = template.PotentialDoors;

            for (int i = 0; i < doors.Count; i++)
            {
                for (int j = 0; j < doors.Count; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    if (!pathFinding.arePointsConnected(0, doors[i].Location, doors[j].Location, Pathing.PathingPermission.Normal))
                    {
                        pathable = false;
                        break;
                    }
                }
            }

            if (!pathable)
            {
                pathFinding.updateMap(0, p, originalTerrain);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        private void BuildPathableMap()
        {
            pathFinding = new LibTCOD.TCODPathFindingWrapper();

            pathingMap = new PathingMap(template.Width, template.Height);

            for (int i = 0; i < template.Width; i++)
            {
                for (int j = 0; j < template.Height; j++)
                {
                    pathingMap.setCell(i, j,
                                       RoomTemplateTerrainWalkable.terrainWalkable[template.terrainMap[i, j]] ? PathingTerrain.Walkable : PathingTerrain.Unwalkable);
                }
            }

            pathFinding.updateMap(0, pathingMap);
        }
Ejemplo n.º 3
0
        private void BuildPathableMap()
        {
            pathFinding = new LibTCOD.TCODPathFindingWrapper();

            pathingMap = new PathingMap(template.Width, template.Height);

            for (int i = 0; i < template.Width; i++)
            {
                for (int j = 0; j < template.Height; j++)
                {
                    pathingMap.setCell(i, j,
                        RoomTemplateTerrainWalkable.terrainWalkable[template.terrainMap[i, j]] ? PathingTerrain.Walkable : PathingTerrain.Unwalkable);
                }
            }

            pathFinding.updateMap(0, pathingMap);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// General pathing finding function.
        /// allDoorsAsOpen - assume all doors are open (for creatures who can open doors)
        /// </summary>
        /// <param name="level"></param>
        /// <param name="origin"></param>
        /// <param name="dest"></param>
        /// <param name="allDoorsAsOpen"></param>
        /// <param name="attackDestination"></param>
        /// <returns></returns>
        private PathingResult GetPathToPoint(int level, Point origin, Point dest, PathingPermission permission)
        {
            //Try to walk the path
            //If we fail, check if this square occupied by a creature
            //If so, make that square temporarily unwalkable and try to re-route

            List <Point> blockedSquares = new List <Point>();
            bool         goodPath       = false;
            bool         pathBlockedByCreatureOrLock = false;
            Point        nextStep    = new Point(-1, -1);
            bool         interaction = false;

            //Check for pathing to own square - return blocked but not terminally
            if (origin == dest)
            {
                LogFile.Log.LogEntryDebug("Monster trying to path to monster on same square", LogDebugLevel.High);
                return(new PathingResult(origin, false, false));
            }

            do
            {
                //Generate path object
                //We actually only need the next point here
                List <Point> pathNodes = pathFinding.pathNodes(level, origin, dest, permission);

                //No path
                if (pathNodes.Count == 1)
                {
                    //If there was no blocking creature then there is no possible route (hopefully impossible in a fully connected dungeon)
                    if (!pathBlockedByCreatureOrLock)
                    {
                        //This gets thrown a lot mainly when you cheat
                        LogFile.Log.LogEntryDebug("Path blocked by terrain!", LogDebugLevel.High);
                        return(new PathingResult(origin, false, false));
                    }
                    else
                    {
                        //All paths are blocked by creatures, we will return the origin creature's location
                        nextStep = origin;
                        //Exits loop and allows cleanup
                        break;
                    }
                }

                //Non-null, find next step (0th index is origin)
                Point theNextStep = pathNodes[1];

                //Check if that square is occupied
                Creature blockingCreature = null;

                foreach (Monster creature in dungeon.Monsters)
                {
                    if (creature.LocationLevel != level)
                    {
                        continue;
                    }

                    if (creature.LocationMap == theNextStep)
                    {
                        blockingCreature = creature;

                        //Is it at the destination? If so, that's the target creature and it is our goal.
                        if (theNextStep == dest)
                        {
                            interaction = true;
                            goodPath    = true;
                            nextStep    = origin;
                            break;
                        }
                    }
                }

                //(above break doesn't break the do, just the foreach)
                if (goodPath)
                {
                    break;
                }

                //Do the same for the player (if the creature is chasing another creature around the player)
                //Ignore if the player is the target - that's a valid move

                if (dungeon.Player.LocationLevel == level && dungeon.Player.LocationMap == theNextStep)
                {
                    //Is it at the destination? If so, that's the target creature and it is our goal.
                    if (dungeon.Player.LocationMap == theNextStep && theNextStep == dest)
                    {
                        //All OK, continue, we will return these coords
                        interaction = true;
                        nextStep    = origin;
                        break;
                    }

                    blockingCreature = dungeon.Player;
                }

                //If no blocking creature, the path is good
                if (blockingCreature == null)
                {
                    goodPath = true;
                    nextStep = theNextStep;
                }
                else
                {
                    //Otherwise, there's a blocking creature. Make his square unwalkable temporarily and try to reroute
                    pathBlockedByCreatureOrLock = true;

                    pathFinding.updateMap(level, theNextStep, PathingTerrain.Unwalkable);

                    //Add this square to a list of squares to put back
                    blockedSquares.Add(theNextStep);

                    //We will try again
                }
            } while (!goodPath);

            //Put back any squares we made unwalkable
            foreach (Point sq in blockedSquares)
            {
                pathFinding.updateMap(level, sq, PathingTerrain.Walkable);
            }

            return(new PathingResult(nextStep, interaction, false));
        }