Skip to content

Commit 778f573

Browse files
committed
fix: sync homeward protocols with main
2 parents 336c6e2 + 0f435a5 commit 778f573

6 files changed

Lines changed: 58 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,4 @@
185185
- feat: new horror-themed disc [stage_4] | by [@Loqor](https://github.com/Loqor) ([#2161](https://github.com/amblelabs/ait/pull/2161))
186186
- feat: new copper console model! | by [@Loqor](https://github.com/Loqor) ([#2162](https://github.com/amblelabs/ait/pull/2162))
187187
- fix: revert interior config back to the old one! | by [@rapbattlegod32](https://github.com/rapbattlegod32) ([#2165](https://github.com/amblelabs/ait/pull/2165))
188+
- feat: hard cap on missed flight events, if hit, crashes tardis | by [@Loqor](https://github.com/Loqor) ([#2173](https://github.com/amblelabs/ait/pull/2173))

src/main/java/dev/amble/ait/core/tardis/control/sequences/Sequence.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public void execute(Tardis tardis, @Nullable ServerPlayerEntity player) {
120120

121121
@Override
122122
public void executeMissed(Tardis tardis, @Nullable ServerPlayerEntity player) {
123+
tardis.travel().missEvent();
123124
this.executeMissed.run(tardis);
124125
}
125126

src/main/java/dev/amble/ait/core/tardis/handler/travel/ProgressiveTravelHandler.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import dev.amble.ait.core.AITSounds;
66
import dev.amble.ait.core.tardis.Tardis;
77
import dev.amble.ait.core.tardis.control.sequences.SequenceHandler;
8+
import dev.amble.ait.data.Exclude;
89
import dev.amble.ait.data.properties.bool.BoolProperty;
910
import dev.amble.ait.data.properties.bool.BoolValue;
1011
import dev.amble.ait.data.properties.integer.IntProperty;
@@ -33,6 +34,12 @@ public abstract class ProgressiveTravelHandler extends TravelHandlerBase {
3334
protected final BoolValue handbrake = HANDBRAKE.create(this);
3435
protected final BoolValue autopilot = AUTOPILOT.create(this);
3536

37+
@Exclude(strategy = Exclude.Strategy.NETWORK)
38+
private int missedEvents;
39+
40+
@Exclude(strategy = Exclude.Strategy.NETWORK)
41+
private int missedHardCap;
42+
3643
public ProgressiveTravelHandler(Id id) {
3744
super(id);
3845
}
@@ -46,6 +53,8 @@ public void onLoaded() {
4653

4754
handbrake.of(this, HANDBRAKE);
4855
autopilot.of(this, AUTOPILOT);
56+
57+
this.updateMissedHardCap(this.getTargetTicks());
4958
}
5059

5160
private boolean isInFlight() {
@@ -97,13 +106,15 @@ public void recalculate() {
97106
}
98107

99108
protected void startFlight() {
109+
this.resetMissed();
100110
this.setFlightTicks(0);
101111
this.setTargetTicks(TravelUtil.getFlightDuration(this.position(), this.destination()));
102112
}
103113

104114
protected void resetFlight() {
105115
this.setFlightTicks(0);
106116
this.setTargetTicks(0);
117+
this.resetMissed();
107118
}
108119

109120
public int getFlightTicks() {
@@ -120,6 +131,13 @@ public int getTargetTicks() {
120131

121132
protected void setTargetTicks(int ticks) {
122133
this.targetTicks.set(ticks);
134+
this.updateMissedHardCap(ticks);
135+
}
136+
137+
private void updateMissedHardCap(int targetTicks) {
138+
int newHardCap = TravelUtil.getHardCap(targetTicks);
139+
this.missedEvents = TravelUtil.rescaleMissedEvents(this.missedEvents, this.missedHardCap, newHardCap);
140+
this.missedHardCap = newHardCap;
123141
}
124142

125143
public void handbrake(boolean value) {
@@ -222,4 +240,22 @@ public void triggerSequencingDuringFlight(Tardis tardis) {
222240
sequences.triggerRandomSequence(true);
223241
}
224242
}
243+
244+
public void missEvent() {
245+
if (this.getState() != State.FLIGHT || this.getTargetTicks() <= 0)
246+
return;
247+
248+
if (this.missedHardCap <= 0)
249+
this.updateMissedHardCap(this.getTargetTicks());
250+
251+
this.missedEvents++;
252+
if (this.missedEvents >= this.missedHardCap) {
253+
this.tardis().crash();
254+
this.resetMissed();
255+
}
256+
}
257+
258+
public void resetMissed() {
259+
this.missedEvents = 0;
260+
}
225261
}

src/main/java/dev/amble/ait/core/tardis/handler/travel/TravelHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,8 @@ public Optional<ActionQueue> forceRemat() {
595595
if (this.tardis.sequence().hasActiveSequence())
596596
this.tardis.sequence().cancelActiveSequence();
597597

598+
this.resetMissed();
599+
598600
CachedDirectedGlobalPos initialPos = this.getProgress();
599601
boolean destinationHome = this.tardis.returnHome().isDestinationHome();
600602
boolean exactHailMaryLanding = this.tardis.returnHome().isHailMaryExactLanding();

src/main/java/dev/amble/ait/core/tardis/handler/travel/TravelUtil.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
public class TravelUtil {
1818

1919
private static final int BASE_FLIGHT_TICKS = 5 * 20;
20+
private static final int QUICK_FLIGHT_THRESHOLD = 128;
2021

2122
public static void randomPos(Tardis tardis, int limit, int max, Consumer<CachedDirectedGlobalPos> consumer) {
2223
TravelHandler travel = tardis.travel();
@@ -78,7 +79,7 @@ public static int getFlightDuration(CachedDirectedGlobalPos source, CachedDirect
7879
boolean hasDirChanged = source.getRotation() != destination.getRotation();
7980
boolean hasDimChanged = !source.getDimension().equals(destination.getDimension());
8081

81-
if (distance < 128 && !hasDimChanged)
82+
if (distance < QUICK_FLIGHT_THRESHOLD && !hasDimChanged)
8283
return 1; // fast travel
8384

8485
return (int) (BASE_FLIGHT_TICKS + (distance / 10f) + (hasDirChanged ? 100 : 0) + (hasDimChanged ? 600 : 0));
@@ -119,4 +120,20 @@ public static CachedDirectedGlobalPos jukePos(CachedDirectedGlobalPos pos, int m
119120
public static CachedDirectedGlobalPos jukePos(CachedDirectedGlobalPos pos, int min, int max) {
120121
return jukePos(pos, min, max, 1);
121122
}
123+
124+
public static int getHardCap(int targetTicks) {
125+
if (targetTicks <= QUICK_FLIGHT_THRESHOLD) return 1;
126+
return 1 + MathHelper.floor(1d / 6d * MathHelper.sqrt(targetTicks - QUICK_FLIGHT_THRESHOLD));
127+
}
128+
129+
static int rescaleMissedEvents(int missedEvents, int previousHardCap, int newHardCap) {
130+
int normalizedHardCap = Math.max(newHardCap, 1);
131+
int maximumMissedEvents = normalizedHardCap - 1;
132+
133+
if (missedEvents <= 0) return 0;
134+
if (previousHardCap <= 0) return MathHelper.clamp(missedEvents, 0, maximumMissedEvents);
135+
136+
long proportionalMisses = (long) missedEvents * normalizedHardCap / previousHardCap;
137+
return MathHelper.clamp((int) Math.min(proportionalMisses, Integer.MAX_VALUE), 0, maximumMissedEvents);
138+
}
122139
}
37.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)