Class tjhCell

java.lang.Object
  |
  +--tjhCell

public class tjhCell
extends java.lang.Object

Encapsulates a cell in our pseudo-biological simulation. The cell's properties include a position, a reference to its parent (if any) and a list of children (if any). This is a tree structure.


Field Summary
protected  float angular_momentum
          the current angular momentum of the cell (in degrees)
protected static float ANGULAR_MOMENTUM
          the maximum angular momentum of each cell in degrees
protected  boolean has_parent
          stores whether this cell has a parent, or is the root cell for this creature
protected  tjhCreature host_creature
          a reference to the owning host creature
protected  tjh2dVector location
          the current location of the cell
protected  tjhNeuron neuron
          the cell's brains (they're a bit thick at the moment)
protected  tjhCell parent
          a reference to the parent of the cell (if any)
protected static float RADIUS
          the radius of the cells, fixed for now at least
protected  boolean seen_green
          stores whether the cell has seen a green enemy cell nearby
protected  boolean seen_red
          stores whether the cell has seen a red enemy cell nearby
protected static float SIGHT_DIST
          the distance within which cells can sense each other
protected  java.util.Vector subnodes
          a list of the cells that are children of this cell
protected  int type
          stores the type of the cell, determines its interactions and how it is drawn
protected static boolean USE_BRAINS
          do we want the cells to use their brains?
 
Constructor Summary
tjhCell()
          default constructor
 
Method Summary
protected  boolean CanMoveBy(tjh2dVector delta, tjh2dVector limit, tjhBuckets buckets, tjhCell asker, java.util.Vector deaths)
          detect any collisions with other cells that the requested move would cause
protected  boolean CanMoveTo(tjh2dVector prop_loc, tjh2dVector limit, tjhBuckets buckets, tjhCell asker, java.util.Vector deaths)
          collision detection/resolution check for a *single* cell, doesn't recurse
protected  boolean CanRotate(tjh2dVector centre, float delta, tjh2dVector limit, tjhBuckets buckets, tjhCell asker, java.util.Vector deaths)
          will the requested rotation cause a collision?
protected  boolean CloserThan(tjh2dVector loc, tjhCell them, float d)
          is the point loc closer to the cell them than the distance d?
 void Draw(java.awt.Graphics g)
          draws the cell (recurses to draw its daughter cells too)
protected  boolean InArea(tjh2dVector loc, tjh2dVector limit)
          is the point loc within the area of the simulation?
protected  void Instantiate(tjhGene genome, tjhCreature host, tjhBuckets buckets, tjh2dVector limit)
          top-level call to instantiate a tree of cells from the given genome.
protected  void InstantiateChildren(tjhGene genome, tjhCreature host, tjhBuckets buckets, tjh2dVector limit)
          recurses down to instantiate all mid-level and leaf-level nodes in the tree of cells that is being created
protected  boolean IsOurChild(tjhCell child)
          is the specified cell below us in the tree?
protected  void Killed(tjhBuckets buckets)
          this cell has been killed, ask it to tidy itself away
protected  void MoveArms(java.awt.Graphics g, tjhBuckets buckets, tjh2dVector limit)
          each cell moves about its parent axis (as long as no collision is caused)
protected  void MoveBy(tjh2dVector delta, tjhBuckets buckets)
          all checks have been made, just move the cells
protected  boolean MoveIfCan(tjh2dVector delta, tjh2dVector limit, tjhBuckets buckets)
          a move request, the cell will move as requested only if able to
protected  int NearestVisible(java.util.Vector within_sight)
          returns the index (in the list within_sight) of the nearest enemy cell
protected  float RandomAngle()
          return a random angle between 0 and 360 degrees
protected  float RandomAngularMomentum()
          pick an angular momentum at random
protected  void RemoveAllFromGlobalList(tjhBuckets buckets)
          recurses down to ask all children to remove themselves from the global buckets structure
protected  void Rotate(tjh2dVector centre, float delta, tjhBuckets buckets)
          all checks have been made, just rotate the cell
protected  boolean RotateIfCan(tjh2dVector centre, float delta, tjh2dVector limit, tjhBuckets buckets)
          a rotation request, the cell will rotate only if no collision is caused
protected  void StimulusResponse(java.awt.Graphics g, tjhBuckets buckets)
          if the neurons are active, reset the angular momentum in response to the nearby cells, otherwise does nothing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RADIUS

protected static final float RADIUS
the radius of the cells, fixed for now at least

ANGULAR_MOMENTUM

protected static final float ANGULAR_MOMENTUM
the maximum angular momentum of each cell in degrees

SIGHT_DIST

