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

@ -161,6 +161,7 @@ void HacksComp_Init(struct HacksComp* hacks) {
hacks->CanSeeAllNames = true; hacks->CanSeeAllNames = true;
hacks->CanDoubleJump = true; hacks->CanDoubleJump = true;
hacks->BaseHorSpeed = 1.0f; hacks->BaseHorSpeed = 1.0f;
hacks->MaxHorSpeed = 1.0f;
hacks->MaxJumps = 1; hacks->MaxJumps = 1;
hacks->NoclipSlide = true; hacks->NoclipSlide = true;
hacks->CanBePushed = true; hacks->CanBePushed = true;
@ -237,6 +238,7 @@ void HacksComp_RecheckFlags(struct HacksComp* hacks) {
if (hacks->IsOp) HacksComp_ParseAllFlag(hacks, "+ophax", "-ophax"); if (hacks->IsOp) HacksComp_ParseAllFlag(hacks, "+ophax", "-ophax");
hacks->BaseHorSpeed = HacksComp_ParseFlagFloat("horspeed=", hacks); hacks->BaseHorSpeed = HacksComp_ParseFlagFloat("horspeed=", hacks);
hacks->MaxHorSpeed = HacksComp_ParseFlagFloat("maxspeed=", hacks);
hacks->MaxJumps = HacksComp_ParseFlagInt("jumps=", hacks); hacks->MaxJumps = HacksComp_ParseFlagInt("jumps=", hacks);
HacksComp_Update(hacks); HacksComp_Update(hacks);
} }
@ -270,6 +272,15 @@ void HacksComp_SetNoclip(struct HacksComp* hacks, cc_bool noclip) {
Event_RaiseVoid(&UserEvents.HacksStateChanged); 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-------------------------------------------------* *--------------------------------------------------InterpolationComponent-------------------------------------------------*
@ -1072,11 +1083,10 @@ static float PhysicsComp_LowestModifier(struct PhysicsComp* comp, struct AABB* b
return modifier; return modifier;
} }
static float PhysicsComp_GetSpeed(struct HacksComp* hacks, float speedMul) { static float PhysicsComp_GetSpeed(struct HacksComp* hacks, float speedMul, cc_bool canSpeed) {
float factor = hacks->Floating ? speedMul : 1.0f, speed = factor; float factor = hacks->Floating ? speedMul : 1.0f;
if (hacks->Speeding && hacks->CanSpeed) speed += factor * hacks->SpeedMultiplier; float speed = factor * (1 + HacksComp_CalcSpeedFactor(hacks, canSpeed));
if (hacks->HalfSpeeding && hacks->CanSpeed) speed += factor * hacks->SpeedMultiplier / 2; return hacks->CanSpeed ? speed : min(speed, hacks->MaxHorSpeed);
return hacks->CanSpeed ? speed : min(speed, 1.0f);
} }
static float PhysicsComp_GetBaseSpeed(struct PhysicsComp* comp) { 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; if (hacks->Noclip) entity->OnGround = false;
baseSpeed = PhysicsComp_GetBaseSpeed(comp); baseSpeed = PhysicsComp_GetBaseSpeed(comp);
verSpeed = baseSpeed * (PhysicsComp_GetSpeed(hacks, 8.0f) / 5.0f); verSpeed = baseSpeed * (PhysicsComp_GetSpeed(hacks, 8.0f, hacks->CanSpeed) / 5.0f);
horSpeed = baseSpeed * PhysicsComp_GetSpeed(hacks, 8.0f / 5.0f) * hacks->BaseHorSpeed; 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 */ /* 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 */ /* 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 */ /* Entity component that performs management of hack states */
struct HacksComp { struct HacksComp {
cc_bool IsOp; 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 */ /* Speed player move at, relative to normal speed, when the 'speeding' key binding is held down */
float SpeedMultiplier; float SpeedMultiplier;
/* Whether blocks that the player places that intersect themselves, should cause the player to /* Whether blocks that the player places that intersect themselves, should cause the player to
@ -59,7 +60,7 @@ struct HacksComp {
cc_bool WOMStyleHacks; cc_bool WOMStyleHacks;
cc_bool Noclip, Flying, FlyingUp, FlyingDown, Speeding, HalfSpeeding; cc_bool Noclip, Flying, FlyingUp, FlyingDown, Speeding, HalfSpeeding;
cc_bool Floating; /* true if NoClip or Flying */ float MaxHorSpeed;
cc_string HacksFlags; cc_string HacksFlags;
char __HacksFlagsBuffer[STRING_SIZE * 2]; char __HacksFlagsBuffer[STRING_SIZE * 2];
}; };
@ -74,6 +75,7 @@ void HacksComp_RecheckFlags(struct HacksComp* hacks);
void HacksComp_Update(struct HacksComp* hacks); void HacksComp_Update(struct HacksComp* hacks);
void HacksComp_SetFlying(struct HacksComp* hacks, cc_bool flying); void HacksComp_SetFlying(struct HacksComp* hacks, cc_bool flying);
void HacksComp_SetNoclip(struct HacksComp* hacks, cc_bool noclip); void HacksComp_SetNoclip(struct HacksComp* hacks, cc_bool noclip);
float HacksComp_CalcSpeedFactor(struct HacksComp* hacks, cc_bool canSpeed);
/* Represents a position and orientation state */ /* Represents a position and orientation state */
struct InterpState { Vec3 Pos; float Pitch, Yaw, RotX, RotZ; }; 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); 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) { static cc_bool HUDScreen_HasHacksChanged(struct HUDScreen* s) {
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks; 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; return speed != s->lastSpeed || Camera.Fov != s->lastFov || s->hacksChanged;
} }
static void HUDScreen_UpdateHackState(struct HUDScreen* s) { static void HUDScreen_UpdateHackState(struct HUDScreen* s) {
cc_string status; char statusBuffer[STRING_SIZE * 2]; cc_string status; char statusBuffer[STRING_SIZE * 2];
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks; 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->lastSpeed = speed; s->lastFov = Camera.Fov;
s->hacksChanged = false; s->hacksChanged = false;