diff options
Diffstat (limited to 'comp2511/blackout/SatelliteBase.java')
| -rw-r--r-- | comp2511/blackout/SatelliteBase.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/comp2511/blackout/SatelliteBase.java b/comp2511/blackout/SatelliteBase.java new file mode 100644 index 0000000..ed88216 --- /dev/null +++ b/comp2511/blackout/SatelliteBase.java @@ -0,0 +1,57 @@ +package unsw.blackout; + +import unsw.utils.Angle; +import unsw.utils.MathsHelper; + +public abstract class SatelliteBase extends EntityBase { + + /** + * SatelliteBase is an abstract class containing common functionality between satellites. + */ + public SatelliteBase(String satelliteID, double height, Angle position) { + super(satelliteID, position, height); + } + + /** + * Returns true if the device type is supported, false otherwise. + */ + protected abstract boolean isSupportedDeviceType(String type); + + + @ Override + final protected boolean isSupportedEntity(EntityBase entity) { + if (entity instanceof SatelliteBase) { + return true; + } + return this.isSupportedDeviceType(entity.getClass().getSimpleName()); + } + + /** + * Helper function to differentiate between devices and satellite distance calls. + */ + final private double getEntityDistance(EntityBase entity) { + if (entity instanceof SatelliteBase) { + return MathsHelper.getDistance(this.getHeight(), this.getAngle(), entity.getHeight(), entity.getAngle()); + } + return MathsHelper.getDistance(this.getHeight(), this.getAngle(), entity.getAngle()); + } + /** + * Helper function to differentiate between devices and satellite visibility calls. + */ + final private boolean isEntityVisible(EntityBase entity) { + if (entity instanceof SatelliteBase) { + return MathsHelper.isVisible(this.getHeight(), this.getAngle(), entity.getHeight(), entity.getAngle()); + } + return MathsHelper.isVisible(this.getHeight(), this.getAngle(), entity.getAngle()); + } + @ Override + final protected boolean isPhysicallyReachable(EntityBase entity) { + if (!this.isEntityVisible(entity)) { + return false; + } + if (this.getEntityDistance(entity) > this.getRange()) { + return false; + } + return true; + } +} |
