cz.cuni.amis.pogamut.ut2004.agent.navigation
Class UT2004Navigation

Package class diagram package UT2004Navigation
java.lang.Object
  extended by cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004Navigation
All Implemented Interfaces:
IUT2004Navigation

public class UT2004Navigation
extends Object
implements IUT2004Navigation

Facade for navigation in UT2004. Method navigate() can be called both synchronously and asynchronously. Uses IUT2004PathExecutor, FloydWarshallMap, IUT2004RunStraight and IUT2004GetBackToNavGraph to handle all possible navigation cases.

Author:
knight, jimmy

Field Summary
protected static int ARRIVED_AT_LOCATION_XY_THRESHOLD
          Location threshold for checking whether we have arrived on target.
protected static int ARRIVED_AT_LOCATION_Z_THRESHOLD
          Location threshold for checking whether we have arrived on target.
static double AT_PLAYER
          We're managed to get to player
protected  UT2004Bot bot
          UT2004Bot reference.
protected  IWorldEventListener<BotKilled> botKilledMessageListener
           
protected  ILocated continueTo
          Where the bot will continue to.
protected  IPathFuture<NavPoint> continueToPath
          Path to prolong.
protected  IPathFuture currentPathFuture
          Current path stored in IPathFuture object.
protected  ILocated currentTarget
          Current location target.
protected  Player currentTargetPlayer
          Current target is player (if not null)
protected  IWorldEventListener<EndMessage> endMessageListener
           
static double EXTEND_PATH_THRESHOLD
           
protected  double extendPathThreshold
          From which distance we should use IUT2004PathExecutor.extendPath(List).
protected  NavPoint fromNavPoint
          Navpoint we're running from (initial position when path executor has been triggered)
protected  IUT2004GetBackToNavGraph getBackToNavGraph
          UT2004GetBackToNavGraph for returning bot back to the navigation graph.
protected  ILocated lastTarget
          Last location target.
protected  Player lastTargetPlayer
          Last location target.
protected  LogCategory log
          Log used by this class.
protected  boolean navigating
          Whether navigation is running.
protected static int NEW_PATH_DISTANCE_THRESHOLD
          Location threshold for requesting of a new path or switching a path.
protected  IUT2004PathExecutor<ILocated> pathExecutor
          UT2004PathExecutor that is used for the navigation.
protected  IPathPlanner<NavPoint> pathPlanner
          FloydWarshallMap that is used for path planning.
protected static double PLAYER_DISTANCE_TRASHOLD
          When PLAYER is further from currentTarget than this location, recompute the path
protected  boolean runningStraightToPlayer
          We're running straight to the player.
protected  Location runningStraightToPlayerFailedAt
          Where run-straight failed.
protected  IUT2004RunStraight runStraight
          UT2004RunStraight is used to run directly to player at some moment.
protected  cz.cuni.amis.utils.flag.Flag<NavigationState> state
          State of UT2004Navigation
protected  NavPoint toNavPoint
          Navpoint we're running to, nearest navpoint to currentTarget
protected  boolean usingGetBackToNavGraph
          Whether we're using getBackToNavGraph.
 
Constructor Summary
UT2004Navigation(UT2004Bot bot, AgentInfo info, AdvancedLocomotion move)
          Will auto-create all needed UT2004Navigation subparts.
UT2004Navigation(UT2004Bot bot, IUT2004PathExecutor ut2004PathExecutor, IPathPlanner<NavPoint> pathPlanner, IUT2004GetBackToNavGraph getBackOnPath, IUT2004RunStraight runStraight)
          Here you may specify any custom UT2004Navigation parts.
UT2004Navigation(UT2004Bot bot, IUT2004PathExecutor ut2004PathExecutor, IPathPlanner<NavPoint> pathPlanner, IUT2004GetBackToNavGraph getBackOnPath, IUT2004RunStraight runStraight, double extendPathThreshold)
          Here you may specify any custom UT2004Navigation parts.
 
