cz.cuni.pogamut.Client
Class PathManager

java.lang.Object
  extended by cz.cuni.pogamut.Client.PathManager
All Implemented Interfaces:
RcvMsgListener, java.util.EventListener

public class PathManager
extends java.lang.Object
implements RcvMsgListener

This class encapsulate work with paths during navigation so it is on one place and it is clearer what is going on with them
1) call either retrievePathGB() or retrievePathAStart()
2) check it's result ... if PATH_FOUND then use getPath() to get found path


3) When the path is successfully retrieved, you may then call runAlongPath() method.


Nested Class Summary
private static class PathManager.Lift
           
static class PathManager.PathResult
          Result when finding the path...
private static class PathManager.RunAlongPathState
           
static class PathManager.RunResult
          Result of the runAlongPath.
 
Field Summary
private  java.util.List<Triple> agentLocationHistory
          History of agent's location - stuck check is working over this...
private  AgentBody body
          AgentBody, we need it to be able to issue commands.
private  NeighNav edge
          Edge between navpoints we're running over.
private  NavPoint fromNavPoint
          Navpoint we're running from.
private  GameMap gameMap
          Owner of the PathManager
private  long lastAgentLocationAddedMillis
          When was the last time we've added the agent location to the history?
private  long lastJumpMillis
          When was the last time the bot has tried to jump over obstacle, millis
private  long lastPathRequestSent
          When was the last time System.currentTimeMillis() when we've asked GB to get us a path.
private  int liftAttempts
          How many times we've tried to get to the lift.
private  java.util.logging.Logger log
          Platform log.
private  java.lang.String logPrefix
          Log prefix.
private  Mover myMover
          Filled when we have to enter the lift.
private  java.util.ArrayList<NavPoint> path
          Current path the manager is working over
private static int PATH_ID_START_COUNTER
          First path id to use.
static long PATH_REQUEST_TIMEOUT
          How many millis we will wait for the GB to answer GETPATH command before we timeout...
private  int pathId
          Last used pathId when communicating with GB.
private  boolean pathRequestSent
          Whether we sent request to the GB to get the path.
protected  java.util.HashMap<java.lang.String,java.util.ArrayList<NavPoint>> pathsFromGB
          Structure that stores collected paths according to their id.
private  Triple pathToLocation
          Last path requested was for this location
private  boolean returningToLiftExit
          Whether the command to return to lift exit has been issued.
private  PathManager.RunAlongPathState runningState
          State of the runAlongPath() that allows us to handle lifts.
private  int runningToNavPointIndex
          Index of the navpoint we're running to.
private  NavPoint toNavPoint
          Navpoint we're running to.
private  boolean waitingForLift
          If true the bot has started to wait for the lift...
private  long waitingForLiftStartedMillis
          Time when the bot started to wait for the lift.
private  double zCoordWhenLiftCenterReached
          What was the bot z-coord when lift center has been reached?
 
Constructor Summary
PathManager(GameMap gameMap, AgentBody body, java.util.logging.Logger platformLog)
          Creates a new instance of PathManager, body is passed so the PathManager may hook a listener to sniff PATH messages and SPAWN messages (to know when to restart itself) and issue commands.
 
Method Summary
private  double deviationFromTheRunningLine(Triple agentLocation)
           
private  NavPoint getNavPointFromMemory(NavPoint np)
          Retrieves navpoint from memory or if not found returns current 'np'.
private  NavPoint getNextNavPoint()
           
 java.util.ArrayList<NavPoint> getPath()
          When you get PATH_FOUND result from either retrievePathGB() or retrievePathAStart(), you may call this method to actually get that path.
 java.util.ArrayList<NavPoint> getPath(java.lang.String pathId)
          Returns path of specific id if present.
private  PathManager.Lift isNavpointLift(NavPoint np)
          Called if toNavPoint is not null, checks whether we're not entering the lift with the next navpoint.
private  boolean isStucked()
           
private  void jumpCheck(Triple agentLocation)
           
private  Mover locateMover(Triple location)
           
