Skip to content

Commit

Permalink
SF: Minor cleanup on horizontal buffer.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
asofold committed Jul 22, 2013
1 parent ec956a9 commit d31fe6b
Showing 1 changed file with 16 additions and 20 deletions.
Expand Up @@ -197,9 +197,6 @@ else if (now <= data.timeSprinting + cc.sprintingGrace) {
else{
data.hVelActive.clear();
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.
Expand Down Expand Up @@ -233,6 +230,11 @@ else if (now <= data.timeSprinting + cc.sprintingGrace) {
}
}
}

// Finally check horizontal buffer regain.
if (hDistanceAboveLimit < 0.0 && hDistance > 0.0 && data.sfHorizontalBuffer < hBufMax) {
hBufRegain(hDistance, hDistanceAboveLimit, data);
}

//////////////////////////
// Vertical move.
Expand Down Expand Up @@ -840,7 +842,7 @@ private double[] hDistAfterFailure(final Player player, final PlayerLocation fro
// TODO: Speed effect affects hDistanceAboveLimit?
// TODO: Might want to check assumeonground or from on ground (!).
data.bunnyhopDelay = bunnyHopMax;
hDistanceAboveLimit = 0D; // TODO: maybe relate buffer use to this + sprinting ?
hDistanceAboveLimit = 0D;
tags.add("bunnyhop"); // TODO: Which here...
}
}
Expand All @@ -849,30 +851,24 @@ private double[] hDistAfterFailure(final Player player, final PlayerLocation fro
if (data.sfLastHDist != Double.MAX_VALUE){
// 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){
// Increase buffer by the needed amount.
final double amount = hDistance - hAllowedDistance;
// TODO: Might use min(hAllowedDistance and some maximal thing like sprinting speed?)
data.sfHorizontalBuffer = Math.min(hBufMax, data.sfHorizontalBuffer) + amount; // Cheat !
// TODO: Confine further (max. amount)?
// Allow the move.
hDistanceAboveLimit = 0.0;
tags.add("bunnyfly");
}
}
}
}

// Horizontal buffer.
if (hDistanceAboveLimit > 0.0) {
if (hDistanceAboveLimit > 0.0 && data.sfHorizontalBuffer > 0.0) {
// Handle buffer only if moving too far.
if (data.sfHorizontalBuffer > 0.0) {
// Consume buffer.
tags.add("hbufuse");
final double amount = Math.min(data.sfHorizontalBuffer, hDistanceAboveLimit);
hDistanceAboveLimit -= amount;
// Ensure we never end up below zero.
data.sfHorizontalBuffer = Math.max(0.0, data.sfHorizontalBuffer - amount);
}
// else: No consumption.
} else if (data.sfHorizontalBuffer < hBufMax && hDistance > 0.0) {
hBufRegain(hDistance, hDistanceAboveLimit, data);
// Consume buffer.
tags.add("hbufuse");
final double amount = Math.min(data.sfHorizontalBuffer, hDistanceAboveLimit);
hDistanceAboveLimit -= amount;
// Ensure we never end up below zero.
data.sfHorizontalBuffer = Math.max(0.0, data.sfHorizontalBuffer - amount);
}

// Add the hspeed tag on violation.
Expand Down

0 comments on commit d31fe6b

Please sign in to comment.