Method Summary
 void addStrongNavigationListener(cz.cuni.amis.utils.flag.FlagListener<NavigationState> listener)
          Use this to register listeners to various states the navigation - stuck, target reached, etc.
 IUT2004GetBackToNavGraph getBackToNavGraph()
          Returns underlying IUT2004GetBackToNavGraph object that is being used by this IUT2004Navigation.
 ILocated getContinueTo()
          Returns where the bot will continue to, for more info see IUT2004Navigation.setContinueTo(ILocated).
 List<ILocated> getCurrentPathCopy()
          Returns COPY of current path in list.
 List<ILocated> getCurrentPathDirect()
          Returns current path as in IPathFuture object that is used by ut2004pathExecutor to navigate.
 ILocated getCurrentTarget()
          Current POINT where the navigation is trying to get to.
 Item getCurrentTargetItem()
          If navigation is trying to get to some item, otherwise returns null.
 NavPoint getCurrentTargetNavPoint()
          If navigation is trying to get to some navpoint, otherwise returns null.
 Player getCurrentTargetPlayer()
          If navigation is trying to get to some player, otherwise returns null.
 ILocated getFocus()
          Returns current focus of the bots, may be null (== no focus).
 ILocated getLastTarget()
          Returns previous location we tried to get to (i.e., what was getCurrentTarget() before another navigate(ILocated) or navigate(Player) was called.
 Item getLastTargetItem()
          If previous target was an item, returns non-null Item we previously tried to get to.
 Player getLastTargetPlayer()
          If previous target was a player, returns non-null player we previously tried to get to (i.e., what was getCurrentTargetPlayer() before another navigate(ILocated) or navigate(Player) was called.
 Logger getLog()
          Returns logger used by the object.
 NavPoint getNearestNavPoint(ILocated location)
          Returns nearest navigation point to input location.
 IUT2004PathExecutor<ILocated> getPathExecutor()
          Returns underlying IUT2004PathExecutor object that is being used by this IUT2004Navigation.
 double getRemainingDistance()
          Returns how far is our target (path-distance == real-distance).
 IUT2004RunStraight getRunStraight()
          Returns underlying IUT2004RunStraight object that is being used by this IUT2004Navigation.
 cz.cuni.amis.utils.flag.Flag<NavigationState> getState()
          Returns an immutable flag with the current state of the navigation.
 boolean isNavigating()
          True if navigating, e.g., trying to get somewhere using either IUT2004PathExecutor, IUT2004GetBackToNavGraph or IUT2004RunStraight.
 boolean isNavigatingToItem()
          Whether we're currently navigating to item (final target).
 boolean isNavigatingToNavPoint()
          Whether we're currently navigating to navpoint (final target).
 boolean isNavigatingToPlayer()
          Whether we're currently navigating to player (final target).
 boolean isPathExecuting()
          Whether UT2004Navigation is currently using IUT2004PathExecutor to follow the path.
 boolean isRunningStraight()
          Whether UT2004Navigation is currently using runStraight to get to player by running straight to it/him/her.
 boolean isTryingToGetBackToNav()
          Whether UT2004Navigation is currently trying to get back to nav using IUT2004GetBackToNavGraph.
protected  void navigate()
           
 void navigate(ILocated target)
          This method can be called periodically or asynchronously.
 void navigate(IPathFuture<ILocated> pathHandle)
          Let the bot to follow this path.
 void navigate(Player player)
          This method can be called periodically or asynchronously.
protected  void noPath()
           
protected  boolean processPathFuture(IPathFuture futurePath, ILocated currentTarget)
          Checks if last path element is in close distance from our desired target and if not, we will add our desired target as the last path element.
 void removeStrongNavigationListener(cz.cuni.amis.utils.flag.FlagListener<NavigationState> listener)
          Removes path state listener.
protected  void reset(boolean stopGetBackToNavGraph, NavigationState resultState)
           
 void setContinueTo(ILocated continueTo)
          When the bot is about to reach its target, it will prolong his path to continue to 'target'.
 void setFocus(ILocated located)
          Sets focus of the bot when navigating (when using this object to run to some location target)! To reset focus call this method with null parameter.
 void stopNavigation()
          Stops navigation and resets the class.
protected  void stuck()
           
protected  void switchState(NavigationState newState)
           
protected  void targetReached()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXTEND_PATH_THRESHOLD

public static double EXTEND_PATH_THRESHOLD

log

protected LogCategory log
Log used by this class.


pathExecutor

protected IUT2004PathExecutor<ILocated> pathExecutor
UT2004PathExecutor that is used for the navigation.


pathPlanner

protected IPathPlanner<NavPoint> pathPlanner
FloydWarshallMap that is used for path planning.


bot

protected UT2004Bot bot
UT2004Bot reference.


getBackToNavGraph

protected IUT2004GetBackToNavGraph getBackToNavGraph
UT2004GetBackToNavGraph for returning bot back to the navigation graph.


runStraight

protected IUT2004RunStraight runStraight
UT2004RunStraight is used to run directly to player at some moment.


extendPathThreshold

protected double extendPathThreshold
From which distance we should use IUT2004PathExecutor.extendPath(List).


NEW_PATH_DISTANCE_THRESHOLD

protected static final int NEW_PATH_DISTANCE_THRESHOLD
Location threshold for requesting of a new path or switching a path.

See Also:
Constant Field Values

ARRIVED_AT_LOCATION_XY_THRESHOLD

protected static final int ARRIVED_AT_LOCATION_XY_THRESHOLD
Location threshold for checking whether we have arrived on target. For XY - 2D plane distance

See Also:
Constant Field Values

ARRIVED_AT_LOCATION_Z_THRESHOLD

protected static final int ARRIVED_AT_LOCATION_Z_THRESHOLD
Location threshold for checking whether we have arrived on target. For Z distance.

See Also:
Constant Field Values

PLAYER_DISTANCE_TRASHOLD

protected static final double PLAYER_DISTANCE_TRASHOLD
When PLAYER is further from currentTarget than this location, recompute the path

See Also:
Constant Field Values

AT_PLAYER

public static final double AT_PLAYER
We're managed to get to player

See Also:
Constant Field Values

state

protected cz.cuni.amis.utils.flag.Flag<NavigationState> state
State of UT2004Navigation


endMessageListener

protected IWorldEventListener<EndMessage> endMessageListener

botKilledMessageListener

protected IWorldEventListener<BotKilled> botKilledMessageListener

lastTarget

protected ILocated lastTarget
Last location target.


lastTargetPlayer

protected Player lastTargetPlayer
Last location target.


currentTarget

protected ILocated currentTarget
Current location target.


currentTargetPlayer

protected Player currentTargetPlayer
Current target is player (if not null)


fromNavPoint

protected NavPoint fromNavPoint
Navpoint we're running from (initial position when path executor has been triggered)


toNavPoint

protected NavPoint toNavPoint
Navpoint we're running to, nearest navpoint to currentTarget


currentPathFuture

protected IPathFuture currentPathFuture
Current path stored in IPathFuture object.


navigating

protected boolean navigating
Whether navigation is running.


runningStraightToPlayer

protected boolean runningStraightToPlayer
We're running straight to the player.


runningStraightToPlayerFailedAt

protected Location runningStraightToPlayerFailedAt
Where run-straight failed.


usingGetBackToNavGraph

protected boolean usingGetBackToNavGraph
Whether we're using getBackToNavGraph.


continueTo

protected ILocated continueTo
Where the bot will continue to.


continueToPath

protected IPathFuture<NavPoint> continueToPath
Path to prolong.

Constructor Detail

UT2004Navigation

public UT2004Navigation(UT2004Bot bot,
                        IUT2004PathExecutor ut2004PathExecutor,
                        IPathPlanner<NavPoint> pathPlanner,
                        IUT2004GetBackToNavGraph getBackOnPath,
                        IUT2004RunStraight runStraight)
Here you may specify any custom UT2004Navigation parts.

Parameters:
bot -
ut2004PathExecutor -
pathPlanner -
getBackOnPath -
runStraight -

UT2004Navigation

public UT2004Navigation(UT2004Bot bot,
                        IUT2004PathExecutor ut2004PathExecutor,
                        IPathPlanner<NavPoint> pathPlanner,
                        IUT2004GetBackToNavGraph getBackOnPath,
                        IUT2004RunStraight runStraight,
                        double extendPathThreshold)
Here you may specify any custom UT2004Navigation parts.

Parameters:
bot -
ut2004PathExecutor -
pathPlanner -
getBackOnPath -
runStraight -

UT2004Navigation

public UT2004Navigation(UT2004Bot bot,
                        AgentInfo info,
                        AdvancedLocomotion move)
Will auto-create all needed UT2004Navigation subparts.

Parameters:
bot -
info -
move -
Method Detail

getLog

public Logger getLog()
Description copied from interface: IUT2004Navigation
Returns logger used by the object.

Specified by:
getLog in interface IUT2004Navigation
Returns:

addStrongNavigationListener

public void addStrongNavigationListener(cz.cuni.amis.utils.flag.FlagListener<NavigationState> listener)
Description copied from interface: IUT2004Navigation
Use this to register listeners to various states the navigation - stuck, target reached, etc. See NavigationState.

Specified by:
addStrongNavigationListener in interface IUT2004Navigation

removeStrongNavigationListener

public void removeStrongNavigationListener(cz.cuni.amis.utils.flag.FlagListener<NavigationState> listener)
Description copied from interface: IUT2004Navigation
Removes path state listener.

Specified by:
removeStrongNavigationListener in interface IUT2004Navigation

getPathExecutor

public IUT2004PathExecutor<ILocated> getPathExecutor()
Description copied from interface: IUT2004Navigation
Returns underlying IUT2004PathExecutor object that is being used by this IUT2004Navigation.

Specified by:
getPathExecutor in interface IUT2004Navigation
Returns:

getBackToNavGraph

public IUT2004GetBackToNavGraph getBackToNavGraph()
Description copied from interface: IUT2004Navigation
Returns underlying IUT2004GetBackToNavGraph object that is being used by this IUT2004Navigation.

Specified by:
getBackToNavGraph in interface IUT2004Navigation
Returns:

getRunStraight

public IUT2004RunStraight getRunStraight()
Description copied from interface: IUT2004Navigation
Returns underlying IUT2004RunStraight object that is being used by this IUT2004Navigation.

Specified by:
getRunStraight in interface IUT2004Navigation
Returns:

isNavigating

public boolean isNavigating()
Description copied from interface: IUT2004Navigation
True if navigating, e.g., trying to get somewhere using either IUT2004PathExecutor, IUT2004GetBackToNavGraph or IUT2004RunStraight.

Specified by:
isNavigating in interface IUT2004Navigation
Returns:

isNavigatingToNavPoint

public boolean isNavigatingToNavPoint()
Description copied from interface: IUT2004Navigation
Whether we're currently navigating to navpoint (final target).

Specified by:
isNavigatingToNavPoint in interface IUT2004Navigation
Returns:

isNavigatingToItem

public boolean isNavigatingToItem()
Description copied from interface: IUT2004Navigation
Whether we're currently navigating to item (final target).

Specified by:
isNavigatingToItem in interface IUT2004Navigation
Returns:

isNavigatingToPlayer

public boolean isNavigatingToPlayer()
Description copied from interface: IUT2004Navigation
Whether we're currently navigating to player (final target).

Specified by:
isNavigatingToPlayer in interface IUT2004Navigation
Returns:

isTryingToGetBackToNav

public boolean isTryingToGetBackToNav()
Description copied from interface: IUT2004Navigation
Whether UT2004Navigation is currently trying to get back to nav using IUT2004GetBackToNavGraph.

Specified by:
isTryingToGetBackToNav in interface IUT2004Navigation
Returns:

isPathExecuting

public boolean isPathExecuting()
Description copied from interface: IUT2004Navigation
Whether UT2004Navigation is currently using IUT2004PathExecutor to follow the path.

Specified by:
isPathExecuting in interface IUT2004Navigation
Returns:

isRunningStraight

public boolean isRunningStraight()
Description copied from interface: IUT2004Navigation
Whether UT2004Navigation is currently using runStraight to get to player by running straight to it/him/her.

Specified by:
isRunningStraight in interface IUT2004Navigation
Returns:

getFocus

public ILocated getFocus()
Description copied from interface: IUT2004Navigation
Returns current focus of the bots, may be null (== no focus).

Specified by:
getFocus in interface IUT2004Navigation

setFocus

public void setFocus(ILocated located)
Description copied from interface: IUT2004Navigation
Sets focus of the bot when navigating (when using this object to run to some location target)! To reset focus call this method with null parameter.

Specified by:
setFocus in interface IUT2004Navigation

stopNavigation

public void stopNavigation()
Description copied from interface: IUT2004Navigation
Stops navigation and resets the class. Does NOT reset focus!

Specified by:
stopNavigation in interface IUT2004Navigation

navigate

public void navigate(ILocated target)
Description copied from interface: IUT2004Navigation
This method can be called periodically or asynchronously. Will move bot to 'target'. The bot will stop on bad input (location == null).

Specified by:
navigate in interface IUT2004Navigation
Parameters:
target - target location

navigate

public void navigate(Player player)
Description copied from interface: IUT2004Navigation
This method can be called periodically or asynchronously. Will move bot to input location. Uses UT2004PathExecutor and FloydWarshallMap. The bot will stop on bad input (location null).

Specified by:
navigate in interface IUT2004Navigation

navigate

public void navigate(IPathFuture<ILocated> pathHandle)
Description copied from interface: IUT2004Navigation
Let the bot to follow this path.

Specified by:
navigate in interface IUT2004Navigation

getNearestNavPoint

public NavPoint getNearestNavPoint(ILocated location)
Description copied from interface: IUT2004Navigation
Returns nearest navigation point to input location. FloydWarshallMap works only on NavPoints.

Specified by:
getNearestNavPoint in interface IUT2004Navigation
Returns:

getContinueTo

public ILocated getContinueTo()
Description copied from interface: IUT2004Navigation
Returns where the bot will continue to, for more info see IUT2004Navigation.setContinueTo(ILocated). WARNING: continueTo is reset when bot stop navigating / stuck, etc. WARNING: continueTo is also "nullified" when the bot actually prolongs its path to reach the 'target'.

Specified by:
getContinueTo in interface IUT2004Navigation
Returns:

setContinueTo

public void setContinueTo(ILocated continueTo)
Description copied from interface: IUT2004Navigation
When the bot is about to reach its target, it will prolong his path to continue to 'target'. DOES NOT WORK WITH IUT2004Navigation.navigate(Player). WARNING: continueTo is reset when bot stop navigating / stuck, etc. WARNING: continueTo is also "nullified" when the bot actually prolongs its path to reach the 'target'.

Specified by:
setContinueTo in interface IUT2004Navigation
Parameters:
continueTo - cannot be Player

getCurrentPathCopy

public List<ILocated> getCurrentPathCopy()
Description copied from interface: IUT2004Navigation
Returns COPY of current path in list. May take some time to fill up. Returns empty list if path not computed.

Specified by:
getCurrentPathCopy in interface IUT2004Navigation
Returns:

getCurrentPathDirect

public List<ILocated> getCurrentPathDirect()
Description copied from interface: IUT2004Navigation
Returns current path as in IPathFuture object that is used by ut2004pathExecutor to navigate. Can be altered. May return null if path not computed! Be carefull when altering this during UT2004PathExecutor run - it may cause undesirable behavior.

Specified by:
getCurrentPathDirect in interface IUT2004Navigation
Returns:

getCurrentTarget

public ILocated getCurrentTarget()
Description copied from interface: IUT2004Navigation
Current POINT where the navigation is trying to get to.

Specified by:
getCurrentTarget in interface IUT2004Navigation
Returns:

getCurrentTargetPlayer

public Player getCurrentTargetPlayer()
Description copied from interface: IUT2004Navigation
If navigation is trying to get to some player, otherwise returns null.

Specified by:
getCurrentTargetPlayer in interface IUT2004Navigation
Returns:

getCurrentTargetItem

public Item getCurrentTargetItem()
Description copied from interface: IUT2004Navigation
If navigation is trying to get to some item, otherwise returns null.

Specified by:
getCurrentTargetItem in interface IUT2004Navigation
Returns:

getCurrentTargetNavPoint

public NavPoint getCurrentTargetNavPoint()
Description copied from interface: IUT2004Navigation
If navigation is trying to get to some navpoint, otherwise returns null.

Specified by:
getCurrentTargetNavPoint in interface IUT2004Navigation
Returns:

getLastTarget

public ILocated getLastTarget()
Description copied from interface: IUT2004Navigation
Returns previous location we tried to get to (i.e., what was getCurrentTarget() before another navigate(ILocated) or navigate(Player) was called.

Specified by:
getLastTarget in interface IUT2004Navigation
Returns:

getLastTargetPlayer

public Player getLastTargetPlayer()
Description copied from interface: IUT2004Navigation
If previous target was a player, returns non-null player we previously tried to get to (i.e., what was getCurrentTargetPlayer() before another navigate(ILocated) or navigate(Player) was called.

Specified by:
getLastTargetPlayer in interface IUT2004Navigation
Returns:

getLastTargetItem

public Item getLastTargetItem()
Description copied from interface: IUT2004Navigation
If previous target was an item, returns non-null Item we previously tried to get to. (i.e., what was getCurrentTargetItem() before another navigate(ILocated) or navigate(Player) was called.

Specified by:
getLastTargetItem in interface IUT2004Navigation
Returns:

getRemainingDistance

public double getRemainingDistance()
Description copied from interface: IUT2004Navigation
Returns how far is our target (path-distance == real-distance). May return -1 if it cannot be computed.

Specified by:
getRemainingDistance in interface IUT2004Navigation
Returns:

navigate

protected void navigate()

processPathFuture

protected boolean processPathFuture(IPathFuture futurePath,
                                    ILocated currentTarget)
Checks if last path element is in close distance from our desired target and if not, we will add our desired target as the last path element.

Parameters:
futurePath -

switchState

protected void switchState(NavigationState newState)

noPath

protected void noPath()

stuck

protected void stuck()

targetReached

protected void targetReached()

reset

protected void reset(boolean stopGetBackToNavGraph,
                     NavigationState resultState)

getState

public cz.cuni.amis.utils.flag.Flag<NavigationState> getState()
Description copied from interface: IUT2004Navigation
Returns an immutable flag with the current state of the navigation.

Specified by:
getState in interface IUT2004Navigation
Returns:
an immutable flag with the current state of the navigation.


Copyright © 2015 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.