rl.common.mapping
Class HexGrid

java.lang.Object
  extended by rl.common.mapping.HexGrid
All Implemented Interfaces:
java.io.Serializable

public class HexGrid
extends java.lang.Object
implements java.io.Serializable

Title: Legatus

Copyright: Copyright Daniel Cleyne (c) 2004-2006

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Version:
0.1
Author:
Daniel Cleyne
See Also:
Serialized Form

Field Summary
static double HEXSIDE
           
protected  Hexagon[] m_HexList
           
(package private) static long serialVersionUID
           
 
Constructor Summary
HexGrid()
           
HexGrid(int gridWidth, int gridHeight, int xOffset, int yOffset)
           
 
Method Summary
protected  void buildHexGrid(int xOff, int yOff, int GridWidth, int GridHeight)
           
 int degree(Coordinate s, Coordinate d)
          Code from Megamek Returns the degree direction of another Coordinate.
 int direction(Coordinate c, Coordinate d)
          Code from Megamek Returns the direction in which another coordinate lies; 0 if the coordinates are equal.
 int distance(Coordinate src, Coordinate dst)
          Code from Megamek Returns the distance to another coordinate.
 Coordinate getCoordinateFromHex(Hexagon hex)
           
 Coordinate getCoordinateFromPoint(java.awt.Point p)
           
 java.awt.Dimension getGridDimension()
           
 Hexagon getHex(Coordinate c)
           
 Hexagon getHex(int HexNo)
           
 Hexagon getHex(int x, int y)
           
 Hexagon getHexFromPoint(java.awt.Point p)
           
 java.awt.Dimension getHexSize()
           
 java.awt.Point getOffset()
           
 int getSize()
           
 java.util.Vector<Coordinate> intervening(Coordinate src, Coordinate dest)
          This code taken from Megamek class IdealHex Returns an array of the Coordinate of hexes that are crossed by a straight line from the center of src to the center of dest, including src & dest.
 java.util.Vector<Coordinate> intervening(Coordinate src, Coordinate dest, boolean split)
           
 boolean isValidCoordinate(Coordinate c)
           
 double radian(Coordinate srcCoord, Coordinate destCoord)
          Code from Megamek Returns the radian direction of another Coordinate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

HEXSIDE

public static final double HEXSIDE
See Also:
Constant Field Values

m_HexList

protected Hexagon[] m_HexList
Constructor Detail

HexGrid

public HexGrid()

HexGrid

public HexGrid(int gridWidth,
               int gridHeight,
               int xOffset,
               int yOffset)
Method Detail

getHex

public Hexagon getHex(int HexNo)

getHex

public Hexagon getHex(int x,
                      int y)

getHex

public Hexagon getHex(Coordinate c)

getOffset

public java.awt.Point getOffset()

getGridDimension

public java.awt.Dimension getGridDimension()

getHexSize

public java.awt.Dimension getHexSize()

buildHexGrid

protected void buildHexGrid(int xOff,
                            int yOff,
                            int GridWidth,
                            int GridHeight)

getSize

public int getSize()

getHexFromPoint

public Hexagon getHexFromPoint(java.awt.Point p)

getCoordinateFromPoint

public Coordinate getCoordinateFromPoint(java.awt.Point p)

getCoordinateFromHex

public Coordinate getCoordinateFromHex(Hexagon hex)

radian

public double radian(Coordinate srcCoord,
                     Coordinate destCoord)
Code from Megamek Returns the radian direction of another Coordinate.

Parameters:
srcCoord - the source coordinate.
destCoord - the destination coordinate.

degree

public int degree(Coordinate s,
                  Coordinate d)
Code from Megamek Returns the degree direction of another Coordinate.

Parameters:
s - the source coordinate.
d - the destination coordinate.

direction

public int direction(Coordinate c,
                     Coordinate d)
Code from Megamek Returns the direction in which another coordinate lies; 0 if the coordinates are equal.

Parameters:
c - the source coordinate.
d - the destination coordinate.

distance

public int distance(Coordinate src,
                    Coordinate dst)
Code from Megamek Returns the distance to another coordinate.

Parameters:
src - the source coordinate
dst - the destination coordinate

intervening

public java.util.Vector<Coordinate> intervening(Coordinate src,
                                                Coordinate dest)
This code taken from Megamek class IdealHex Returns an array of the Coordinate of hexes that are crossed by a straight line from the center of src to the center of dest, including src & dest. The returned coordinates are in line order, and if the line passes directly between two hexes, it returns them both. Based on the degree of the angle, the next hex is going to be one of three hexes. We check those three hexes, sides first, add the first one that intersects and continue from there. Based off of some of the formulas at Amit's game programming site. (http://www-cs-students.stanford.edu/~amitp/gameprog.html)


intervening

public java.util.Vector<Coordinate> intervening(Coordinate src,
                                                Coordinate dest,
                                                boolean split)

isValidCoordinate

public boolean isValidCoordinate(Coordinate c)