aboutsummaryrefslogtreecommitdiff
path: root/comp2511/blackout/SatelliteBase.java
blob: ed88216d01c68835d1a556082cfb86d73c21b8ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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;
    }
}