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; } }