wyvern.lib
Class Location

java.lang.Object
  extended bywyvern.lib.Location
Direct Known Subclasses:
ServerURL

public class Location
extends java.lang.Object

Encapsulates a location: a map and an (x, y) position in the map. Also provides a number of static utility methods for manipulating locations.

Version:
1.0, Nov 10, 1997
Author:
Steve Yegge

Field Summary
protected  boolean askMap_
           
protected  java.lang.String map_
           
protected  int x_
           
protected  int y_
           
 
Constructor Summary
Location()
          Constructs a new Location with no value.
Location(int x, int y, java.lang.String map)
          Constructs a new Location with the passed parameters.
Location(Location loc)
          Constructs a new Location that has the same values as the passed location.
Location(Point p, java.lang.String map)
          Constructs a new Location with the passed parameters.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Overrides Object.equals.
static java.lang.String formatPoint(int x, int y)
          Point-formatting utility.
static java.lang.String formatPoint(int x, int y, int z)
          Point-formatting utility.
static java.lang.String formatPoint(Point p)
          Point-formatting utility.
static Rectangle getBounds(java.util.List locations)
          Returns the bounding rectangle for an arbitrary location list.
static Rectangle getBounds(Point[] locations)
          Returns the bounding rectangle for an arbitrary location list.
 java.lang.String getMap()
           
 Point getPoint()
           
 int getX()
           
 int getY()
           
 boolean isAsking()
          Returns true if this Location is flagged as not having a specific point in the map.
static Location parseLocation(java.lang.String value)
          Parses a location in the form "map x y".
 void setAskMap(boolean ask)
          Tells the user of this Location that they should ask the destination map for the start point.
 void setCoords(Point p)
          Sets coordinates to those of the passed Point.
 void setMap(java.lang.String map)
           
 void setX(int x)
           
 void setY(int y)
           
 java.lang.String toCommand(java.lang.String verb)
          Same as toPath(), but prepends the specific command verb before the path.
 java.lang.String toPath()
          Returns this locations's path in the form "map x y", so you can append it to a command like "teleport".
 java.lang.String toString()
          Returns a String representation of this Location.
static java.util.ArrayList translate(java.util.List src, Point offset)
          Translates a location list by a specified (x, y) offset.
static Point[] translate(Point[] src, Point offset)
          Translates a location list by a specified (x, y) offset.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x_

protected int x_

y_

protected int y_

map_

protected java.lang.String map_

askMap_

protected boolean askMap_
Constructor Detail

Location

public Location()
Constructs a new Location with no value.


Location

public Location(int x,
                int y,
                java.lang.String map)
Constructs a new Location with the passed parameters.

Parameters:
map - relative path to the map
x - map x
y - map y

Location

public Location(Point p,
                java.lang.String map)
Constructs a new Location with the passed parameters.

Parameters:
map - relative path to the map
p - map (x, y) coordinates (p doesn't change)

Location

public Location(Location loc)
Constructs a new Location that has the same values as the passed location.

Parameters:
loc - another Location object
Method Detail

getX

public int getX()

getY

public int getY()

getMap

public java.lang.String getMap()

setX

public void setX(int x)

setY

public void setY(int y)

setCoords

public void setCoords(Point p)
Sets coordinates to those of the passed Point.


setMap

public void setMap(java.lang.String map)

getPoint

public Point getPoint()

isAsking

public boolean isAsking()
Returns true if this Location is flagged as not having a specific point in the map. The user of the Location should call map.getStartLocation() and set the agent there.


setAskMap

public void setAskMap(boolean ask)
Tells the user of this Location that they should ask the destination map for the start point. This method name is deliberately inconsistent with isAsking() so that the JavaBeans API doesn't try to externalize this property.

Parameters:
ask - true to ask, false to use Location's x and y coordinates

toString

public java.lang.String toString()
Returns a String representation of this Location.

Returns:
a debugging string

toPath

public java.lang.String toPath()
Returns this locations's path in the form "map x y", so you can append it to a command like "teleport".

Returns:
the path, x, and y, separated by spaces

toCommand

public java.lang.String toCommand(java.lang.String verb)
Same as toPath(), but prepends the specific command verb before the path.

Parameters:
verb - a command like "goto" or "teleport".
Returns:
verb + " " + getMap() + " " + getX() + " " + getY()

equals

public boolean equals(java.lang.Object obj)
Overrides Object.equals. Checks relevant fields for equality.

Parameters:
obj - another Location; returns false if the passed object is not a Location object.
Returns:
true if the passed Location has the same field values as this one. Warning: don't use Location objects as keys in java.util data structures (e.g. TreeMap) that rely on equals() using "==".

parseLocation

public static Location parseLocation(java.lang.String value)
Parses a location in the form "map x y". Useful for saving out (and restoring) a map location without going to the effort of creating a Location property value.


formatPoint

public static java.lang.String formatPoint(int x,
                                           int y)
Point-formatting utility. Useful for error-checking and diagnostics.

Parameters:
x - any int
y - any int
Returns:
"(x, y)"

formatPoint

public static java.lang.String formatPoint(Point p)
Point-formatting utility. Useful for error-checking and diagnostics.

Parameters:
p - any Point
Returns:
"(x, y)"

formatPoint

public static java.lang.String formatPoint(int x,
                                           int y,
                                           int z)
Point-formatting utility. Useful for error-checking and diagnostics.

Parameters:
x - any int
y - any int
z - any int
Returns:
"(x, y, z)"

getBounds

public static Rectangle getBounds(Point[] locations)
Returns the bounding rectangle for an arbitrary location list.

Returns:
the minimum bounding box that includes all locations occupied by this object at the time the method is called.

getBounds

public static Rectangle getBounds(java.util.List locations)
Returns the bounding rectangle for an arbitrary location list.

Returns:
the minimum bounding box that includes all locations occupied by this object at the time the method is called.

translate

public static Point[] translate(Point[] src,
                                Point offset)
Translates a location list by a specified (x, y) offset.

Returns:
a new list with the translated points

translate

public static java.util.ArrayList translate(java.util.List src,
                                            Point offset)
Translates a location list by a specified (x, y) offset.

Returns:
a new ArrayList with the translated points