Skip to content

Commit

Permalink
feat: "TOO LOW - TERRAIN" warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Octol1ttle committed Mar 7, 2024
1 parent f6880da commit 8f60698
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ private ConfigCategory computers(Text name, ComputerConfig config, ComputerConfi
.controller(opt -> EnumControllerBuilder.create(opt).enumClass(ComputerConfig.ProtectionMode.class))
.build()
)
.option(Option.<ComputerConfig.WarningMode>createBuilder()
.name(Text.translatable("config.flightassistant.computers.gpws.landing.warning"))
.binding(defaults.landingClearanceWarning, () -> config.landingClearanceWarning, o -> config.landingClearanceWarning = o)
.controller(opt -> EnumControllerBuilder.create(opt).enumClass(ComputerConfig.WarningMode.class))
.build()
)

.option(LabelOption.create(Text.translatable("config.flightassistant.computers.void_level")))
.option(Option.<ComputerConfig.ProtectionMode>createBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public record AlertSoundData(@Nullable SoundEvent sound, int priority) {
SoundEvent.of(new Identifier("flightassistant:terrain")),
2
);
public static final AlertSoundData TOO_LOW_TERRAIN = new AlertSoundData(
SoundEvent.of(new Identifier("flightassistant:too_low_terrain")),
2
);
public static final AlertSoundData AUTOPILOT_DISCONNECT = new AlertSoundData(
SoundEvent.of(new Identifier("flightassistant:autopilot_disconnect")),
3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ru.octol1ttle.flightassistant.alerts.nav.gpws;

import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
import ru.octol1ttle.flightassistant.HudComponent;
import ru.octol1ttle.flightassistant.alerts.AlertSoundData;
import ru.octol1ttle.flightassistant.alerts.BaseAlert;
import ru.octol1ttle.flightassistant.alerts.ICenteredAlert;
import ru.octol1ttle.flightassistant.computers.safety.GPWSComputer;
import ru.octol1ttle.flightassistant.config.FAConfig;

public class UnsafeTerrainClearanceAlert extends BaseAlert implements ICenteredAlert {
private final GPWSComputer gpws;

public UnsafeTerrainClearanceAlert(GPWSComputer gpws) {
this.gpws = gpws;
}

@Override
public boolean isTriggered() {
return gpws.landingClearanceStatus == GPWSComputer.LandingClearanceStatus.TOO_LOW;
}

@Override
public @NotNull AlertSoundData getSoundData() {
return AlertSoundData.ifEnabled(FAConfig.computer().landingClearanceWarning, AlertSoundData.TOO_LOW_TERRAIN);
}

@Override
public boolean render(TextRenderer textRenderer, DrawContext context, int x, int y, boolean highlight) {
if (FAConfig.computer().landingClearanceWarning.screenDisabled()) {
return false;
}

HudComponent.drawHighlightedMiddleAlignedText(textRenderer, context, Text.translatable("alerts.flightassistant.too_low_terrain"), x, y,
FAConfig.indicator().cautionColor, highlight);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public float flightHeading() {
public float heightAboveGround() {
float height = Math.max(0.0f, altitude() - groundLevel);
if (height < 1.0f) {
throw new AssertionError();
throw new AssertionError(height);
}
return height;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import ru.octol1ttle.flightassistant.alerts.nav.MinimumsAlert;
import ru.octol1ttle.flightassistant.alerts.nav.gpws.ExcessiveDescentAlert;
import ru.octol1ttle.flightassistant.alerts.nav.gpws.ExcessiveTerrainClosureAlert;
import ru.octol1ttle.flightassistant.alerts.nav.gpws.UnsafeTerrainClearanceAlert;
import ru.octol1ttle.flightassistant.alerts.other.ElytraHealthLowAlert;
import ru.octol1ttle.flightassistant.alerts.other.StallAlert;
import ru.octol1ttle.flightassistant.computers.ComputerHost;
Expand All @@ -37,6 +38,7 @@ public AlertController(ComputerHost host, SoundManager manager, HudRenderer rend
allAlerts = List.of(
new StallAlert(host.stall),
new ExcessiveDescentAlert(host.data, host.gpws), new ExcessiveTerrainClosureAlert(host.gpws, host.time),
new UnsafeTerrainClearanceAlert(host.gpws),
new AutopilotOffAlert(host.autoflight), new AutoFireworkOffAlert(host.autoflight),
new MinimumsAlert(host.plan),
new ComputerFaultAlert(host), new IndicatorFaultAlert(renderer),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ public class GPWSComputer implements ITickableComputer {
private static final float CAUTION_THRESHOLD = 10.0f;
private static final float PULL_UP_THRESHOLD = 5.0f;
private static final float PITCH_CORRECT_THRESHOLD = 2.5f;
private static final float OPTIMUM_GLIDE_RATIO = 10.0f;
private final AirDataComputer data;
private final FlightPlanner plan;
public float descentImpactTime = STATUS_UNKNOWN;
public float terrainImpactTime = STATUS_UNKNOWN;
public Vector2d terrainAvoidVector = new Vector2d();
public LandingClearanceStatus landingClearanceStatus = LandingClearanceStatus.UNKNOWN;
public boolean fireworkUseSafe = true;

public GPWSComputer(AirDataComputer data, FlightPlanner plan) {
Expand All @@ -42,6 +44,7 @@ public GPWSComputer(AirDataComputer data, FlightPlanner plan) {
public void tick() {
descentImpactTime = this.computeDescentImpactTime();
terrainImpactTime = this.computeTerrainImpactTime();
landingClearanceStatus = this.computeLandingClearanceStatus();
fireworkUseSafe = this.computeFireworkUseSafe();
}

Expand Down Expand Up @@ -138,6 +141,26 @@ private boolean computeFireworkUseSafe() {
return distance / FIREWORK_SPEED > PULL_UP_THRESHOLD;
}

private LandingClearanceStatus computeLandingClearanceStatus() {
if (!data.isFlying() || data.player().isTouchingWater()) {
return LandingClearanceStatus.UNKNOWN;
}
if (!plan.landingInProgress) {
return LandingClearanceStatus.NOT_LANDING;
}

Double distance = plan.getDistanceToNextWaypoint();
if (distance == null) {
throw new AssertionError();
}

if (data.velocity.y > -3.0f || distance / data.heightAboveGround() <= OPTIMUM_GLIDE_RATIO) {
return LandingClearanceStatus.SAFE;
}

return LandingClearanceStatus.TOO_LOW;
}

private boolean positiveLessOrEquals(float time, float lessOrEquals) {
if (time < 0.0f) {
return false;
Expand Down Expand Up @@ -165,6 +188,14 @@ public void reset() {
descentImpactTime = STATUS_UNKNOWN;
terrainImpactTime = STATUS_UNKNOWN;
terrainAvoidVector = new Vector2d();
landingClearanceStatus = LandingClearanceStatus.UNKNOWN;
fireworkUseSafe = true;
}

public enum LandingClearanceStatus {
TOO_LOW,
SAFE,
NOT_LANDING,
UNKNOWN
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class ComputerConfig {
public WarningMode terrainWarning = WarningMode.SCREEN_AND_AUDIO;
@SerialEntry
public ProtectionMode terrainProtection = ProtectionMode.HARD;
@SerialEntry
public WarningMode landingClearanceWarning = WarningMode.SCREEN_AND_AUDIO;

@SerialEntry
public ProtectionMode voidProtection = ProtectionMode.HARD;
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/flightassistant/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"config.flightassistant.computers.gpws.sinkrate.protection": "Sinkrate protection mode",
"config.flightassistant.computers.gpws.terrain.warning": "Terrain warning mode",
"config.flightassistant.computers.gpws.terrain.protection": "Terrain protection mode",
"config.flightassistant.computers.gpws.landing.warning": "Landing clearance warning mode",
"config.flightassistant.computers.void_level": "Void level",
"config.flightassistant.computers.void_level.protection": "Void level protection mode",
"config.flightassistant.computers.void_level.fireworks": "Use fireworks for recovery",
Expand All @@ -99,6 +100,7 @@
"alerts.flightassistant.sink_rate": "SINK RATE",
"alerts.flightassistant.stall": "STALL",
"alerts.flightassistant.terrain_ahead": "TERRAIN AHEAD",
"alerts.flightassistant.too_low_terrain": "TOO LOW - TERRAIN",

"alerts.flightassistant.elytra_health_low": "ELYTRA HEALTH LOW",

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/flightassistant/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"config.flightassistant.computers.gpws.sinkrate.protection": "Режим защиты от быстрого снижения",
"config.flightassistant.computers.gpws.terrain.warning": "Режим предупреждения о приближении к земле",
"config.flightassistant.computers.gpws.terrain.protection": "Режим защиты от приближения к земле",
"config.flightassistant.computers.gpws.landing.warning": "Режим предупреждения о близости с землёй при посадке",
"config.flightassistant.computers.void_level": "Уровень пустоты",
"config.flightassistant.computers.void_level.protection": "Режим защиты от пересечения уровня пустоты",
"config.flightassistant.computers.void_level.fireworks": "Использовать фейерверки для восстановления",
Expand All @@ -100,6 +101,7 @@
"alerts.flightassistant.sink_rate": "СКОР. СНИЖЕНИЯ",
"alerts.flightassistant.stall": "СВАЛИВАНИЕ",
"alerts.flightassistant.terrain_ahead": "ЗЕМЛЯ ВПЕРЕДИ",
"alerts.flightassistant.too_low_terrain": "СЛИШКОМ НИЗКО - ЗЕМЛЯ",

"alerts.flightassistant.elytra_health_low": "ЗДОРОВЬЕ ЭЛИТР НИЗК.",

Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/assets/flightassistant/sounds.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"flightassistant:terrain"
]
},
"too_low_terrain": {
"sounds": [
"flightassistant:too_low_terrain"
]
},
"warning": {
"sounds": [
"flightassistant:warning"
Expand Down
Binary file not shown.

0 comments on commit 8f60698

Please sign in to comment.