robocode.naval
Class ComponentBase

java.lang.Object
  extended by robocode.naval.ComponentBase
All Implemented Interfaces:
Serializable, IComponent
Direct Known Subclasses:
MineComponent, RadarComponent, WeaponComponent

public abstract class ComponentBase
extends Object
implements IComponent, Serializable

The abstract class for the basic ship components.

Since:
1.9.2.2
Author:
Thales B.V. / Jiri Waning
See Also:
Serialized Form

Nested Class Summary
protected static class ComponentBase.HiddenComponentHelper
          Only visible towards subclasses.
 
Field Summary
protected  double angle
          The angle, in radians, of the component.
protected  double lastHeading
          Keeping track of the heading before the current heading.
protected  ComponentType type
          The type of this component.
 
Constructor Summary
ComponentBase(double x, double y, ComponentType type, double angle)
          Creates a new robot component at the specified point.
ComponentBase(Point2D pivot, ComponentType type)
          Creates a new robot component at the specified point.
ComponentBase(Point2D pivot, ComponentType type, double angle)
          Creates a new robot component at the specified point.
 
Method Summary
 boolean equals(Object obj)
          
 double getAngle()
          Get the angle of the component; in radians.
 double getAngleDegrees()
          Get the angle of the component; in degrees.
 Color getColor()
          Get the color of the component.
 double getGunHeat()
           
 double getLastAngle()
           
 Point2D getOrigin(ITransformable peer)
          Get the exact location of the component.
 Point2D getPivot()
          Get the pivot point of the component as a Point2D object.
 byte getSerializeType()
           
 ComponentType getType()
          Get the type of the component.
 void setAngle(double angle)
          Set the angle of the component; in radians.
 void setAngleDegrees(double angle)
          Set the angle of the component; in degrees.
 void setColor(Color color)
          Set the color of the component.
 void setLastAngle(double lastHeading)
          Sets the lastHeading of the component in Radians.
protected  void setType(ComponentType type)
          Set the type of the component.
 String toString()
          
abstract  double turnRadians(double turnRemaining)
          Attempts to turn the component.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

angle

protected double angle
The angle, in radians, of the component.


type

protected ComponentType type
The type of this component. Default: Undefined


lastHeading

protected double lastHeading
Keeping track of the heading before the current heading. Useful for deciding the scan width

Constructor Detail

ComponentBase

public ComponentBase(Point2D pivot,
                     ComponentType type)
Creates a new robot component at the specified point.

Parameters:
pivot - The pivot point of the component.
type - The type of the child component.

ComponentBase

public ComponentBase(double x,
                     double y,
                     ComponentType type,
                     double angle)
Creates a new robot component at the specified point.

Parameters:
x - The X-coordinate of the pivot point of the component.
y - The Y-coordinate of the pivot point of the component.
type - The type of the child component.
angle - The angle of the component in radians.

ComponentBase

public ComponentBase(Point2D pivot,
                     ComponentType type,
                     double angle)
Creates a new robot component at the specified point.

Parameters:
pivot - The pivot point of the component.
type - The type of the child component.
angle - The angle of the component in radians.
Method Detail

getGunHeat

public double getGunHeat()
Specified by:
getGunHeat in interface IComponent

getPivot

public Point2D getPivot()
Get the pivot point of the component as a Point2D object.

The point is relative to that of the ship.

Specified by:
getPivot in interface IComponent
Returns:
The pivot point of the component.

getOrigin

public Point2D getOrigin(ITransformable peer)
Get the exact location of the component. (On battlefield coordinates!)

Specified by:
getOrigin in interface IComponent
Parameters:
peer - The robot the component belongs to.
Returns:
The exact location of the component.

setLastAngle

public void setLastAngle(double lastHeading)
Sets the lastHeading of the component in Radians. This function is for example used to determine how large the Arc of the Radar has to be.

Specified by:
setLastAngle in interface IComponent
Parameters:
lastHeading - The lastHeading in Radians.

getLastAngle

public double getLastAngle()
Specified by:
getLastAngle in interface IComponent

getAngle

public double getAngle()
Get the angle of the component; in radians.

Specified by:
getAngle in interface IComponent
Returns:
The angle of the component; in radians.

getAngleDegrees

public double getAngleDegrees()
Get the angle of the component; in degrees.

Specified by:
getAngleDegrees in interface IComponent
Returns:
The angle of the component; in degrees.

setAngle

public void setAngle(double angle)
Set the angle of the component; in radians.

Specified by:
setAngle in interface IComponent
Parameters:
angle - The angle to which to set the component.

setAngleDegrees

public void setAngleDegrees(double angle)
Set the angle of the component; in degrees.

Specified by:
setAngleDegrees in interface IComponent
Parameters:
angle - The angle to which to set the component.

setType

protected void setType(ComponentType type)
Set the type of the component.

The types differ for each child class.

Parameters:
type - The type of the component.

getType

public ComponentType getType()
Get the type of the component.

The types differ for each class and classes may have multiple types!

Specified by:
getType in interface IComponent
Returns:
The type of the component.

setColor

public void setColor(Color color)
Set the color of the component.

Specified by:
setColor in interface IComponent
Parameters:
color - The color of the component.

getColor

public Color getColor()
Get the color of the component.

Specified by:
getColor in interface IComponent
Returns:
The color of the component.

turnRadians

public abstract double turnRadians(double turnRemaining)
Description copied from interface: IComponent
Attempts to turn the component.

Specified by:
turnRadians in interface IComponent
Parameters:
turnRemaining - The angle in RADIANS the component still has to turn.
Returns:
The turnRemaining after the turning has been done.

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

toString

public String toString()

Overrides:
toString in class Object

getSerializeType

public byte getSerializeType()
Specified by:
getSerializeType in interface IComponent


Copyright © 2015 Robocode. All Rights Reserved.