Skip to content

Commit

Permalink
feat: void damage protection
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <[email protected]>
  • Loading branch information
Octol1ttle committed Oct 24, 2023
1 parent 6207680 commit bbf2c5a
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.torocraft.flighthud.alerts.AlertSoundData;
import net.torocraft.flighthud.alerts.ECAMSoundData;
import net.torocraft.flighthud.computers.FlightComputer;
import net.torocraft.flighthud.computers.VoidDamageLevelComputer;
import org.jetbrains.annotations.NotNull;

import static net.torocraft.flighthud.HudComponent.CONFIG;
Expand All @@ -21,7 +22,7 @@ public ApproachingVoidDamageLevelAlert(FlightComputer computer) {

@Override
public boolean isTriggered() {
return computer.groundLevel == computer.voidLevel && computer.altitude < computer.voidLevel + 8;
return computer.voidDamage.status >= VoidDamageLevelComputer.STATUS_APPROACHING_DAMAGE_LEVEL;
}

@Override
Expand All @@ -31,8 +32,11 @@ public boolean isTriggered() {

@Override
public int renderECAM(TextRenderer textRenderer, DrawContext context, float x, float y, boolean highlight) {
return HudComponent.drawHighlightedFont(textRenderer, context, x, y,
Text.translatable("alerts.flighthud.nav.approaching_void_damage_level"),
Text text = computer.voidDamage.status == VoidDamageLevelComputer.STATUS_REACHED_DAMAGE_LEVEL
? Text.translatable("alerts.flighthud.nav.reached_void_damage_level")
: Text.translatable("alerts.flighthud.nav.approaching_void_damage_level");

return HudComponent.drawHighlightedFont(textRenderer, context, x, y, text,
CONFIG.alertColor,
!dismissed && highlight);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class FlightComputer {
public final AutoFlightComputer autoflight;
public final TimeComputer time;
public final StallComputer stall;
public final VoidDamageLevelComputer voidDamage;
public final PitchController pitchController;
public final AlertController alertController;
@NotNull
Expand Down Expand Up @@ -57,6 +58,7 @@ public FlightComputer(@NotNull MinecraftClient mc) {
this.gpws = new GPWSComputer(this);
this.autoflight = new AutoFlightComputer(this);
this.stall = new StallComputer(this);
this.voidDamage = new VoidDamageLevelComputer(this);
this.time = new TimeComputer();
this.pitchController = new PitchController(this);
this.alertController = new AlertController(this, mc.getSoundManager());
Expand Down Expand Up @@ -101,6 +103,7 @@ public void tick() {
autoflight.tick();
alertController.tick();
stall.tick();
voidDamage.tick();
}

public void updateRoll(Matrix3f normal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public void tick(float delta) {
smoothSetPitch(-computer.stall.maximumSafePitch, delta);
return;
}
if (computer.pitch < computer.voidDamage.minimumSafePitch) {
smoothSetPitch(-computer.voidDamage.minimumSafePitch, delta);
return;
}
if (forceLevelOff) {
smoothSetPitch(0.0f, MathHelper.clamp(delta / computer.gpws.descentImpactTime, 0.001f, 1.0f));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import net.minecraft.util.math.MathHelper;

public class StallComputer {
public static final int STATUS_APPROACHING_STALL = 1;
private static final int STATUS_FULL_STALL = 2;
public static final int STATUS_APPROACHING_STALL = 1;
private static final int STATUS_PITCH_SAFE = -1;
private static final int STATUS_FALL_DISTANCE_TOO_LOW = -2;
private static final int STATUS_AIRSPEED_SAFE = -3;
private static final int STATUS_AIRSPEED_SAFE = -2;
private static final int STATUS_FALL_DISTANCE_TOO_LOW = -3;
private final FlightComputer computer;
public int stalling;
public float maximumSafePitch;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.torocraft.flighthud.computers;

import net.torocraft.flighthud.indicators.PitchIndicator;

public class VoidDamageLevelComputer {
public static final int STATUS_REACHED_DAMAGE_LEVEL = 2;
public static final int STATUS_APPROACHING_DAMAGE_LEVEL = 1;
public static final int STATUS_ALTITUDE_SAFE = -1;
public static final int STATUS_NOT_ABOVE_VOID = -2;
public static final int STATUS_PLAYER_INVULNERABLE = -3;
private static final int OPTIMUM_ALTITUDE_PRESERVATION_PITCH = 10;

private final FlightComputer computer;
public int status;
public float minimumSafePitch;

public VoidDamageLevelComputer(FlightComputer computer) {
this.computer = computer;
}

public void tick() {
status = computeStatus();
minimumSafePitch = computeMinimumSafePitch();
}

private int computeStatus() {
if (computer.player.isInvulnerableTo(computer.player.getDamageSources().outOfWorld())) {
return STATUS_PLAYER_INVULNERABLE;
}

if (computer.groundLevel != computer.voidLevel) {
return STATUS_NOT_ABOVE_VOID;
}

if (computer.altitude - computer.voidLevel >= 8) {
return STATUS_ALTITUDE_SAFE;
}

if (computer.altitude >= computer.voidLevel) {
return STATUS_APPROACHING_DAMAGE_LEVEL;
}

// TODO: TOGA LK
return STATUS_REACHED_DAMAGE_LEVEL;
}

private float computeMinimumSafePitch() {
if (status <= STATUS_NOT_ABOVE_VOID) {
return -90.0f;
}
if (computer.altitude - computer.voidLevel < 20) {
return Math.min(OPTIMUM_ALTITUDE_PRESERVATION_PITCH, computer.stall.maximumSafePitch);
}

return PitchIndicator.DANGEROUS_DOWN_PITCH + 10;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void render(DrawContext context, TextRenderer textRenderer) {
drawReferenceMark(context, yHorizon, CONFIG.pitchLadder_optimumClimbAngle, CONFIG.color);
drawReferenceMark(context, yHorizon, CONFIG.pitchLadder_optimumGlideAngle, CONFIG.color);
drawReferenceMark(context, yHorizon, computer.stall.maximumSafePitch, CONFIG.alertColor);
drawReferenceMark(context, yHorizon, computer.voidDamage.minimumSafePitch, CONFIG.alertColor);

if (CONFIG.pitchLadder_showHorizon) {
pitchData.l1 -= pitchData.margin;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/torocraft/flighthud/mixin/EntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public void preventUpsetPitch(float pitch, CallbackInfo ci) {
boolean stalling = -pitch > computer.stall.maximumSafePitch
|| computer.stall.stalling >= StallComputer.STATUS_APPROACHING_STALL;
boolean highSinkRate = !stalling && computer.gpws.shouldBlockPitchChanges();
if (stalling && pitch < that.getPitch() || highSinkRate && pitch > that.getPitch())
boolean approachingVoidDamage = -pitch < computer.voidDamage.minimumSafePitch;
if (stalling && pitch < that.getPitch() || (highSinkRate || approachingVoidDamage) && pitch > that.getPitch())
ci.cancel();
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/flighthud/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"category.flighthud": "Flight HUD",
"key.flighthud.toggle_display_mode": "Switch Display Mode",
"key.flighthud.toggle_auto_thrust": "Toggle Auto Thrust",
"key.flighthud.dismiss_master_caution": "Silence (dismiss) yellow alerts",
"key.flighthud.dismiss_master_warning": "Silence (dismiss) master warning",
"key.flighthud.dismiss_master_caution": "Silence (dismiss) master caution",

"alerts.flighthud.pull_up": "PULL UP",
"alerts.flighthud.sink_rate": "SINK RATE",
"alerts.flighthud.stall": "STALL",
"alerts.flighthud.terrain_ahead": "TERRAIN AHEAD",
"alerts.flighthud.autoflight.athr_speed_not_set": "A/THR SPEED NOT SET",
"alerts.flighthud.nav.approaching_void_damage_level": "APPROACHING VOID DAMAGE LEVEL",
"alerts.flighthud.nav.reached_void_damage_level": "REACHED VOID DAMAGE LEVEL",

"flighthud.north_short": "N",
"flighthud.east_short": "E",
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/flighthud/lang/ru_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"category.flighthud": "Flight HUD",
"key.flighthud.toggle_display_mode": "Переключить режим интерфейса",
"key.flighthud.toggle_auto_thrust": "Вкл/выкл автомат тяги",
"key.flighthud.dismiss_master_caution": "Заглушить (убрать) жёлтое предупреждение",
"key.flighthud.dismiss_master_warning": "Заглушить (скрыть) предупреждение особой важности",
"key.flighthud.dismiss_master_caution": "Заглушить (скрыть) обычное предупреждение",

"alerts.flighthud.pull_up": "ТЯНИ ВВЕРХ",
"alerts.flighthud.sink_rate": "СКОР. СНИЖЕНИЯ",
"alerts.flighthud.stall": "СВАЛИВАНИЕ",
"alerts.flighthud.terrain_ahead": "ЗЕМЛЯ ВПЕРЕДИ",
"alerts.flighthud.autoflight.athr_speed_not_set": "СКОРОСТЬ А/ТЯГИ НЕ ВЫБРАНА",
"alerts.flighthud.nav.approaching_void_damage_level": "ПРИБЛИЖЕНИЕ К ВЫСОТЕ УРОНА ПУСТОТЫ",
"alerts.flighthud.nav.reached_void_damage_level": "ДОСТИГНУТА ВЫСОТА УРОНА ПУСТОТЫ",

"flighthud.north_short": "С",
"flighthud.east_short": "В",
Expand Down

0 comments on commit bbf2c5a

Please sign in to comment.