From 0d9855cfe719d3a776436bf304427654886a3d40 Mon Sep 17 00:00:00 2001 From: nashmuhandes Date: Wed, 13 Mar 2024 05:30:35 +0800 Subject: [PATCH] Expose `LandingSpeed` to ZScript. This controls the minimum Z velocity from falling down that's needed to "squat" the player's view (defaults to -8). --- src/playsim/actor.h | 3 +++ src/playsim/p_mobj.cpp | 11 +++++------ src/scripting/vmthunks_actors.cpp | 1 + wadsrc/static/zscript/actors/actor.zs | 3 +++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/playsim/actor.h b/src/playsim/actor.h index d985b0824..e14e7ea17 100644 --- a/src/playsim/actor.h +++ b/src/playsim/actor.h @@ -1369,6 +1369,9 @@ public: int SpawnTime; uint32_t SpawnOrder; + // landing speed from a jump with normal gravity (squats the player's view) + // (note: this is put into AActor instead of the PlayerPawn because non-players also use the value) + double LandingSpeed; // ThingIDs void SetTID (int newTID); diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index c3f4a82d5..ff98fb4da 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -391,7 +391,8 @@ void AActor::Serialize(FSerializer &arc) A("lightlevel", LightLevel) A("userlights", UserLights) A("WorldOffset", WorldOffset) - ("modelData", modelData); + ("modelData", modelData) + A("LandingSpeed", LandingSpeed); SerializeTerrain(arc, "floorterrain", floorterrain, &def->floorterrain); SerializeArgs(arc, "args", args, def->args, special); @@ -2584,11 +2585,9 @@ static void P_ZMovement (AActor *mo, double oldfloorz) mo->SetZ(mo->floorz); if (mo->Vel.Z < 0) { - const double minvel = -8; // landing speed from a jump with normal gravity - // Spawn splashes, etc. P_HitFloor (mo); - if (mo->DamageType == NAME_Ice && mo->Vel.Z < minvel) + if (mo->DamageType == NAME_Ice && mo->Vel.Z < mo->LandingSpeed) { mo->tics = 1; mo->Vel.Zero(); @@ -2601,11 +2600,11 @@ static void P_ZMovement (AActor *mo, double oldfloorz) } if (mo->player) { - if (mo->player->jumpTics < 0 || mo->Vel.Z < minvel) + if (mo->player->jumpTics < 0 || mo->Vel.Z < mo->LandingSpeed) { // delay any jumping for a short while mo->player->jumpTics = 7; } - if (mo->Vel.Z < minvel && !(mo->flags & MF_NOGRAVITY)) + if (mo->Vel.Z < mo->LandingSpeed && !(mo->flags & MF_NOGRAVITY)) { // Squat down. // Decrease viewheight for a moment after hitting the ground (hard), diff --git a/src/scripting/vmthunks_actors.cpp b/src/scripting/vmthunks_actors.cpp index 219d63e0d..e8c7acbb6 100644 --- a/src/scripting/vmthunks_actors.cpp +++ b/src/scripting/vmthunks_actors.cpp @@ -2126,6 +2126,7 @@ DEFINE_FIELD(AActor, ShadowAimFactor) DEFINE_FIELD(AActor, ShadowPenaltyFactor) DEFINE_FIELD(AActor, AutomapOffsets) DEFINE_FIELD(AActor, Path) +DEFINE_FIELD(AActor, LandingSpeed) DEFINE_FIELD_X(FCheckPosition, FCheckPosition, thing); DEFINE_FIELD_X(FCheckPosition, FCheckPosition, pos); diff --git a/wadsrc/static/zscript/actors/actor.zs b/wadsrc/static/zscript/actors/actor.zs index 9c694e38f..1c4ea98c8 100644 --- a/wadsrc/static/zscript/actors/actor.zs +++ b/wadsrc/static/zscript/actors/actor.zs @@ -262,6 +262,7 @@ class Actor : Thinker native native uint freezetics; native Vector2 AutomapOffsets; native Array Path; + native double LandingSpeed; meta String Obituary; // Player was killed by this actor meta String HitObituary; // Player was killed by this actor in melee @@ -367,6 +368,7 @@ class Actor : Thinker native property ShadowAimFactor: ShadowAimFactor; property ShadowPenaltyFactor: ShadowPenaltyFactor; property AutomapOffsets : AutomapOffsets; + property LandingSpeed: LandingSpeed; // need some definition work first //FRenderStyle RenderStyle; @@ -455,6 +457,7 @@ class Actor : Thinker native RenderHidden 0; RenderRequired 0; FriendlySeeBlocks 10; // 10 (blocks) * 128 (one map unit block) + LandingSpeed -8; // landing speed from a jump with normal gravity (squats the player's view) } // Functions