Skip to content

Commit 672a981

Browse files
committed
add config options for new alerts
Signed-off-by: Octol1ttle <[email protected]>
1 parent 89eeb02 commit 672a981

File tree

12 files changed

+120
-13
lines changed

12 files changed

+120
-13
lines changed

src/main/kotlin/ru/octol1ttle/flightassistant/config/FAConfigScreen.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,36 @@ object FAConfigScreen {
399399
binding(current::obstacleAutoPitch, defaults.obstacleAutoPitch)
400400
controller(tickBox())
401401
}
402+
rootOptions.register("gpws.altitude_loss_with_toga.enabled") {
403+
setSafetyName()
404+
binding(current::altitudeLossAlert, defaults.altitudeLossAlert)
405+
controller(tickBox())
406+
}
407+
rootOptions.register("gpws.altitude_loss_with_toga.alert_method") {
408+
setSafetyName()
409+
binding(current::altitudeLossAlertMethod, defaults.altitudeLossAlertMethod)
410+
controller(enumSwitch(SafetyOptions.AlertMethod::class.java))
411+
}
412+
rootOptions.register("gpws.unsafe_terrain_clearance.enabled") {
413+
setSafetyName()
414+
binding(current::unsafeTerrainClearanceAlert, defaults.unsafeTerrainClearanceAlert)
415+
controller(tickBox())
416+
}
417+
rootOptions.register("gpws.unsafe_terrain_clearance.alert_method") {
418+
setSafetyName()
419+
binding(current::unsafeTerrainClearanceAlertMethod, defaults.unsafeTerrainClearanceAlertMethod)
420+
controller(enumSwitch(SafetyOptions.AlertMethod::class.java))
421+
}
422+
rootOptions.register("gpws.below_glide_slope.alert_mode") {
423+
setSafetyName()
424+
binding(current::belowGlideSlopeAlertMode, defaults.belowGlideSlopeAlertMode)
425+
controller(enumSwitch(SafetyOptions.AlertMode::class.java))
426+
}
427+
rootOptions.register("gpws.below_glide_slope.alert_method") {
428+
setSafetyName()
429+
binding(current::belowGlideSlopeAlertMethod, defaults.belowGlideSlopeAlertMethod)
430+
controller(enumSwitch(SafetyOptions.AlertMethod::class.java))
431+
}
402432