private  double maxDistanceInAgentLocationHistory()
          Returns max distance between two locations in agentLocationHistory
 void receiveMessage(RcvMsgEvent e)
          Saves obtained paths from GB and restart path manager if bot is respawned.
 void restartPathManager()
          Call to reset all variables of the path manager - called also internally when restarting paths.
 void restartRunAlongPath()
          Used to restart the running along path - all variables cleared - called automaticaly during restartPathManager() or agent respawn.
 PathManager.PathResult retrievePathAStar(NavPoint target)
          Use this method before you call runAlongPath() to prepare the path to run along :) When PATH_FOUND is returned, you may then call runAlongPath().
 PathManager.PathResult retrievePathGB(Triple location)
          Use this method before you call runAlongPath() to prepare the path to run along :) When PATH_FOUND is returned, you may then call runAlongPath().
private  PathManager.RunResult runAlongPath_EnteringLiftState(Triple agentLocation)
           
private  PathManager.RunResult runAlongPath_ExitingLift(Triple agentLocation)
           
private  PathManager.RunResult runAlongPath_InCenterOfTheLiftState(Triple agentLocation)
           
private  PathManager.RunResult runAlongPath_PathRestartedState(Triple agentLocation)
           
private  PathManager.RunResult runAlongPath_RunningToNavpointState(Triple agentLocation)
           
 PathManager.RunResult runAlongPath()
          method to follow smoothly desired path - list of navigation points obtained from game map can handle movers - wait on it until top and leave note that movers in the way are in this fashion: - LiftExit -> LiftCenter -> LiftExit so as agent is supposed to go up when he is supposed to go to LiftCenter (therefore is around first LiftExit) he waits for mover to be about his level and then goes on it, wait to level with second LiftExit and move on
private  void switchToNextNavPoint()
          Changes runningToNavPointIndex, fromNavpoint = toNavPoint, toNavPoint = next navpoint (if there is any, otherwise null, path ended).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATH_REQUEST_TIMEOUT

public static final long PATH_REQUEST_TIMEOUT
How many millis we will wait for the GB to answer GETPATH command before we timeout...

See Also:
Constant Field Values

PATH_ID_START_COUNTER

private static final int PATH_ID_START_COUNTER
First path id to use.

See Also:
Constant Field Values

pathsFromGB

protected java.util.HashMap<java.lang.String,java.util.ArrayList<NavPoint>> pathsFromGB
Structure that stores collected paths according to their id.


pathRequestSent

private boolean pathRequestSent
Whether we sent request to the GB to get the path.


pathId

private int pathId
Last used pathId when communicating with GB.


pathToLocation

private Triple pathToLocation
Last path requested was for this location


path

private java.util.ArrayList<NavPoint> path
Current path the manager is working over


lastPathRequestSent

private long lastPathRequestSent
When was the last time System.currentTimeMillis() when we've asked GB to get us a path.


gameMap

private GameMap gameMap
Owner of the PathManager


body

private AgentBody body
AgentBody, we need it to be able to issue commands.


log

private java.util.logging.Logger log
Platform log.


runningState

private PathManager.RunAlongPathState runningState
State of the runAlongPath() that allows us to handle lifts.


fromNavPoint

private NavPoint fromNavPoint
Navpoint we're running from.


toNavPoint

private NavPoint toNavPoint
Navpoint we're running to.


edge

private NeighNav edge
Edge between navpoints we're running over.


runningToNavPointIndex

private int runningToNavPointIndex
Index of the navpoint we're running to.


logPrefix

private java.lang.String logPrefix
Log prefix.


myMover

private Mover myMover
Filled when we have to enter the lift.


waitingForLift

private boolean waitingForLift
If true the bot has started to wait for the lift...


waitingForLiftStartedMillis

private long waitingForLiftStartedMillis
Time when the bot started to wait for the lift.


returningToLiftExit

private boolean returningToLiftExit
Whether the command to return to lift exit has been issued.


liftAttempts

private int liftAttempts
How many times we've tried to get to the lift.


zCoordWhenLiftCenterReached

private double zCoordWhenLiftCenterReached
What was the bot z-coord when lift center has been reached?


agentLocationHistory

private java.util.List<Triple> agentLocationHistory
History of agent's location - stuck check is working over this...


lastAgentLocationAddedMillis

private long lastAgentLocationAddedMillis
When was the last time we've added the agent location to the history?


lastJumpMillis

private long lastJumpMillis
When was the last time the bot has tried to jump over obstacle, millis

Constructor Detail

PathManager

