Class MapGraph

  • All Implemented Interfaces:
    com.badlogic.gdx.ai.pfa.Graph<Junction>, com.badlogic.gdx.ai.pfa.indexed.IndexedGraph<Junction>

    public class MapGraph
    extends java.lang.Object
    implements com.badlogic.gdx.ai.pfa.indexed.IndexedGraph<Junction>
    This class creates a MapGraph which contains all junctions and connections between them. It is also used to find a path between two junctions and keep track of which roads are being travelled on by patrols
    • Constructor Detail

      • MapGraph

        public MapGraph()
    • Method Detail

      • findPath

        public com.badlogic.gdx.ai.pfa.GraphPath<Junction> findPath​(Junction startJunction,
                                                                    Junction goalJunction)
        This finds the path from the startJunction to the goalJunction
        Parameters:
        startJunction - starting junction
        goalJunction - finishing junction
        Returns:
        path of junctions needed to get from the startJunction to the goalJunction
      • getRoad

        public Road getRoad​(Junction fromJunction,
                            Junction toJunction)
        Gets road between two junction
        Parameters:
        fromJunction - first junction
        toJunction - second junction
        Returns:
        returns a road going from fromJunction to toJunction
      • addJunction

        public void addJunction​(Junction junction)
        Adds a junction to junctions
        Parameters:
        junction - junction to add
      • connectJunctions

        public void connectJunctions​(Junction fromJunction,
                                     Junction toJunction)
        This creates a road from fromJunction to toJunction and adds it to roads. It also adds this road to connectionsFromJunctionMap which keeps track of which connections you can take from each junction
        Parameters:
        fromJunction - one end of the road - the end the patrol starts at
        toJunction - the other end of the road - the end the patrol ends at
      • getConnections

        public com.badlogic.gdx.utils.Array<com.badlogic.gdx.ai.pfa.Connection<Junction>> getConnections​(Junction fromNode)
        This returns the connections you can take from the fromNode
        Specified by:
        getConnections in interface com.badlogic.gdx.ai.pfa.Graph<Junction>
        Parameters:
        fromNode - The node you want to find possible connections from
        Returns:
        Array An array of the connections you could take from fromNode - returns an empty array if there are no connections
      • isRoadLocked

        public boolean isRoadLocked​(Junction from,
                                    Junction to)
        Checks if a patrol is travelling on the road between fromJunction to toJunction. Have to check the road in both directions otherwise the patrols can collide head on
        Parameters:
        from - The junction at one end of the road
        to - The junction at the other end of the road
        Returns:
        true if another Patrol is travelling on that road (knows this because the road is present in lockedRoads) false if no Patrol is travelling on that road
      • lockRoad

        public void lockRoad​(Road road,
                             PatrolMovementSprite patrol)
        Locks a road by a patrol if that road is not already locked
        Parameters:
        road - The road to lock
        patrol - The patrol who locked that road - the only patrol who can unlock it
      • unlockRoad

        public void unlockRoad​(Road road,
                               PatrolMovementSprite patrol)
        Unlocks a road if there is a road that the patrol had previously locked
        Parameters:
        road - The road to unlock
        patrol - The patrol who wants to unlock the road. Will only unlock if this is the patrol who locked the road.
      • removeDead

        public void removeDead​(PatrolMovementSprite patrol)
        Removes the road that a patrol was travelling on from locked roads when it died. Otherwise this road would still be locked after the patrol died and no other patrol would be able to travel on that road
        Parameters:
        patrol - The patrol who died
      • getJunctions

        public com.badlogic.gdx.utils.Array<Junction> getJunctions()
      • getIndex

        public int getIndex​(Junction node)
        Specified by:
        getIndex in interface com.badlogic.gdx.ai.pfa.indexed.IndexedGraph<Junction>
      • getNodeCount

        public int getNodeCount()
        Specified by:
        getNodeCount in interface com.badlogic.gdx.ai.pfa.indexed.IndexedGraph<Junction>