universe.server.database
Class GalaxyStd

java.lang.Object
  |
  +--universe.common.database.DBItem
        |
        +--universe.server.database.GalaxyBase
              |
              +--universe.server.database.GalaxyStd
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
GalaxyElliptical, GalaxyGlobular, GalaxySpiral

public class GalaxyStd
extends GalaxyBase

Class used for standard irregular galaxies containing a a random scattering of star systems with no discernable structure. Subclasses which want to have a random generated galaxy which imposes some kind of overall structure should override the randomCoord method of this class. This class is suitable for small scale games with low to moderate star densities. At larger sizes and higher densities, a more subclass with a structure which is more visually and strategically intereseting is recommended.

Version:
$Id: GalaxyStd.java,v 1.6 2003/04/04 00:52:07 sstarkey Exp $
See Also:
GalaxyElliptical, GalaxySpiral, GalaxyGlobular, Serialized Form

Field Summary
static java.lang.String DESCRIPTION
           
private  Coord myCenter
           
private  float myDensity
           
private  Coord mySpan
           
static java.util.Random ourRandGen
           
 
Fields inherited from class universe.server.database.GalaxyBase
 
Constructor Summary
GalaxyStd()
          This is not actually used, but is declared public in order to not interfere with subclassing.
GalaxyStd(float width, float height, float depth, float density)
          This is the designated constructor which should be used to create instances this class.
 
Method Summary
 boolean containsCoord(Coord aCoord)
          This method returns true if the given coordinate is contained within the retricted hull of the receiving galaxy.
 void generateSystems(float[] planetDistribution)
          This method extends that of our super class to causes the receiving galaxy to generate the random collection of star systems which it will contain and assign planets to each of these.
 Coord getCenter()
          Returns the center point of the galaxy.
 float getDensity()
          Returns the average number of star systems per parsec.
 Coord getSpan()
          Returns the height, width, and depth of this galaxy.
 Coord newSystemCoord()
          This method returns a random coordinate within the overall shape of the galaxy (as tested with containsCoord).
 int starSystemCount()
          Returns the number of star systems that will be present in the receiving galaxy after star system generation, as calculated from the usable dimensions of the galaxy and its assigned density.
 java.lang.String structureDescription()
          This method returns a (usually one-word) string describing the structure of the galaxy.
 
Methods inherited from class universe.server.database.GalaxyBase
addSystem, getID, getIndex, getName, getSystems, hasGeneratedSystems, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myCenter

private Coord myCenter

mySpan

private Coord mySpan

myDensity

private float myDensity

ourRandGen

public static java.util.Random ourRandGen

DESCRIPTION

public static java.lang.String DESCRIPTION
Constructor Detail

GalaxyStd

public GalaxyStd(float width,
                 float height,
                 float depth,
                 float density)
This is the designated constructor which should be used to create instances this class.

Parameters:
width - The width of the galaxy (in parsecs)
height - The height of the galaxy (in parsecs)
depth - The depth of the galaxy (in parsecs)
density - The average density (in systems per cubic parsec) of stars within the hull of the galaxy (not its bounding cube).

GalaxyStd

public GalaxyStd()
This is not actually used, but is declared public in order to not interfere with subclassing.

Method Detail

getSpan

public Coord getSpan()
Returns the height, width, and depth of this galaxy.

Returns:
A coordinate with maximum dimensions of the galaxy.

getCenter

public Coord getCenter()
Returns the center point of the galaxy.

Returns:
A coordinate representing the center point of the galaxy.

getDensity

public float getDensity()
Returns the average number of star systems per parsec.

Returns:
A floating point value representing the average number of star systems per parsec.

structureDescription

public java.lang.String structureDescription()
This method returns a (usually one-word) string describing the structure of the galaxy. Subclasses should override this method.


starSystemCount

public int starSystemCount()
Returns the number of star systems that will be present in the receiving galaxy after star system generation, as calculated from the usable dimensions of the galaxy and its assigned density. In this class it is calculated using a simple formula using the average density and the total volume of a cube. Subclasses which implement a galaxy having a specific structure which causes it to make use of less than the entire cube volume should override this method to use a more appropriate calculation.


newSystemCoord

public Coord newSystemCoord()
This method returns a random coordinate within the overall shape of the galaxy (as tested with containsCoord).

While this method is primarily used by the standard contructor it can also be used to generate locations for random events in interstellar space within the galaxy.

Subclasses may choose to override this method in order to more efficiently generate coordinates within some kind of overall galactic structure, as this implementation will test random points throughout the bounding cube. However, overridding the containsCoord method is all that is minimally required to get a new shape. Subclasses wishing to have the star system distribution follow a general internal structure, however, will definately wish to override this method.

Returns:
An unoccupied coordinate within the galaxy suitable for placement of a new star system.
See Also:
#containsCoord()

containsCoord

public boolean containsCoord(Coord aCoord)
This method returns true if the given coordinate is contained within the retricted hull of the receiving galaxy.

This method is provided as a convenience to subclass implementations of newSystemCoord(), where unchecked random pertubrations and rounding may result in a system coordindates outside the bounds of the galaxy.

In this base class, this simply means that it is within the bounding cube around the galactic center. However, subclasses which have other specific shapes and wish to ensure that no system "leaks" out into the cube beyond should override this method to test those more restrictive boundaries.

Parameters:
aCoord - The coordinate to be tested.
See Also:
newSystemCoord()

generateSystems

public void generateSystems(float[] planetDistribution)
                     throws SchemeUnknownException,
                            java.lang.InterruptedException
This method extends that of our super class to causes the receiving galaxy to generate the random collection of star systems which it will contain and assign planets to each of these. Subclass should not need to override this method as it calls starSystemCount and randomCoord (which should be overridden) in order to do its work. Calls to this method after the galaxy is already populated with star systems will have no effect.

Overrides:
generateSystems in class GalaxyBase
Parameters:
planetDistribution - Array of floating point values representing the probability of finding planet mass at successive distances from its primary.
Throws:
SchemeUnknownException - If unable to determine a ID of the galaxy to which systems are to be added.
java.lang.InterruptedException - If access to a resource needed for star system generation has been interrupted.
See Also:
GalaxyBase.hasGeneratedSystems()


Copyright © 2001 Universe Dev Team All Rights Reserved.