403433
rootOptions.registerLabel(
404434
"firework",

src/main/kotlin/ru/octol1ttle/flightassistant/config/options/SafetyOptions.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class SafetyOptions {
4242
@SerialEntry
4343
var sinkRateAlertMethod: AlertMethod = AlertMethod.SCREEN_AND_AUDIO
4444
@SerialEntry
45-
var sinkRateLimitPitch: Boolean = true // TODO: this often triggers BEFORE the automatic recovery. they should trigger at the same time and be paired with each other.
45+
var sinkRateLimitPitch: Boolean = true
4646
@SerialEntry
4747
var sinkRateAutoThrust: Boolean = true
4848
@SerialEntry
@@ -59,6 +59,21 @@ class SafetyOptions {
5959
@SerialEntry
6060
var obstacleAutoPitch: Boolean = true
6161

62+
@SerialEntry
63+
var altitudeLossAlert: Boolean = true
64+
@SerialEntry
65+
var altitudeLossAlertMethod: AlertMethod = AlertMethod.SCREEN_AND_AUDIO
66+
67+
@SerialEntry
68+
var unsafeTerrainClearanceAlert: Boolean = true
69+
@SerialEntry
70+
var unsafeTerrainClearanceAlertMethod: AlertMethod = AlertMethod.SCREEN_AND_AUDIO
71+
72+
@SerialEntry
73+
var belowGlideSlopeAlertMode: AlertMode = AlertMode.WARNING_AND_CAUTION
74+
@SerialEntry
75+
var belowGlideSlopeAlertMethod: AlertMethod = AlertMethod.SCREEN_AND_AUDIO
76+
6277
@SerialEntry
6378
var fireworkExplosiveAlert: Boolean = true
6479
@SerialEntry

src/main/kotlin/ru/octol1ttle/flightassistant/impl/alert/flight_plan/ArrivalElevationDisagreeAlert.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ArrivalElevationDisagreeAlert(computers: ComputerBus) : Alert(computers),
2222
}
2323
val x = computers.plan.arrivalData.coordinatesX
2424
val z = computers.plan.arrivalData.coordinatesZ
25-
if (!computers.data.isChunkLoaded(x, z)) {
25+
if (!computers.chunk.isLoaded(x, z)) {
2626
return false
2727
}
2828
val actualElevation: Int = computers.data.level.getHeight(Heightmap.Types.MOTION_BLOCKING, x, z)
@@ -31,7 +31,7 @@ class ArrivalElevationDisagreeAlert(computers: ComputerBus) : Alert(computers),
3131

3232
override fun render(guiGraphics: GuiGraphics, firstLineX: Int, otherLinesX: Int, firstLineY: Int): Int {
3333
var i = 0
34-
guiGraphics.drawString(Component.translatable("alert.flightassistant.flight_plan.arrival_elevation_disagree"), firstLineX, firstLineY, cautionColor)
34+
i += guiGraphics.drawString(Component.translatable("alert.flightassistant.flight_plan.arrival_elevation_disagree"), firstLineX, firstLineY, cautionColor)
3535
var y = firstLineY + 1
3636

3737
y += 10

src/main/kotlin/ru/octol1ttle/flightassistant/impl/alert/gpws/BelowGlideSlopeAlert.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ import ru.octol1ttle.flightassistant.api.util.FATickCounter.totalTicks
1010
import ru.octol1ttle.flightassistant.api.util.extensions.cautionColor
1111
import ru.octol1ttle.flightassistant.api.util.extensions.centerX
1212
import ru.octol1ttle.flightassistant.api.util.extensions.drawHighlightedCenteredText
13+
import ru.octol1ttle.flightassistant.config.FAConfig
14+
import ru.octol1ttle.flightassistant.config.options.SafetyOptions
1315
import ru.octol1ttle.flightassistant.impl.computer.autoflight.FlightPlanComputer
1416

1517
class BelowGlideSlopeAlert(computers: ComputerBus) : Alert(computers), CenteredAlert {
1618
override val data: AlertData
1719
get() = AlertData.BELOW_GLIDE_SLOPE
1820

1921
override fun shouldActivate(): Boolean {
22+
if (!FAConfig.safety.belowGlideSlopeAlertMode.caution()) {
23+
return false
24+
}
2025
if (computers.plan.currentPhase != FlightPlanComputer.FlightPhase.LANDING) {
2126
return false
2227
}
@@ -29,4 +34,8 @@ class BelowGlideSlopeAlert(computers: ComputerBus) : Alert(computers), CenteredA
2934
guiGraphics.drawHighlightedCenteredText(Component.translatable("alert.flightassistant.gpws.below_glide_slope"), guiGraphics.centerX, y, cautionColor, totalTicks % 40 >= 20)
3035
return true
3136
}
37+
38+
override fun getAlertMethod(): SafetyOptions.AlertMethod {
39+
return FAConfig.safety.belowGlideSlopeAlertMethod
40+
}
3241
}

src/main/kotlin/ru/octol1ttle/flightassistant/impl/alert/gpws/BelowGlideSlopeWarningAlert.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ import ru.octol1ttle.flightassistant.api.util.FATickCounter.totalTicks
1010
import ru.octol1ttle.flightassistant.api.util.extensions.centerX
1111
import ru.octol1ttle.flightassistant.api.util.extensions.drawHighlightedCenteredText
1212
import ru.octol1ttle.flightassistant.api.util.extensions.warningColor
13+
import ru.octol1ttle.flightassistant.config.FAConfig
14+
import ru.octol1ttle.flightassistant.config.options.SafetyOptions
1315
import ru.octol1ttle.flightassistant.impl.computer.autoflight.FlightPlanComputer
1416

1517
class BelowGlideSlopeWarningAlert(computers: ComputerBus) : Alert(computers), CenteredAlert {
1618
override val data: AlertData
1719
get() = AlertData.BELOW_GLIDE_SLOPE_WARNING
1820

1921
override fun shouldActivate(): Boolean {
22+
if (!FAConfig.safety.belowGlideSlopeAlertMode.warning()) {
23+
return false
24+
}
2025
if (computers.plan.currentPhase != FlightPlanComputer.FlightPhase.LANDING) {
2126
return false
2227
}
@@ -30,4 +35,8 @@ class BelowGlideSlopeWarningAlert(computers: ComputerBus) : Alert(computers), Ce
3035
guiGraphics.drawHighlightedCenteredText(Component.translatable("alert.flightassistant.gpws.below_glide_slope"), guiGraphics.centerX, y, warningColor, totalTicks % 20 >= 10)
3136
return true
3237
}
38+
39+
override fun getAlertMethod(): SafetyOptions.AlertMethod {
40+
return FAConfig.safety.belowGlideSlopeAlertMethod
41+
}
3342
}

src/main/kotlin/ru/octol1ttle/flightassistant/impl/alert/gpws/DontSinkAlert.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import ru.octol1ttle.flightassistant.api.util.FATickCounter.totalTicks
1111
import ru.octol1ttle.flightassistant.api.util.extensions.cautionColor
1212
import ru.octol1ttle.flightassistant.api.util.extensions.centerX
1313
import ru.octol1ttle.flightassistant.api.util.extensions.drawHighlightedCenteredText
14+
import ru.octol1ttle.flightassistant.config.FAConfig
15+
import ru.octol1ttle.flightassistant.config.options.SafetyOptions
1416
import ru.octol1ttle.flightassistant.impl.computer.autoflight.FlightPlanComputer
1517

1618
class DontSinkAlert(computers: ComputerBus) : Alert(computers), CenteredAlert {
@@ -19,6 +21,9 @@ class DontSinkAlert(computers: ComputerBus) : Alert(computers), CenteredAlert {
1921
private var age: Int = 0
2022

2123
override fun shouldActivate(): Boolean {
24+
if (!FAConfig.safety.altitudeLossAlert) {
25+
return false
26+
}
2227
if ((computers.plan.currentPhase == FlightPlanComputer.FlightPhase.TAKEOFF || computers.plan.currentPhase == FlightPlanComputer.FlightPhase.GO_AROUND)
2328
&& !computers.data.fallDistanceSafe && computers.data.velocity.y < 0) {
2429
age += FATickCounter.ticksPassed
@@ -33,4 +38,8 @@ class DontSinkAlert(computers: ComputerBus) : Alert(computers), CenteredAlert {
3338
guiGraphics.drawHighlightedCenteredText(Component.translatable("alert.flightassistant.gpws.dont_sink"), guiGraphics.centerX, y, cautionColor, totalTicks % 40 >= 20)
3439
return true
3540
}
41+
42+
override fun getAlertMethod(): SafetyOptions.AlertMethod {
43+
return FAConfig.safety.altitudeLossAlertMethod
44+
}
3645
}

src/main/kotlin/ru/octol1ttle/flightassistant/impl/alert/gpws/TooLowTerrainAlert.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ru.octol1ttle.flightassistant.impl.alert.gpws
22

3+
import kotlin.math.max
34
import net.minecraft.client.gui.GuiGraphics
45
import net.minecraft.network.chat.Component
56
import ru.octol1ttle.flightassistant.api.alert.Alert
@@ -10,14 +11,26 @@ import ru.octol1ttle.flightassistant.api.util.FATickCounter.totalTicks
1011
import ru.octol1ttle.flightassistant.api.util.extensions.cautionColor
1112
import ru.octol1ttle.flightassistant.api.util.extensions.centerX
1213
import ru.octol1ttle.flightassistant.api.util.extensions.drawHighlightedCenteredText
14+
import ru.octol1ttle.flightassistant.config.FAConfig
15+
import ru.octol1ttle.flightassistant.config.options.SafetyOptions
1316
import ru.octol1ttle.flightassistant.impl.computer.autoflight.FlightPlanComputer
1417

1518
class TooLowTerrainAlert(computers: ComputerBus) : Alert(computers), CenteredAlert {
1619
override val data: AlertData
1720
get() = AlertData.TOO_LOW_TERRAIN
1821

22+
private var maxRadarAltitude: Double = 0.0
23+
1924
override fun shouldActivate(): Boolean {
25+
if (!FAConfig.safety.unsafeTerrainClearanceAlert) {
26+
return false
27+
}
28+
2029
val altitudeAboveGround = computers.data.altitude - (computers.data.groundY ?: return false)
30+
maxRadarAltitude = max(maxRadarAltitude, altitudeAboveGround)
31+
if (maxRadarAltitude < 15) {
32+
return false
33+
}
2134

2235
return when (computers.plan.currentPhase) {
2336
FlightPlanComputer.FlightPhase.UNKNOWN,
@@ -40,4 +53,8 @@ class TooLowTerrainAlert(computers: ComputerBus) : Alert(computers), CenteredAle
4053
guiGraphics.drawHighlightedCenteredText(Component.translatable("alert.flightassistant.gpws.too_low_terrain"), guiGraphics.centerX, y, cautionColor, totalTicks % 40 >= 20)
4154
return true
4255
}
56+
57+
override fun getAlertMethod(): SafetyOptions.AlertMethod {
58+
return FAConfig.safety.unsafeTerrainClearanceAlertMethod
59+
}
4360
}

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/autoflight/modes/BuiltInThrustModes.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ data class VerticalProfileThrustMode(val climbThrust: Float, val descendThrust:
3838
if (verticalMode !is AutoFlightComputer.FollowsAltitudeMode) {
3939
return null
4040
}
41-
val nearTarget: Boolean = abs(verticalMode.targetAltitude - computers.data.altitude) <= 10.0f
41+
val nearTarget: Boolean = abs(verticalMode.targetAltitude - computers.data.altitude) <= 5.0f
4242
val useClimbThrust: Boolean = nearTarget || verticalMode.targetAltitude > computers.data.altitude
4343
return ControlInput(
4444
if (useClimbThrust) climbThrust else descendThrust,

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/data/AirDataComputer.kt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import net.minecraft.client.Minecraft
66
import net.minecraft.client.multiplayer.ClientLevel
77
import net.minecraft.client.player.LocalPlayer
88
import net.minecraft.core.Direction
9-
import net.minecraft.core.SectionPos
109
import net.minecraft.resources.ResourceLocation
1110
import net.minecraft.tags.DamageTypeTags
1211
import net.minecraft.util.Mth
@@ -79,20 +78,13 @@ class AirDataComputer(computers: ComputerBus, private val mc: Minecraft) : Compu
7978
val flightPitch: Float
8079
get() = degrees(asin(velocity.normalize().y).toFloat())
8180

82-
val isCurrentChunkLoaded: Boolean
83-
get() = level.chunkSource.hasChunk(player.chunkPosition().x, player.chunkPosition().z)
84-
8581
override fun tick() {
8682
groundY = computeGroundLevel()
8783
forwardVelocity = computeForwardVector(velocity)
8884
forwardVelocityPerSecond = forwardVelocity.perSecond()
8985
forwardAcceleration = forwardVelocity.length() - computeForwardVector(player.getDeltaMovementLerped(0.0f)).length()
9086
}
9187

92-
fun isChunkLoaded(x: Int, z: Int): Boolean {
93-
return level.chunkSource.hasChunk(SectionPos.blockToSectionCoord(x), SectionPos.blockToSectionCoord(z))
94-
}
95-
9688
fun automationsAllowed(checkFlying: Boolean = true): Boolean {
9789
return (!checkFlying || flying) && (FAConfig.global.automationsAllowedInOverlays || (mc.screen == null && mc.overlay == null))
9890
}
@@ -110,7 +102,7 @@ class AirDataComputer(computers: ComputerBus, private val mc: Minecraft) : Compu
110102
}
111103

112104
private fun computeGroundLevel(): Double? {
113-
if (!isCurrentChunkLoaded) {
105+
if (!computers.chunk.isCurrentLoaded) {
114106
return groundY
115107
}
116108

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/safety/ChunkStatusComputer.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ package ru.octol1ttle.flightassistant.impl.computer.safety
22

33
import kotlin.math.abs
44
import net.minecraft.client.multiplayer.ClientChunkCache
5+
import net.minecraft.core.SectionPos
56
import net.minecraft.resources.ResourceLocation
67
import net.minecraft.world.level.ChunkPos
78
import ru.octol1ttle.flightassistant.FlightAssistant
89
import ru.octol1ttle.flightassistant.api.computer.Computer
910
import ru.octol1ttle.flightassistant.api.computer.ComputerBus
1011

1112
class ChunkStatusComputer(computers: ComputerBus) : Computer(computers) {
13+
val isCurrentLoaded: Boolean
14+
get() = computers.data.level.chunkSource.hasChunk(computers.data.player.chunkPosition().x, computers.data.player.chunkPosition().z)
15+
1216
var status: Status = Status.LOADED
1317
private set
1418

@@ -38,6 +42,10 @@ class ChunkStatusComputer(computers: ComputerBus) : Computer(computers) {
3842
}
3943
}
4044

45+
fun isLoaded(x: Int, z: Int): Boolean {
46+
return computers.data.level.chunkSource.hasChunk(SectionPos.blockToSectionCoord(x), SectionPos.blockToSectionCoord(z))
47+
}
48+
4149
override fun reset() {
4250
status = Status.LOADED
4351
}

0 commit comments

Comments
 (0)