com.planet_ink.coffee_mud.core
Class Directions

java.lang.Object
  extended by com.planet_ink.coffee_mud.core.Directions

public class Directions
extends java.lang.Object


Nested Class Summary
static interface Directions.DirectionWordTranslator
          An interface to a translator for the direction words in this class
 
Field Summary
static int DOWN
           
static int EAST
           
static int GATE
           
static int NORTH
           
static int NORTHEAST
           
static int NORTHWEST
           
static int SOUTH
           
static int SOUTHEAST
           
static int SOUTHWEST
           
static int UP
           
static int WEST
           
 
Constructor Summary
Directions()
          Constructs a new Directions object for the current thread group.
 
Method Summary
static int[] adjustXYByDirections(int x, int y, int direction)
          Given an x and y coordinate, and a direction code, this method will return an int array with 2 entries x, and y, representing the changes to the given x and y after moving in that direction.
static int[] adjustXYZByDirections(int x, int y, int z, int direction)
          Given an x and y and z coordinate, and a direction code, this method will return an int array with 2 entries x, y, and z representing the changes to the given x, y, and z after moving in that direction.
static int[] CODES()
          The BASE direction code numbers, in numeric order.
static Directions d(char c)
          Returns the Directions instance tied to the given thread group, or null if not yet created.
static int[] DISPLAY_CODES()
          The direction code numbers in preferred display order.
 int getCompassDirectionCode(java.lang.String theDir)
          Given a string which is supposed to be a compass direction name, this method will make a case-insensitive check against the given string and return the direction it probably represents.
 java.lang.String getDirectionChar(int code)
          Given the numeric direction code, this method returns the 1 or 2 char "code" that represents that direction, such as N, S, E, W, NW, SW, etc..
 int getDirectionCode(java.lang.String theDir)
          Given a string which is supposed to be a direction name of any type, this method will make a case-insensitive check against the given string and return the direction it probably represents.
 java.lang.String getDirectionName(int code)
          Given the direction code, returns the formal name of that direction, capitalized.
 java.lang.String getDirectionName(java.lang.String theDir)
          Returns the formal direction name of the partial direction given.
 java.lang.String getFromCompassDirectionName(int code)
          Returns the proper english compass direction name to follow the preposition "from" when talking about something or someone coming FROM the given direction code.
 java.lang.String getFromShipDirectionName(int code)
          Returns the proper english ship direction name to follow the preposition "from" when talking about something or someone coming FROM the given direction code on a ship.
 int getGoodCompassDirectionCode(java.lang.String theDir)
          Given a string which is supposed to be a compass direction name, this method will make a case-insensitive check against the given string and return the direction it probably represents.
 int getGoodDirectionCode(java.lang.String theDir)
          Given a string which is supposed to be a direction name of any type, this method will make a case-insensitive check against the given string and return the direction it probably represents.
 int getGoodShipDirectionCode(java.lang.String theDir)
          Given a string which is technically supposed to be a ship-talk direction name, this method will make a case-insensitive check against the given string and return the direction it probably represents.
static int getGradualDirectionCode(int curentCode, int targetCode)
          Returns the direction code next to the given curentCode that moves towards the target direction code
 java.lang.String getInDirectionName(int code)
          Returns the proper english compass direction name to follow the preposition "happens" when talking about something happening in the given direction code.
static int getOpDirectionCode(int code)
          Returns the direction code opposite to the given code.
 int getOpDirectionCode(java.lang.String theDir)
          Given a string which is supposed to be a direction name of any type, this method will make a case-insensitive check against the given string and return the direction opposite to what it probably represents.
 int getProbableDirectionCode(java.lang.String theDir)
          Given a string which is supposed to be a direction name of any type, this method will make a case-insensitive check against the given string and return the direction it probably represents.
static int getRelative11Directions(int[] xyFrom, int[] xyTo)
          Returns the cardinal direction from the FROM point on a graph to the TO point, where the points are X, then Y, with the northwest corner being 0,0.
 java.lang.String getRelativeCompassDirectionName(int code)
          Returns the proper english compass direction name to relative to somewhere else.
static int getRelativeDirection(int[] xyFrom, int[] xyTo)
          Returns the cardinal direction from the FROM point on a graph to the TO point, where the points are X, then Y, with the northwest corner being 0,0.
