Skip to content

Commit

Permalink
coding fresh in the morning
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
  • Loading branch information
Octol1ttle committed Jun 16, 2024
1 parent 24fee22 commit f053908
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,20 @@ public DaBRThrustHandler() {
}

@Override
public boolean available() {
public boolean enabled() {
return ModConfig.INSTANCE.getEnableThrust();
}

@Override
public boolean isFireworkLike() {
public boolean canBeUsed() {
return true;
}

@Override
public boolean isFireworkLike() {
return false;
}

@Override
public void reset() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public interface IThrustHandler extends IComputer {
default void tickThrust() {
}

boolean available();
boolean enabled();

boolean canBeUsed();
boolean isFireworkLike();
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package ru.octol1ttle.flightassistant.computers.impl.autoflight;

import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.Nullable;
import org.joml.Vector2d;
import ru.octol1ttle.flightassistant.FAMathHelper;
import ru.octol1ttle.flightassistant.computers.api.ControlInput;
import ru.octol1ttle.flightassistant.computers.api.IAutopilotProvider;
import ru.octol1ttle.flightassistant.computers.api.IHeadingController;
Expand Down Expand Up @@ -65,39 +63,74 @@ public void tick() {
setTargetThrust(null, Text.empty());

setTargetPitch(null, Text.empty());
Integer targetAltitude = autoflight.getTargetAltitude();
if (targetAltitude == null) {
return;
}
if (!thrust.getThrustHandler().canBeUsed()) {
setTargetThrust(0.0f, Text.translatable("mode.flightassistant.thrust.unavailable"));
setTargetPitch(PitchController.GLIDE_PITCH, Text.translatable("mode.flightassistant.vert.glide"));
} else {
Integer targetAltitude = autoflight.getTargetAltitude();
if (targetAltitude != null) {
float diff = Math.abs(targetAltitude - data.altitude());
float speedAdjustment = targetSpeed != null ? data.speed() - targetSpeed : 0.0f;
if (autoflight.selectedAltitude != null) {
tickSelectedAltitude(diff, speedAdjustment);
} else {
tickManagedAltitude(diff, speedAdjustment);
}
}

float diff = targetAltitude - data.altitude();
tickSpeed(targetSpeed);
}
}

private void tickSelectedAltitude(float diff, float speedAdjustment) {
boolean useReducedThrust = thrust.getThrustHandler().isFireworkLike(); // I wish I didn't have to account for this
float climbThrust = useReducedThrust ? THRUST_CLIMB_REDUCED : THRUST_CLIMB;
String thrustSuffix = useReducedThrust ? "_reduced" : "";

if (autoflight.selectedAltitude != null) {
float speedAdjustment = targetSpeed != null ? data.speed() - targetSpeed : 0.0f;
if (targetAltitude >= data.altitude()) {
setTargetThrust(climbThrust, Text.translatable("mode.flightassistant.thrust.climb" + thrustSuffix));
float pitch;
if (useReducedThrust) {
pitch = 47.5f - 47.5f * (Math.max(20.0f - diff, 0.0f) / 15.0f) + 7.5f;
} else {
pitch = 55.0f - 55.0f * (Math.max(15.0f - diff, 0.0f) / 15.0f) + speedAdjustment;
}
setTargetPitch(pitch, Text.translatable("mode.flightassistant.vert.climb.selected"));

if (diff > 0) {
float pitch;
if (useReducedThrust) {
setTargetThrust(THRUST_CLIMB_REDUCED, Text.translatable("mode.flightassistant.thrust.climb_reduced"));
pitch = 47.5f - 47.5f * (Math.max(20.0f - Math.max(diff - 5, 0), 0.0f) / 20.0f) + 7.5f;
} else {
setTargetThrust(THRUST_CLIMB, Text.translatable("mode.flightassistant.thrust.climb"));
pitch = 55.0f - 55.0f * (Math.max(15.0f - diff, 0.0f) / 15.0f) + speedAdjustment;
}
setTargetPitch(pitch, Text.translatable("mode.flightassistant.vert.climb.selected", autoflight.selectedAltitude));
} else {
setTargetThrust(0.0f, Text.translatable("mode.flightassistant.thrust.idle"));
float pitch;
if (useReducedThrust) {
pitch = -25.0f + 25.0f * (Math.max(20.0f - Math.max(diff - 10, 0), 0.0f) / 20.0f) + 7.5f;
} else {
setTargetThrust(climbThrust, Text.translatable("mode.flightassistant.thrust.descend" + thrustSuffix));
pitch = -35.0f + 35.0f * (Math.max(15.0f - diff, 0.0f) / 15.0f) + speedAdjustment;
}
setTargetPitch(pitch, Text.translatable("mode.flightassistant.vert.descend.selected", autoflight.selectedAltitude));
}
}

if (targetAltitude > data.altitude()) {
private void tickManagedAltitude(float diff, float speedAdjustment) {
// TODO
boolean useReducedThrust = thrust.getThrustHandler().isFireworkLike();

if (diff > 0) {
float pitch;
if (useReducedThrust) {
setTargetThrust(THRUST_CLIMB_REDUCED, Text.translatable("mode.flightassistant.thrust.climb_reduced"));
pitch = 47.5f - 47.5f * (Math.max(20.0f - Math.max(diff - 5, 0), 0.0f) / 20.0f) + 7.5f;
} else {
setTargetThrust(THRUST_CLIMB, Text.translatable("mode.flightassistant.thrust.climb"));
pitch = 55.0f - 55.0f * (Math.max(15.0f - diff, 0.0f) / 15.0f) + speedAdjustment;
}
setTargetPitch(pitch, Text.translatable("mode.flightassistant.vert.climb.selected", autoflight.selectedAltitude));
} else {
setTargetThrust(0.0f, Text.translatable("mode.flightassistant.thrust.idle"));
float pitch;
if (useReducedThrust) {
pitch = -25.0f + 25.0f * (Math.max(20.0f - Math.max(diff - 10, 0), 0.0f) / 20.0f) + 7.5f;
} else {
pitch = -35.0f + 35.0f * (Math.max(15.0f - diff, 0.0f) / 15.0f) + speedAdjustment;
}
setTargetPitch(pitch, Text.translatable("mode.flightassistant.vert.descend.selected", autoflight.selectedAltitude));
}

// overwrite any thrust setting if we have a target speed
tickSpeed(targetSpeed);
}

private void tickSpeed(Integer targetSpeed) {
Expand All @@ -123,7 +156,7 @@ private void tickLateral() {
}
}

private Float computeTargetPitch() {
/*private Float computeTargetPitch() {
Integer targetAltitude = autoflight.getTargetAltitude();
if (targetAltitude == null) {
return null;
Expand Down Expand Up @@ -181,7 +214,7 @@ private float computeClimbPitch(float diff, Vector2d target) {
}
return degrees;
}
}*/

public Float getTargetPitch() {
return targetPitch;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,18 @@ public boolean isFireworkSafe(ItemStack stack) {
}

@Override
public boolean available() {
public boolean enabled() {
return true;
}

@Override
public boolean canBeUsed() {
return !noFireworks;
}

@Override
public boolean isFireworkLike() {
return false;
return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void updateTargetThrust() {
}

public IThrustHandler getThrustHandler() {
return thrustHandler.available() ? thrustHandler : fallback;
return thrustHandler.enabled() ? thrustHandler : fallback;
}

@Override
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/flightassistant/lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ mode.flightassistant:
relative: MINIM +%s
not_set: NO MINIMS
thrust:
unavailable: THR UNAVAIL
toga: TOGA
climb: THR CLB
climb_reduced: RED CLB
Expand All @@ -236,6 +237,7 @@ mode.flightassistant:
selected: SPD %s
managed: P. SPD %s
vert:
glide: OPT GLD
climb:
optimum: OPT CLB
selected: CLB %s
Expand Down
15 changes: 7 additions & 8 deletions src/main/resources/assets/flightassistant/lang/ru_ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,17 @@ mode.flightassistant:
absolute: МИНИМ %s
relative: МИНИМ +%s
not_set: НЕТ МИНИМ
firework:
none_in_hotbar: НЕТ ФРВКОВ
locked: ТОЛЬКО А/ФРВК
manual: РУЧН ФРВК
no_spd_alt: УСТАН СКОР/ВЫС
protection: ФРВК ЗАЩИТА
idle: ФРВК СНИЖ
climb: ФРВК НАБОР
thrust:
unavailable: ТЯГА НЕДОСТУПНА
toga: ВЗЛЕТН ТЯГА
climb: ТЯГА НАБОР
climb_reduced: СНИЖЕН НАБОР
idle: МАЛАЯ ТЯГА
speed:
selected: СКОР %s
managed: П. СКОР %s
vert:
glide: ОПТ ПЛАНИР
climb:
optimum: ОПТ НАБОР
selected: НАБОР %s
Expand Down

0 comments on commit f053908

Please sign in to comment.