public PathManager(GameMap gameMap,
                   AgentBody body,
                   java.util.logging.Logger platformLog)
Creates a new instance of PathManager, body is passed so the PathManager may hook a listener to sniff PATH messages and SPAWN messages (to know when to restart itself) and issue commands.

GameMap is needed for the PathManager to be able to use AStar.

Method Detail

restartPathManager

public void restartPathManager()
Call to reset all variables of the path manager - called also internally when restarting paths.


retrievePathGB

public PathManager.PathResult retrievePathGB(Triple location)
Use this method before you call runAlongPath() to prepare the path to run along :)

When PATH_FOUND is returned, you may then call runAlongPath().

If NO_PATH is returned, the PathManager is restarted and you next call of this method will send another GETPATH command.

If called for different location then previous calls, the path manager is restarted and new GETPATH is sent.

If returning OBTAINING_PATH just keep calling this method with the same 'location' until it returns NO_PATH or PATH_FOUND.

Parameters:
location -
Returns:

retrievePathAStar

public PathManager.PathResult retrievePathAStar(NavPoint target)
Use this method before you call runAlongPath() to prepare the path to run along :)

When PATH_FOUND is returned, you may then call runAlongPath().

If NO_PATH is returned, the AStar was unable to find a path from agent's current location.

Parameters:
target -
Returns:

receiveMessage

public void receiveMessage(RcvMsgEvent e)
Saves obtained paths from GB and restart path manager if bot is respawned.

Specified by:
receiveMessage in interface RcvMsgListener

getPath

public java.util.ArrayList<NavPoint> getPath()
When you get PATH_FOUND result from either retrievePathGB() or retrievePathAStart(), you may call this method to actually get that path.

Returns:
found path

restartRunAlongPath

public void restartRunAlongPath()
Used to restart the running along path - all variables cleared - called automaticaly during restartPathManager() or agent respawn.


deviationFromTheRunningLine

private double deviationFromTheRunningLine(Triple agentLocation)

getNavPointFromMemory

private NavPoint getNavPointFromMemory(NavPoint np)
Retrieves navpoint from memory or if not found returns current 'np'.

Parameters:
np -
Returns:

switchToNextNavPoint

private void switchToNextNavPoint()
Changes runningToNavPointIndex, fromNavpoint = toNavPoint, toNavPoint = next navpoint (if there is any, otherwise null, path ended).


getNextNavPoint

private NavPoint getNextNavPoint()

isNavpointLift

private PathManager.Lift isNavpointLift(NavPoint np)
Called if toNavPoint is not null, checks whether we're not entering the lift with the next navpoint.


getPath

public java.util.ArrayList<NavPoint> getPath(java.lang.String pathId)
Returns path of specific id if present.

Parameters:
pathId -
Returns:

maxDistanceInAgentLocationHistory

private double maxDistanceInAgentLocationHistory()
Returns max distance between two locations in agentLocationHistory

Returns:

isStucked

private boolean isStucked()

jumpCheck

private void jumpCheck(Triple agentLocation)

runAlongPath

public PathManager.RunResult runAlongPath()
method to follow smoothly desired path - list of navigation points obtained from game map can handle movers - wait on it until top and leave note that movers in the way are in this fashion: - LiftExit -> LiftCenter -> LiftExit so as agent is supposed to go up when he is supposed to go to LiftCenter (therefore is around first LiftExit) he waits for mover to be about his level and then goes on it, wait to level with second LiftExit and move on

Returns:
boolean value - true if there are no problems, false if agent reaches the end or is unable to reach next navPoint

runAlongPath_PathRestartedState

private PathManager.RunResult runAlongPath_PathRestartedState(Triple agentLocation)

runAlongPath_RunningToNavpointState

private PathManager.RunResult runAlongPath_RunningToNavpointState(Triple agentLocation)

locateMover

private Mover locateMover(Triple location)

runAlongPath_EnteringLiftState

private PathManager.RunResult runAlongPath_EnteringLiftState(Triple agentLocation)

runAlongPath_InCenterOfTheLiftState

private PathManager.RunResult runAlongPath_InCenterOfTheLiftState(Triple agentLocation)

runAlongPath_ExitingLift

private PathManager.RunResult runAlongPath_ExitingLift(Triple agentLocation)