Skip to content

Commit ad9127a

Browse files
authored
Merge pull request cortex-command-community#229 from Architector4/patch-5
AHuman - rewrite EstimateJumpHeight
2 parents 066841d + 2f2139b commit ad9127a

File tree

1 file changed

+47
-13
lines changed

1 file changed

+47
-13
lines changed

Source/Entities/AHuman.cpp

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -967,27 +967,61 @@ float AHuman::EstimateJumpHeight() const {
967967
return 0.0F;
968968
}
969969

970+
// Estimate by "simulating" the character velocity frame by frame as the jetpack is used.
971+
// In pixels per second. Positive value means moving upward.
972+
//
973+
// Start with zero, for now.
974+
float currentYVelocity = 0.0F;
975+
976+
// Upward acceleration per frame.
977+
float yGravity = -(g_SceneMan.GetGlobalAcc().GetY() * g_TimerMan.GetDeltaTimeSecs());
978+
970979
float totalMass = GetMass();
971-
float fuelTime = m_pJetpack->GetJetTimeTotal();
972-
float fuelUseMultiplier = m_pJetpack->GetThrottleFactor();
973980
float impulseBurst = m_pJetpack->EstimateImpulse(true) / totalMass;
974981
float impulseThrust = m_pJetpack->EstimateImpulse(false) / totalMass;
982+
float fuelTime = m_pJetpack->GetJetTimeTotal();
983+
float fuelUseMultiplierThrust = m_pJetpack->GetThrottleFactor();
984+
float fuelUseMultiplierBurst = fuelUseMultiplierThrust * impulseBurst / impulseThrust;
985+
986+
bool hasBursted = false;
987+
988+
float totalHeight = 0.0F;
989+
990+
// Simulate up until we start falling.
991+
while (true) {
992+
// Account for the forces upon us.
993+
if (!hasBursted && fuelTime > 0.0F) {
994+
currentYVelocity += impulseBurst;
995+
fuelTime -= g_TimerMan.GetDeltaTimeMS() * fuelUseMultiplierBurst;
996+
hasBursted = true;
997+
}
975998

976-
Vector globalAcc = g_SceneMan.GetGlobalAcc() * g_TimerMan.GetDeltaTimeSecs();
977-
Vector currentVelocity = Vector(0.0F, -impulseBurst);
978-
float totalHeight = currentVelocity.GetY() * g_TimerMan.GetDeltaTimeSecs() * c_PPM;
979-
do {
980-
currentVelocity += globalAcc;
981-
totalHeight += currentVelocity.GetY() * g_TimerMan.GetDeltaTimeSecs() * c_PPM;
982999
if (fuelTime > 0.0F) {
983-
currentVelocity.m_Y -= impulseThrust;
984-
fuelTime -= g_TimerMan.GetDeltaTimeMS() * fuelUseMultiplier;
1000+
currentYVelocity += impulseThrust;
1001+
fuelTime -= g_TimerMan.GetDeltaTimeMS() * fuelUseMultiplierThrust;
9851002
}
986-
} while (currentVelocity.GetY() < 0.0F);
9871003

988-
float finalCalculatedHeight = totalHeight * -1.0F * c_MPP;
1004+
if (currentYVelocity + yGravity >= currentYVelocity) {
1005+
// Velocity is too big or gravity is too small. Either way, this will loop forever now.
1006+
// Just assume that we can reach the stars.
1007+
totalHeight = g_SceneMan.GetSceneHeight() * c_MPP;
1008+
break;
1009+
}
1010+
1011+
currentYVelocity += yGravity;
1012+
1013+
if (currentYVelocity > 0.0F) {
1014+
// If we're still flying up, that means more height.
1015+
totalHeight += currentYVelocity * g_TimerMan.GetDeltaTimeSecs() * c_PPM;
1016+
} else {
1017+
// If we're not, that means we're done simulating.
1018+
break;
1019+
}
1020+
}
1021+
9891022
float finalHeightMultipler = 0.6f; // Make us think we can do less because AI path following is shit
990-
return finalCalculatedHeight * finalHeightMultipler;
1023+
1024+
return totalHeight * c_MPP * finalHeightMultipler;
9911025
}
9921026

9931027
bool AHuman::EquipShield() {

0 commit comments

Comments
 (0)