Add speed limit enforcement for minecarts
This commit is contained in:
parent
5231e4a7e4
commit
01a100dc97
@ -277,12 +277,9 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::millisecon
|
|||||||
if (GetSpeedZ() >= 0)
|
if (GetSpeedZ() >= 0)
|
||||||
{
|
{
|
||||||
// SpeedZ POSITIVE, going SOUTH
|
// SpeedZ POSITIVE, going SOUTH
|
||||||
if (GetSpeedZ() <= MAX_SPEED) // Speed limit
|
|
||||||
{
|
|
||||||
AddSpeedZ(0.5); // Speed up
|
AddSpeedZ(0.5); // Speed up
|
||||||
SetSpeedY(-GetSpeedZ()); // Downward movement is negative (0 minus positive numbers is negative)
|
SetSpeedY(-GetSpeedZ()); // Downward movement is negative (0 minus positive numbers is negative)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// SpeedZ NEGATIVE, going NORTH
|
// SpeedZ NEGATIVE, going NORTH
|
||||||
@ -303,14 +300,11 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::millisecon
|
|||||||
SetSpeedY(GetSpeedZ()); // Upward movement positive
|
SetSpeedY(GetSpeedZ()); // Upward movement positive
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (GetSpeedZ() >= MAX_SPEED_NEGATIVE) // Speed limit
|
|
||||||
{
|
{
|
||||||
// SpeedZ NEGATIVE, going NORTH
|
// SpeedZ NEGATIVE, going NORTH
|
||||||
AddSpeedZ(-0.5); // Speed up
|
AddSpeedZ(-0.5); // Speed up
|
||||||
SetSpeedY(GetSpeedZ()); // Downward movement negative
|
SetSpeedY(GetSpeedZ()); // Downward movement negative
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case E_META_RAIL_ASCEND_XM: // ASCEND EAST
|
case E_META_RAIL_ASCEND_XM: // ASCEND EAST
|
||||||
@ -319,13 +313,10 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::millisecon
|
|||||||
SetSpeedZ(NO_SPEED);
|
SetSpeedZ(NO_SPEED);
|
||||||
|
|
||||||
if (GetSpeedX() >= NO_SPEED)
|
if (GetSpeedX() >= NO_SPEED)
|
||||||
{
|
|
||||||
if (GetSpeedX() <= MAX_SPEED)
|
|
||||||
{
|
{
|
||||||
AddSpeedX(0.5);
|
AddSpeedX(0.5);
|
||||||
SetSpeedY(-GetSpeedX());
|
SetSpeedY(-GetSpeedX());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddSpeedX(1);
|
AddSpeedX(1);
|
||||||
@ -344,13 +335,10 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, std::chrono::millisecon
|
|||||||
SetSpeedY(GetSpeedX());
|
SetSpeedY(GetSpeedX());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (GetSpeedX() >= MAX_SPEED_NEGATIVE)
|
|
||||||
{
|
{
|
||||||
AddSpeedX(-0.5);
|
AddSpeedX(-0.5);
|
||||||
SetSpeedY(GetSpeedX());
|
SetSpeedY(GetSpeedX());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case E_META_RAIL_CURVED_ZM_XM: // Ends pointing NORTH and WEST
|
case E_META_RAIL_CURVED_ZM_XM: // Ends pointing NORTH and WEST
|
||||||
@ -483,13 +471,10 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
|
|||||||
SetSpeedZ(NO_SPEED);
|
SetSpeedZ(NO_SPEED);
|
||||||
|
|
||||||
if (GetSpeedX() >= NO_SPEED)
|
if (GetSpeedX() >= NO_SPEED)
|
||||||
{
|
|
||||||
if (GetSpeedX() <= MAX_SPEED)
|
|
||||||
{
|
{
|
||||||
AddSpeedX(AccelDecelSpeed);
|
AddSpeedX(AccelDecelSpeed);
|
||||||
SetSpeedY(-GetSpeedX());
|
SetSpeedY(-GetSpeedX());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddSpeedX(AccelDecelNegSpeed);
|
AddSpeedX(AccelDecelNegSpeed);
|
||||||
@ -508,13 +493,10 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
|
|||||||
SetSpeedY(GetSpeedX());
|
SetSpeedY(GetSpeedX());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (GetSpeedX() >= MAX_SPEED_NEGATIVE)
|
|
||||||
{
|
{
|
||||||
AddSpeedX(AccelDecelNegSpeed);
|
AddSpeedX(AccelDecelNegSpeed);
|
||||||
SetSpeedY(GetSpeedX());
|
SetSpeedY(GetSpeedX());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH
|
case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH
|
||||||
@ -523,13 +505,10 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
|
|||||||
SetSpeedX(NO_SPEED);
|
SetSpeedX(NO_SPEED);
|
||||||
|
|
||||||
if (GetSpeedZ() >= NO_SPEED)
|
if (GetSpeedZ() >= NO_SPEED)
|
||||||
{
|
|
||||||
if (GetSpeedZ() <= MAX_SPEED)
|
|
||||||
{
|
{
|
||||||
AddSpeedZ(AccelDecelSpeed);
|
AddSpeedZ(AccelDecelSpeed);
|
||||||
SetSpeedY(-GetSpeedZ());
|
SetSpeedY(-GetSpeedZ());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddSpeedZ(AccelDecelNegSpeed);
|
AddSpeedZ(AccelDecelNegSpeed);
|
||||||
@ -548,13 +527,10 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
|
|||||||
SetSpeedY(GetSpeedZ());
|
SetSpeedY(GetSpeedZ());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
if (GetSpeedZ() >= MAX_SPEED_NEGATIVE)
|
|
||||||
{
|
{
|
||||||
AddSpeedZ(AccelDecelNegSpeed);
|
AddSpeedZ(AccelDecelNegSpeed);
|
||||||
SetSpeedY(GetSpeedZ());
|
SetSpeedY(GetSpeedZ());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: ASSERT(!"Unhandled powered rail metadata!"); break;
|
default: ASSERT(!"Unhandled powered rail metadata!"); 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()
|
void cMinecart::Destroyed()
|
||||||
{
|
{
|
||||||
if (m_bIsOnDetectorRail)
|
if (m_bIsOnDetectorRail)
|
||||||
|
@ -51,6 +51,9 @@ protected:
|
|||||||
Vector3i m_DetectorRailPosition;
|
Vector3i m_DetectorRailPosition;
|
||||||
bool m_bIsOnDetectorRail;
|
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);
|
cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z);
|
||||||
|
|
||||||
/** Handles physics on normal rails
|
/** Handles physics on normal rails
|
||||||
|
Loading…
Reference in New Issue
Block a user