Package com.pathFinding
Class MapGraph
- java.lang.Object
-
- com.pathFinding.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 Summary
Constructors Constructor Description MapGraph()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddJunction(Junction junction)Adds a junction to junctionsvoidconnectJunctions(Junction fromJunction, Junction toJunction)This creates a road from fromJunction to toJunction and adds it to roads.com.badlogic.gdx.ai.pfa.GraphPath<Junction>findPath(Junction startJunction, Junction goalJunction)This finds the path from the startJunction to the goalJunctioncom.badlogic.gdx.utils.Array<com.badlogic.gdx.ai.pfa.Connection<Junction>>getConnections(Junction fromNode)This returns the connections you can take from the fromNodeintgetIndex(Junction node)com.badlogic.gdx.utils.Array<Junction>getJunctions()intgetNodeCount()RoadgetRoad(Junction fromJunction, Junction toJunction)Gets road between two junctionbooleanisRoadLocked(Junction from, Junction to)Checks if a patrol is travelling on the road between fromJunction to toJunction.voidlockRoad(Road road, PatrolMovementSprite patrol)Locks a road by a patrol if that road is not already lockedvoidremoveDead(PatrolMovementSprite patrol)Removes the road that a patrol was travelling on from locked roads when it died.voidunlockRoad(Road road, PatrolMovementSprite patrol)Unlocks a road if there is a road that the patrol had previously locked
-
-
-
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 junctiongoalJunction- 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 junctiontoJunction- 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 attoJunction- 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:
getConnectionsin interfacecom.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 roadto- The junction at the other end of the road- Returns:
trueif another Patrol is travelling on that road (knows this because the road is present in lockedRoads)falseif 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 lockpatrol- 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 unlockpatrol- 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:
getIndexin interfacecom.badlogic.gdx.ai.pfa.indexed.IndexedGraph<Junction>
-
getNodeCount
public int getNodeCount()
- Specified by:
getNodeCountin interfacecom.badlogic.gdx.ai.pfa.indexed.IndexedGraph<Junction>
-
-