Add maxspeed= to MOTD to allow specifying a maximum horizontal speed that overrides -speed per request (Thanks Venk)

This commit is contained in:
UnknownShadow200 2020-12-27 11:17:11 +11:00
parent 801e26b03c
commit 6b2766702b
3 changed files with 27 additions and 25 deletions

View File

@ -160,10 +160,11 @@ void HacksComp_Init(struct HacksComp* hacks) {
hacks->IsOp = true;
hacks->CanSeeAllNames = true;
hacks->CanDoubleJump = true;
hacks->BaseHorSpeed = 1.0f;
hacks->MaxJumps = 1;
hacks->NoclipSlide = true;
hacks->CanBePushed = true;
hacks->BaseHorSpeed = 1.0f;
hacks->MaxHorSpeed = 1.0f;
hacks->MaxJumps = 1;
hacks->NoclipSlide = true;
hacks->CanBePushed = true;
String_InitArray(hacks->HacksFlags, hacks->__HacksFlagsBuffer);
}
@ -237,6 +238,7 @@ void HacksComp_RecheckFlags(struct HacksComp* hacks) {
if (hacks->IsOp) HacksComp_ParseAllFlag(hacks, "+ophax", "-ophax");
hacks->BaseHorSpeed = HacksComp_ParseFlagFloat("horspeed=", hacks);
hacks->MaxHorSpeed = HacksComp_ParseFlagFloat("maxspeed=", hacks);
hacks->MaxJumps = HacksComp_ParseFlagInt("jumps=", hacks);
HacksComp_Update(hacks);
}
@ -270,6 +272,15 @@ void HacksComp_SetNoclip(struct HacksComp* hacks, cc_bool noclip) {
Event_RaiseVoid(&UserEvents.HacksStateChanged);
}
float HacksComp_CalcSpeedFactor(struct HacksComp* hacks, cc_bool canSpeed) {
float speed = 0;
if (!canSpeed) return 0;
if (hacks->HalfSpeeding) speed += hacks->SpeedMultiplier / 2;
if (hacks->Speeding) speed += hacks->SpeedMultiplier;
return speed;
}
/*########################################################################################################################*
*--------------------------------------------------InterpolationComponent-------------------------------------------------*
@ -1072,11 +1083,10 @@ static float PhysicsComp_LowestModifier(struct PhysicsComp* comp, struct AABB* b
return modifier;
}
static float PhysicsComp_GetSpeed(struct HacksComp* hacks, float speedMul) {
float factor = hacks->Floating ? speedMul : 1.0f, speed = factor;
if (hacks->Speeding && hacks->CanSpeed) speed += factor * hacks->SpeedMultiplier;
if (hacks->HalfSpeeding && hacks->CanSpeed) speed += factor * hacks->SpeedMultiplier / 2;
return hacks->CanSpeed ? speed : min(speed, 1.0f);
static float PhysicsComp_GetSpeed(struct HacksComp* hacks, float speedMul, cc_bool canSpeed) {
float factor = hacks->Floating ? speedMul : 1.0f;
float speed = factor * (1 + HacksComp_CalcSpeedFactor(hacks, canSpeed));
return hacks->CanSpeed ? speed : min(speed, hacks->MaxHorSpeed);
}
static float PhysicsComp_GetBaseSpeed(struct PhysicsComp* comp) {
@ -1105,8 +1115,8 @@ void PhysicsComp_PhysicsTick(struct PhysicsComp* comp, Vec3 vel) {
if (hacks->Noclip) entity->OnGround = false;
baseSpeed = PhysicsComp_GetBaseSpeed(comp);
verSpeed = baseSpeed * (PhysicsComp_GetSpeed(hacks, 8.0f) / 5.0f);
horSpeed = baseSpeed * PhysicsComp_GetSpeed(hacks, 8.0f / 5.0f) * hacks->BaseHorSpeed;
verSpeed = baseSpeed * (PhysicsComp_GetSpeed(hacks, 8.0f, hacks->CanSpeed) / 5.0f);
horSpeed = baseSpeed * PhysicsComp_GetSpeed(hacks, 8.0f / 5.0f, true) * hacks->BaseHorSpeed;
/* previously horSpeed used to be multiplied by factor of 0.02 in last case */
/* it's now multiplied by 0.1, so need to divide by 5 so user speed modifier comes out same */

View File

@ -36,6 +36,7 @@ void TiltComp_GetCurrent(struct TiltComp* anim, float t);
/* Entity component that performs management of hack states */
struct HacksComp {
cc_bool IsOp;
cc_bool Floating; /* true if NoClip or Flying */
/* Speed player move at, relative to normal speed, when the 'speeding' key binding is held down */
float SpeedMultiplier;
/* Whether blocks that the player places that intersect themselves, should cause the player to
@ -56,10 +57,10 @@ struct HacksComp {
/* Whether the player should slide after letting go of movement buttons in noclip */
cc_bool NoclipSlide;
/* Whether the player has allowed the usage of fast double jumping abilities */
cc_bool WOMStyleHacks;
cc_bool WOMStyleHacks;
cc_bool Noclip, Flying, FlyingUp, FlyingDown, Speeding, HalfSpeeding;
cc_bool Floating; /* true if NoClip or Flying */
float MaxHorSpeed;
cc_string HacksFlags;
char __HacksFlagsBuffer[STRING_SIZE * 2];
};
@ -74,6 +75,7 @@ void HacksComp_RecheckFlags(struct HacksComp* hacks);
void HacksComp_Update(struct HacksComp* hacks);
void HacksComp_SetFlying(struct HacksComp* hacks, cc_bool flying);
void HacksComp_SetNoclip(struct HacksComp* hacks, cc_bool noclip);
float HacksComp_CalcSpeedFactor(struct HacksComp* hacks, cc_bool canSpeed);
/* Represents a position and orientation state */
struct InterpState { Vec3 Pos; float Pitch, Yaw, RotX, RotZ; };

View File

@ -128,26 +128,16 @@ static void HUDScreen_DrawPosition(struct HUDScreen* s) {
Gfx_UpdateDynamicVb_IndexedTris(Models.Vb, vertices, count);
}
static float HUDScreen_CalcHacksSpeed(void) {
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks;
float speed = 0;
if (!hacks->CanSpeed) return 0;
if (hacks->HalfSpeeding) speed += hacks->SpeedMultiplier / 2;
if (hacks->Speeding) speed += hacks->SpeedMultiplier;
return speed;
}
static cc_bool HUDScreen_HasHacksChanged(struct HUDScreen* s) {
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks;
float speed = HUDScreen_CalcHacksSpeed();
float speed = HacksComp_CalcSpeedFactor(hacks, hacks->CanSpeed);
return speed != s->lastSpeed || Camera.Fov != s->lastFov || s->hacksChanged;
}
static void HUDScreen_UpdateHackState(struct HUDScreen* s) {
cc_string status; char statusBuffer[STRING_SIZE * 2];
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks;
float speed = HUDScreen_CalcHacksSpeed();
float speed = HacksComp_CalcSpeedFactor(hacks, hacks->CanSpeed);
s->lastSpeed = speed; s->lastFov = Camera.Fov;
s->hacksChanged = false;