package net.sf.robocode.battle.snapshot; import java.io.IOException; import net.sf.robocode.battle.peer.ExplosionPeer; import net.sf.robocode.battle.peer.ProjectilePeer; import net.sf.robocode.battle.peer.RobotPeer; import net.sf.robocode.peer.ExecCommands; import net.sf.robocode.serialization.IXmlSerializable; import net.sf.robocode.serialization.SerializableOptions; import net.sf.robocode.serialization.XmlReader; import net.sf.robocode.serialization.XmlWriter; import robocode.control.snapshot.BulletState; import robocode.control.snapshot.IBulletSnapshot; public abstract class ProjectileSnapshot implements java.io.Serializable, IXmlSerializable, IBulletSnapshot { private static final long serialVersionUID = 2L; /** The bullet state */ protected BulletState state; /** The bullet power */ protected double power; /** The x position */ protected double x; /** The y position */ protected double y; /** The x painting position (due to offset on robot when bullet hits a robot) */ protected double paintX; /** The y painting position (due to offset on robot when bullet hits a robot) */ protected double paintY; /** The ARGB color of the bullet */ protected int color = ExecCommands.defaultProjectileColor; /** The current frame number to display, i.e. when the bullet explodes */ protected int frame; /** Flag specifying if this bullet has turned into an explosion */ protected boolean isExplosion; /** Index to which explosion image that must be rendered */ protected int explosionImageIndex; protected int bulletId; protected int victimIndex = -1; protected int ownerIndex; protected double heading; /** * Creates a snapshot of a bullet that must be filled out with data later. */ public ProjectileSnapshot() {} /** * Creates a snapshot of a bullet. * * @param bullet the bullet to make a snapshot of. */ public ProjectileSnapshot(ProjectilePeer bullet) { state = bullet.getState(); power = bullet.getPower(); x = bullet.getX(); y = bullet.getY(); paintX = bullet.getPaintX(); paintY = bullet.getPaintY(); color = bullet.getColor(); frame = bullet.getFrame(); isExplosion = (bullet instanceof ExplosionPeer); explosionImageIndex = bullet.getExplosionImageIndex(); bulletId = bullet.getId(); final RobotPeer victim = bullet.getVictim(); if (victim != null) { victimIndex = victim.getContestIndex(); } ownerIndex = bullet.getOwner().getContestIndex(); heading = bullet.getHeading(); } /** * {@inheritDoc} */ public int getBulletId() { return bulletId; } /** * {@inheritDoc} */ public BulletState getState() { return state; } /** * {@inheritDoc} */ public double getPower() { return power; } /** * {@inheritDoc} */ public double getX() { return x; } /** * {@inheritDoc} */ public double getY() { return y; } /** * {@inheritDoc} */ public double getPaintX() { return paintX; } /** * {@inheritDoc} */ public double getPaintY() { return paintY; } /** * {@inheritDoc} */ public int getColor() { return color; } /** * {@inheritDoc} */ public int getFrame() { return frame; } /** * {@inheritDoc} */ public boolean isExplosion() { return isExplosion; } /** * {@inheritDoc} */ public int getExplosionImageIndex() { return explosionImageIndex; } /** * {@inheritDoc} */ public double getHeading() { return heading; } /** * {@inheritDoc} */ public int getVictimIndex() { return victimIndex; } /** * {@inheritDoc} */ public int getOwnerIndex() { return ownerIndex; } /** * {@inheritDoc} */ public abstract void writeXml(XmlWriter writer, SerializableOptions options) throws IOException ; /** * {@inheritDoc} */ public abstract XmlReader.Element readXml(XmlReader reader); }