static int getRelativeDirection(int[] xyFrom, int[] xyTo, boolean useBase4)
          Returns the cardinal direction from the FROM point on a graph to the TO point, where the points are X, then Y, with the northwest corner being 0,0.
 int getShipDirectionCode(java.lang.String theDir)
          Given a string which is technically supposed to be a ship-talk direction name, this method will make a case-insensitive check against the given string and return the direction it probably represents.
 java.lang.String getShipDirectionName(int code)
          Given the direction code, returns the ship-talk name of that direction, capitalized.
 java.lang.String getShipInDirectionName(int code)
          Returns the proper english ship-talk direction name to follow the preposition "happens" when talking about something happening in the given direction code on a ship.
 int getStrictCompassDirectionCode(java.lang.String theDir)
          Given a string which is supposed to be a compass direction name, this method will make a case-insensitive check against the given string and return the direction it probably represents.
 int getStrictDirectionCode(java.lang.String theDir)
          Given a string which is supposed to be a direction name of any type, this method will make a case-insensitive check against the given string and return the direction it probably represents.
 int getStrictShipDirectionCode(java.lang.String theDir)
          Given a string which is technically supposed to be a ship-talk direction name, this method will make a case-insensitive check against the given string and return the direction it represents.
 java.lang.String getUpperDirectionName(int code, boolean useShip)
          Given the direction code, returns the formal name of that direction, capitalized.
static Directions instance()
          Returns the Directions object that applies to the callers thread group.
static java.lang.String LETTERS()
          Returns a string list of all of the permitted direction letters.
static java.lang.String NAMES_LIST()
          Returns a string list of all of the permitted direction names.
static int NUM_DIRECTIONS()
          Returns the total number of permitted exit directions, either 7 or 11
 void reInitialize(int dirs, Directions.DirectionWordTranslator translator)
          Reinitializes this direction object with a new number-of-directions.
static java.lang.String SHIP_NAMES_LIST()
          Returns a string list of all of the permitted direction names, in ship-talk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORTH

public static final int NORTH
See Also:
Constant Field Values

SOUTH

public static final int SOUTH
See Also:
Constant Field Values

EAST

public static final int EAST
See Also:
Constant Field Values

WEST

public static final int WEST
See Also:
Constant Field Values

UP

public static final int UP
See Also:
Constant Field Values

DOWN

public static final int DOWN
See Also:
Constant Field Values

GATE

public static final int GATE
See Also:
Constant Field Values

NORTHEAST

public static final int NORTHEAST
See Also:
Constant Field Values

NORTHWEST

public static final int NORTHWEST
See Also:
Constant Field Values

SOUTHEAST

public static final int SOUTHEAST
See Also:
Constant Field Values

SOUTHWEST

public static final int SOUTHWEST
See Also:
Constant Field Values
Constructor Detail

Directions

public Directions()
Constructs a new Directions object for the current thread group.

Method Detail

d

public static Directions d(char c)
Returns the Directions instance tied to the given thread group, or null if not yet created.

Parameters:
c - the code for the thread group to return (0-255)
Returns:
the Directions instance tied to the given thread group, or null if not yet created.

instance

public static Directions instance()
Returns the Directions object that applies to the callers thread group.

Returns:
the Directions object that applies to the callers thread group.

NUM_DIRECTIONS

public static final int NUM_DIRECTIONS()
Returns the total number of permitted exit directions, either 7 or 11

Returns:
the total number of permitted exit directions, either 7 or 11

CODES

public static final int[] CODES()
The BASE direction code numbers, in numeric order. Typically 4 or 8

Returns:
BASE direction code numbers, in numeric order

DISPLAY_CODES

public static final int[] DISPLAY_CODES()
The direction code numbers in preferred display order. Typically 7 or 11.

Returns:
direction code numbers in preferred display order. Typically 7 or 11.

LETTERS

public static final java.lang.String LETTERS()
Returns a string list of all of the permitted direction letters. Either 7 or 11.

Returns:
a string list of all of the permitted direction letters. Either 7 or 11.

NAMES_LIST

public static final java.lang.String NAMES_LIST()
Returns a string list of all of the permitted direction names. Either 6 or 10.

Returns:
a string list of all of the permitted direction names. Either 6 or 10.

SHIP_NAMES_LIST

public static final java.lang.String SHIP_NAMES_LIST()
Returns a string list of all of the permitted direction names, in ship-talk. Either 6 or 10.

Returns:
a string list of all of the permitted direction names, in ship-talk. Either 6 or 10.

getDirectionName

public java.lang.String getDirectionName(java.lang.String theDir)
Returns the formal direction name of the partial direction given.

Parameters:
theDir - the partial direction name, case insensitive
Returns:
the formal direction name

reInitialize

public final void reInitialize(int dirs,
                               Directions.DirectionWordTranslator translator)
Reinitializes this direction object with a new number-of-directions.

Parameters:
dirs - the number of directions, either 7 or 11
translator - optional language translator for all the strings

getDirectionName

public java.lang.String getDirectionName(int code)
Given the direction code, returns the formal name of that direction, capitalized.

Parameters:
code - the direction code
Returns:
the name of that direction, capitalized

getUpperDirectionName

public java.lang.String getUpperDirectionName(int code,
                                              boolean useShip)
