diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2016-04-15 05:38:26 +0200 |
---|---|---|
committer | LogicParrot <LogicParrot@users.noreply.github.com> | 2016-04-15 05:38:26 +0200 |
commit | 25b6bac8651d10308e8e1b0209fdaf2ee83a7a0d (patch) | |
tree | b9577f0838501dc98b643f2818e514a189f37b8c /src/Entities | |
parent | Merge pull request #3140 from cuberite/revert-3137-issue3136 (diff) | |
parent | Add speed limit enforcement for minecarts (diff) | |
download | cuberite-25b6bac8651d10308e8e1b0209fdaf2ee83a7a0d.tar cuberite-25b6bac8651d10308e8e1b0209fdaf2ee83a7a0d.tar.gz cuberite-25b6bac8651d10308e8e1b0209fdaf2ee83a7a0d.tar.bz2 cuberite-25b6bac8651d10308e8e1b0209fdaf2ee83a7a0d.tar.lz cuberite-25b6bac8651d10308e8e1b0209fdaf2ee83a7a0d.tar.xz cuberite-25b6bac8651d10308e8e1b0209fdaf2ee83a7a0d.tar.zst cuberite-25b6bac8651d10308e8e1b0209fdaf2ee83a7a0d.zip |
Diffstat (limited to 'src/Entities')
-rw-r--r-- | src/Entities/Minecart.cpp | 92 | ||||
-rw-r--r-- | src/Entities/Minecart.h | 3 |
2 files changed, 54 insertions, 41 deletions
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index ea51c49c8..1b037e830 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -277,11 +277,8 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::millisecon if (GetSpeedZ() >= 0) { // SpeedZ POSITIVE, going SOUTH - if (GetSpeedZ() <= MAX_SPEED) // Speed limit - { - AddSpeedZ(0.5); // Speed up - SetSpeedY(-GetSpeedZ()); // Downward movement is negative (0 minus positive numbers is negative) - } + AddSpeedZ(0.5); // Speed up + SetSpeedY(-GetSpeedZ()); // Downward movement is negative (0 minus positive numbers is negative) } else { @@ -304,12 +301,9 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::millisecon } else { - if (GetSpeedZ() >= MAX_SPEED_NEGATIVE) // Speed limit - { - // SpeedZ NEGATIVE, going NORTH - AddSpeedZ(-0.5); // Speed up - SetSpeedY(GetSpeedZ()); // Downward movement negative - } + // SpeedZ NEGATIVE, going NORTH + AddSpeedZ(-0.5); // Speed up + SetSpeedY(GetSpeedZ()); // Downward movement negative } break; } @@ -320,11 +314,8 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::millisecon if (GetSpeedX() >= NO_SPEED) { - if (GetSpeedX() <= MAX_SPEED) - { - AddSpeedX(0.5); - SetSpeedY(-GetSpeedX()); - } + AddSpeedX(0.5); + SetSpeedY(-GetSpeedX()); } else { @@ -345,11 +336,8 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::millisecon } else { - if (GetSpeedX() >= MAX_SPEED_NEGATIVE) - { - AddSpeedX(-0.5); - SetSpeedY(GetSpeedX()); - } + AddSpeedX(-0.5); + SetSpeedY(GetSpeedX()); } break; } @@ -484,11 +472,8 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) if (GetSpeedX() >= NO_SPEED) { - if (GetSpeedX() <= MAX_SPEED) - { - AddSpeedX(AccelDecelSpeed); - SetSpeedY(-GetSpeedX()); - } + AddSpeedX(AccelDecelSpeed); + SetSpeedY(-GetSpeedX()); } else { @@ -509,11 +494,8 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) } else { - if (GetSpeedX() >= MAX_SPEED_NEGATIVE) - { - AddSpeedX(AccelDecelNegSpeed); - SetSpeedY(GetSpeedX()); - } + AddSpeedX(AccelDecelNegSpeed); + SetSpeedY(GetSpeedX()); } break; } @@ -524,11 +506,8 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) if (GetSpeedZ() >= NO_SPEED) { - if (GetSpeedZ() <= MAX_SPEED) - { - AddSpeedZ(AccelDecelSpeed); - SetSpeedY(-GetSpeedZ()); - } + AddSpeedZ(AccelDecelSpeed); + SetSpeedY(-GetSpeedZ()); } else { @@ -549,11 +528,8 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) } else { - if (GetSpeedZ() >= MAX_SPEED_NEGATIVE) - { - AddSpeedZ(AccelDecelNegSpeed); - SetSpeedY(GetSpeedZ()); - } + AddSpeedZ(AccelDecelNegSpeed); + SetSpeedY(GetSpeedZ()); } break; } @@ -1043,6 +1019,40 @@ bool cMinecart::DoTakeDamage(TakeDamageInfo & TDI) +void cMinecart::DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) +{ + if (a_SpeedX > MAX_SPEED) + { + a_SpeedX = MAX_SPEED; + } + else if (a_SpeedX < MAX_SPEED_NEGATIVE) + { + a_SpeedX = MAX_SPEED_NEGATIVE; + } + if (a_SpeedY > MAX_SPEED) + { + a_SpeedY = MAX_SPEED; + } + else if (a_SpeedY < MAX_SPEED_NEGATIVE) + { + a_SpeedY = MAX_SPEED_NEGATIVE; + } + if (a_SpeedZ > MAX_SPEED) + { + a_SpeedZ = MAX_SPEED; + } + else if (a_SpeedZ < MAX_SPEED_NEGATIVE) + { + a_SpeedZ = MAX_SPEED_NEGATIVE; + } + + super::DoSetSpeed(a_SpeedX, a_SpeedY, a_SpeedZ); +} + + + + + void cMinecart::Destroyed() { if (m_bIsOnDetectorRail) diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index c4b1d7f6d..0e5c99f80 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -51,6 +51,9 @@ protected: Vector3i m_DetectorRailPosition; bool m_bIsOnDetectorRail; + // Overwrite to enforce speed limit + virtual void DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ); + cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z); /** Handles physics on normal rails |