SF: Minor cleanup on horizontal buffer.

* Remove code duplication by checking buffer regain after all other.
	The usual case is that regain is checked anyway.
* Don't use buffer for bunnyfly. Makes tags more unique.
This commit is contained in:
asofold 2013-07-22 18:51:48 +02:00
parent ec956a9be0
commit d31fe6b53e

View File

@ -197,9 +197,6 @@ public class SurvivalFly extends Check {
else{ else{
data.hVelActive.clear(); data.hVelActive.clear();
hFreedom = 0.0; hFreedom = 0.0;
if (data.sfHorizontalBuffer < hBufMax && hDistance > 0.0){
hBufRegain(hDistance, hDistanceAboveLimit, data);
}
} }
// Prevent players from walking on a liquid in a too simple way. // Prevent players from walking on a liquid in a too simple way.
@ -233,6 +230,11 @@ public class SurvivalFly extends Check {
} }
} }
} }
// Finally check horizontal buffer regain.
if (hDistanceAboveLimit < 0.0 && hDistance > 0.0 && data.sfHorizontalBuffer < hBufMax) {
hBufRegain(hDistance, hDistanceAboveLimit, data);
}
////////////////////////// //////////////////////////
// Vertical move. // Vertical move.
@ -840,7 +842,7 @@ public class SurvivalFly extends Check {
// TODO: Speed effect affects hDistanceAboveLimit? // TODO: Speed effect affects hDistanceAboveLimit?
// TODO: Might want to check assumeonground or from on ground (!). // TODO: Might want to check assumeonground or from on ground (!).
data.bunnyhopDelay = bunnyHopMax; data.bunnyhopDelay = bunnyHopMax;
hDistanceAboveLimit = 0D; // TODO: maybe relate buffer use to this + sprinting ? hDistanceAboveLimit = 0D;
tags.add("bunnyhop"); // TODO: Which here... tags.add("bunnyhop"); // TODO: Which here...
} }
} }
@ -849,10 +851,9 @@ public class SurvivalFly extends Check {
if (data.sfLastHDist != Double.MAX_VALUE){ if (data.sfLastHDist != Double.MAX_VALUE){
// Speed must decrease by "a lot" at first, then by some minimal amount per event. // Speed must decrease by "a lot" at first, then by some minimal amount per event.
if (data.sfLastHDist - hDistance >= data.sfLastHDist / 100.0 && hDistanceAboveLimit <= someThreshold){ if (data.sfLastHDist - hDistance >= data.sfLastHDist / 100.0 && hDistanceAboveLimit <= someThreshold){
// Increase buffer by the needed amount. // TODO: Confine further (max. amount)?
final double amount = hDistance - hAllowedDistance; // Allow the move.
// TODO: Might use min(hAllowedDistance and some maximal thing like sprinting speed?) hDistanceAboveLimit = 0.0;
data.sfHorizontalBuffer = Math.min(hBufMax, data.sfHorizontalBuffer) + amount; // Cheat !
tags.add("bunnyfly"); tags.add("bunnyfly");
} }
} }
@ -860,19 +861,14 @@ public class SurvivalFly extends Check {
} }
// Horizontal buffer. // Horizontal buffer.
if (hDistanceAboveLimit > 0.0) { if (hDistanceAboveLimit > 0.0 && data.sfHorizontalBuffer > 0.0) {
// Handle buffer only if moving too far. // Handle buffer only if moving too far.
if (data.sfHorizontalBuffer > 0.0) { // Consume buffer.
// Consume buffer. tags.add("hbufuse");
tags.add("hbufuse"); final double amount = Math.min(data.sfHorizontalBuffer, hDistanceAboveLimit);
final double amount = Math.min(data.sfHorizontalBuffer, hDistanceAboveLimit); hDistanceAboveLimit -= amount;
hDistanceAboveLimit -= amount; // Ensure we never end up below zero.
// Ensure we never end up below zero. data.sfHorizontalBuffer = Math.max(0.0, data.sfHorizontalBuffer - amount);
data.sfHorizontalBuffer = Math.max(0.0, data.sfHorizontalBuffer - amount);
}
// else: No consumption.
} else if (data.sfHorizontalBuffer < hBufMax && hDistance > 0.0) {
hBufRegain(hDistance, hDistanceAboveLimit, data);
} }
// Add the hspeed tag on violation. // Add the hspeed tag on violation.