Given the direction code, returns the formal name of that direction, capitalized.

Parameters:
code - the direction code
useShip - true to use ship type directions, false for compass
Returns:
the name of that direction, capitalized

getShipDirectionName

public java.lang.String getShipDirectionName(int code)
Given the direction code, returns the ship-talk name of that direction, capitalized.

Parameters:
code - the direction code
Returns:
the ship-talk name of that direction, capitalized

getDirectionChar

public java.lang.String getDirectionChar(int code)
Given the numeric direction code, this method returns the 1 or 2 char "code" that represents that direction, such as N, S, E, W, NW, SW, etc..

Parameters:
code - the direction code
Returns:
the direction character or characters

getDirectionCode

public int getDirectionCode(java.lang.String theDir)
Given a string which is supposed to be a direction name of any type, this method will make a case-insensitive check against the given string and return the direction it probably represents. It gives preference to actual direction names, such as north, aft, below, up, but if all fail, it will try prefixes, such as nor, por, or just N, S, etc.

Parameters:
theDir - the direction search string
Returns:
the direction code it represents, or -1 if no match at ALL

getShipDirectionCode

public int getShipDirectionCode(java.lang.String theDir)
Given a string which is technically supposed to be a ship-talk direction name, this method will make a case-insensitive check against the given string and return the direction it probably represents. It gives preference to actual direction names, such as port and aft, but if all fail, it will try prefixes, such as por, for, etc.

Parameters:
theDir - the ship-talk direction search string
Returns:
the direction code it represents, or -1 if no match at ALL

getCompassDirectionCode

public int getCompassDirectionCode(java.lang.String theDir)
Given a string which is supposed to be a compass direction name, this method will make a case-insensitive check against the given string and return the direction it probably represents. It gives preference to actual direction names, such as north, south, etc, but if all fail, it will try prefixes, such as nor, sou, or just N, S, etc.

Parameters:
theDir - the direction search string
Returns:
the direction code it represents, or -1 if no match at ALL

getGoodDirectionCode

public int getGoodDirectionCode(java.lang.String theDir)
Given a string which is supposed to be a direction name of any type, this method will make a case-insensitive check against the given string and return the direction it probably represents. It gives preference to actual direction names, such as north, aft, below, up, but if all fail, it will try prefixes, such as nor, por, etc.

Parameters:
theDir - the direction search string
Returns:
the direction code it represents, or -1 if no match at ALL

getStrictDirectionCode

public int getStrictDirectionCode(java.lang.String theDir)
Given a string which is supposed to be a direction name of any type, this method will make a case-insensitive check against the given string and return the direction it probably represents. It requires strict actual direction names, such as north, aft, below, up.

Parameters:
theDir - the direction search string
Returns:
the direction code it represents, or -1 if no match at ALL

getProbableDirectionCode

public int getProbableDirectionCode(java.lang.String theDir)
Given a string which is supposed to be a direction name of any type, this method will make a case-insensitive check against the given string and return the direction it probably represents. It requires complete actual direction names, such as north, aft, below, up, or the words must BE a direction letter, or be a partial direction word, e.g. NOR would be NORTH, but NAP would NOT.

Parameters:
theDir - the direction search string
Returns:
the direction code it represents, or -1 if no match at ALL

getGoodCompassDirectionCode

public int getGoodCompassDirectionCode(java.lang.String theDir)
Given a string which is supposed to be a compass direction name, this method will make a case-insensitive check against the given string and return the direction it probably represents. It gives preference to actual direction names, such as north, south, etc, but if all fail, it will try prefixes, such as nor, sou, etc.

Parameters:
theDir - the direction search string
Returns:
the direction code it represents, or -1 if no match at ALL

getStrictCompassDirectionCode

public int getStrictCompassDirectionCode(java.lang.String theDir)
Given a string which is supposed to be a compass direction name, this method will make a case-insensitive check against the given string and return the direction it probably represents. It requires actual direction names, such as north, south, etc, but if all fail, it will try short letters, such as n, ne, etc.

Parameters:
theDir - the direction search string
Returns:
the direction code it represents, or -1 if no match at ALL

getGoodShipDirectionCode

public int getGoodShipDirectionCode(java.lang.String theDir)
Given a string which is technically supposed to be a ship-talk direction name, this method will make a case-insensitive check against the given string and return the direction it probably represents. It gives preference to actual direction names, such as port and aft, but if all fail, it will try prefixes, such as por, for, etc.

Parameters:
theDir - the ship-talk direction search string
Returns:
the direction code it represents, or -1 if no match at ALL

getStrictShipDirectionCode

public int getStrictShipDirectionCode(java.lang.String theDir)
Given a string which is technically supposed to be a ship-talk direction name, this method will make a case-insensitive check against the given string and return the direction it represents. It requires actual direction names, such as port and aft.