protected static final float SIGHT_DIST
the distance within which cells can sense each other

USE_BRAINS

protected static final boolean USE_BRAINS
do we want the cells to use their brains?

location

protected tjh2dVector location
the current location of the cell

parent

protected tjhCell parent
a reference to the parent of the cell (if any)

host_creature

protected tjhCreature host_creature
a reference to the owning host creature

has_parent

protected boolean has_parent
stores whether this cell has a parent, or is the root cell for this creature

subnodes

protected java.util.Vector subnodes
a list of the cells that are children of this cell

type

protected int type
stores the type of the cell, determines its interactions and how it is drawn

angular_momentum

protected float angular_momentum
the current angular momentum of the cell (in degrees)

neuron

protected tjhNeuron neuron
the cell's brains (they're a bit thick at the moment)

seen_red

protected boolean seen_red
stores whether the cell has seen a red enemy cell nearby

seen_green

protected boolean seen_green
stores whether the cell has seen a green enemy cell nearby
Constructor Detail

tjhCell

public tjhCell()
default constructor
Method Detail

Draw

public void Draw(java.awt.Graphics g)
draws the cell (recurses to draw its daughter cells too)

Instantiate

protected void Instantiate(tjhGene genome,
                           tjhCreature host,
                           tjhBuckets buckets,
                           tjh2dVector limit)
top-level call to instantiate a tree of cells from the given genome. Makes a note of the host creature and adds all new cells to the global buckets structure for global collision detection

InstantiateChildren

protected void InstantiateChildren(tjhGene genome,
                                   tjhCreature host,
                                   tjhBuckets buckets,
                                   tjh2dVector limit)
recurses down to instantiate all mid-level and leaf-level nodes in the tree of cells that is being created

Killed

protected void Killed(tjhBuckets buckets)
this cell has been killed, ask it to tidy itself away

RemoveAllFromGlobalList

protected void RemoveAllFromGlobalList(tjhBuckets buckets)
recurses down to ask all children to remove themselves from the global buckets structure

MoveIfCan

protected boolean MoveIfCan(tjh2dVector delta,
                            tjh2dVector limit,
                            tjhBuckets buckets)
a move request, the cell will move as requested only if able to

CanMoveBy

protected boolean CanMoveBy(tjh2dVector delta,
                            tjh2dVector limit,
                            tjhBuckets buckets,
                            tjhCell asker,
                            java.util.Vector deaths)
detect any collisions with other cells that the requested move would cause

MoveArms

protected void MoveArms(java.awt.Graphics g,
                        tjhBuckets buckets,
                        tjh2dVector limit)
each cell moves about its parent axis (as long as no collision is caused)

StimulusResponse

protected void StimulusResponse(java.awt.Graphics g,
                                tjhBuckets buckets)
if the neurons are active, reset the angular momentum in response to the nearby cells, otherwise does nothing

NearestVisible

protected int NearestVisible(java.util.Vector within_sight)
returns the index (in the list within_sight) of the nearest enemy cell

RotateIfCan

protected boolean RotateIfCan(tjh2dVector centre,
                              float delta,
                              tjh2dVector limit,
                              tjhBuckets buckets)
a rotation request, the cell will rotate only if no collision is caused

CanRotate

protected boolean CanRotate(tjh2dVector centre,
                            float delta,
                            tjh2dVector limit,
                            tjhBuckets buckets,
                            tjhCell asker,
                            java.util.Vector deaths)
will the requested rotation cause a collision?

CanMoveTo

protected boolean CanMoveTo(tjh2dVector prop_loc,
                            tjh2dVector limit,
                            tjhBuckets buckets,
                            tjhCell asker,
                            java.util.Vector deaths)
collision detection/resolution check for a *single* cell, doesn't recurse

IsOurChild

protected boolean IsOurChild(tjhCell child)
is the specified cell below us in the tree?

MoveBy

protected void MoveBy(tjh2dVector delta,
                      tjhBuckets buckets)
all checks have been made, just move the cells

Rotate

protected void Rotate(tjh2dVector centre,
                      float delta,
                      tjhBuckets buckets)
all checks have been made, just rotate the cell

InArea

protected boolean InArea(tjh2dVector loc,
                         tjh2dVector limit)
is the point loc within the area of the simulation?

CloserThan

protected boolean CloserThan(tjh2dVector loc,
                             tjhCell them,
                             float d)
is the point loc closer to the cell them than the distance d?

RandomAngularMomentum

protected float RandomAngularMomentum()
pick an angular momentum at random

RandomAngle

protected float RandomAngle()
return a random angle between 0 and 360 degrees