Parameters:
theDir - the ship-talk direction search string
Returns:
the direction code it represents, or -1 if no match at ALL

adjustXYByDirections

public static final int[] adjustXYByDirections(int x,
                                               int y,
                                               int direction)
Given an x and y coordinate, and a direction code, this method will return an int array with 2 entries x, and y, representing the changes to the given x and y after moving in that direction.

Parameters:
x - the x coordinate
y - the y coordinate
direction - the direction code being travelled
Returns:
the 2 dimensional int array with the new x and y

adjustXYZByDirections

public static final int[] adjustXYZByDirections(int x,
                                                int y,
                                                int z,
                                                int direction)
Given an x and y and z coordinate, and a direction code, this method will return an int array with 2 entries x, y, and z representing the changes to the given x, y, and z after moving in that direction.

Parameters:
x - the x coordinate
y - the y coordinate
z - the z coordinate
direction - the direction code being travelled
Returns:
the 3 dimensional int array with the new x, y, z

getFromCompassDirectionName

public java.lang.String getFromCompassDirectionName(int code)
Returns the proper english compass direction name to follow the preposition "from" when talking about something or someone coming FROM the given direction code. Completes the following sentence: "Joe arrived from ..."

Parameters:
code - the direction code
Returns:
the name of the direction phrase

getRelativeCompassDirectionName

public java.lang.String getRelativeCompassDirectionName(int code)
Returns the proper english compass direction name to relative to somewhere else.

Parameters:
code - the direction code
Returns:
the name of the direction phrase

getFromShipDirectionName

public java.lang.String getFromShipDirectionName(int code)
Returns the proper english ship direction name to follow the preposition "from" when talking about something or someone coming FROM the given direction code on a ship. Completes the following sentence: "Joe arrived from ..."

Parameters:
code - the direction code
Returns:
the name of the direction phrase

getInDirectionName

public java.lang.String getInDirectionName(int code)
Returns the proper english compass direction name to follow the preposition "happens" when talking about something happening in the given direction code. Completes the following sentence: "You hear something happen ..." Usually begins with "to the", such as "to the north", "to the northeast", etc.

Parameters:
code - the direction code the direction the thing is happening in
Returns:
the name of the direction completion phrase

getShipInDirectionName

public java.lang.String getShipInDirectionName(int code)
Returns the proper english ship-talk direction name to follow the preposition "happens" when talking about something happening in the given direction code on a ship. Completes the following sentence: "You hear something happen ..." Usually begins with "to", such as "to foreward", "to portside", etc.

Parameters:
code - the direction code the direction the thing is happening in
Returns:
the name of the direction completion phrase

getOpDirectionCode

public static final int getOpDirectionCode(int code)
Returns the direction code opposite to the given code. E.G. Returns North for South, Northwest for Southeast, etc.

Parameters:
code - the direction code
Returns:
the opposite direction code

getGradualDirectionCode

public static final int getGradualDirectionCode(int curentCode,
                                                int targetCode)
Returns the direction code next to the given curentCode that moves towards the target direction code

Parameters:
curentCode - the current direction code
targetCode - the target direction code
Returns:
the next direction code

getOpDirectionCode

public int getOpDirectionCode(java.lang.String theDir)
Given a string which is supposed to be a direction name of any type, this method will make a case-insensitive check against the given string and return the direction opposite to what it probably represents. It gives preference to actual direction names, such as north, aft, below, up, but if all fail, it will try prefixes, such as nor, por, or just N, S, etc.

Parameters:
theDir - the direction search string
Returns:
the direction code opposite to the one it represents, or -1 if no match at ALL

getRelativeDirection

public static final int getRelativeDirection(int[] xyFrom,
                                             int[] xyTo)
Returns the cardinal direction from the FROM point on a graph to the TO point, where the points are X, then Y, with the northwest corner being 0,0.

Parameters:
xyFrom - the starting point
xyTo - the target point
Returns:
the direction from the start to target

getRelative11Directions

public static final int getRelative11Directions(int[] xyFrom,
                                                int[] xyTo)
Returns the cardinal direction from the FROM point on a graph to the TO point, where the points are X, then Y, with the northwest corner being 0,0. This always return 11 direction codes.

Parameters:
xyFrom - the starting point
xyTo - the target point
Returns:
the direction from the start to target

getRelativeDirection

public static final int getRelativeDirection(int[] xyFrom,
                                             int[] xyTo,
                                             boolean useBase4)
Returns the cardinal direction from the FROM point on a graph to the TO point, where the points are X, then Y, with the northwest corner being 0,0.

Parameters:
xyFrom - the starting point
xyTo - the target point
useBase4 - true to use NSEW, false to use NORTHEAST, etc.
Returns:
the direction from the start to target