From b5a9085aed353f7c2948384301b4c423abe768d0 Mon Sep 17 00:00:00 2001
From: Mitchell Richters <mjr4077au@gmail.com>
Date: Sun, 26 Mar 2023 21:57:17 +1100
Subject: [PATCH] - Exhumed: Restore more accurate pitch adjustment for Ramses.

* Use `maphoriz(-11)` instead of some voodoo degree amount so it's clear when comparing sources.
* Don't stop interpolating while doing Ramses.
* Apply Ramses pitch amount to `nVertDestPan`, just like the original.
* Don't reset all angles when initialising Ramses, just set the yaw angle.
* Don't return player's view to center when doing Ramses, use the delta between `nDestVertPan` and the player's pitch, using same formula as original.
* Comment in how normal/non-ramses `nDestVertPan` setting should be 8x the sprite Z move delta, not 2x. I know it's not correct, but its been this way for a long time and we probably should CVAR it.
* When doing the player's death pitch, it's 40.156 degrees (horizon of 108), not 38 degrees (horizon of 100). This was a misread of mine way back when.
---
 source/core/mapinfo.h                 |  2 +-
 source/games/exhumed/src/gameloop.cpp |  2 +-
 source/games/exhumed/src/player.cpp   | 11 ++++++-----
 source/games/exhumed/src/ramses.cpp   |  4 +++-
 4 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/source/core/mapinfo.h b/source/core/mapinfo.h
index b8c2f7922..5b8f8d89d 100644
--- a/source/core/mapinfo.h
+++ b/source/core/mapinfo.h
@@ -149,7 +149,7 @@ struct MapRecord
 	// game specific stuff
 	int rr_startsound = 0;
 	int rr_mamaspawn = 15;
-	DAngle ex_ramses_horiz = DAngle::fromDeg(-4.912);
+	DAngle ex_ramses_horiz = maphoriz(-11);
 	int ex_ramses_cdtrack = -1; // this is not music, it is the actual dialogue!
 	FString ex_ramses_pup;
 	FString ex_ramses_text;
diff --git a/source/games/exhumed/src/gameloop.cpp b/source/games/exhumed/src/gameloop.cpp
index c74fb76fd..f7e522d77 100644
--- a/source/games/exhumed/src/gameloop.cpp
+++ b/source/games/exhumed/src/gameloop.cpp
@@ -74,7 +74,7 @@ void GameInterface::Render()
         DrawClock();
     }
 
-    const double interpfrac = bRecord || bPlayback || nFreeze != 0 || paused || cl_capfps || !cl_interpolate || EndLevel ? 1. : I_GetTimeFrac();
+    const double interpfrac = bRecord || bPlayback || paused || cl_capfps || !cl_interpolate || EndLevel ? 1. : I_GetTimeFrac();
     DrawView(interpfrac);
 
     if (nFreeze != 2) // Hide when Ramses is talking.
diff --git a/source/games/exhumed/src/player.cpp b/source/games/exhumed/src/player.cpp
index 4c0d2c4f6..a4f72e7a4 100644
--- a/source/games/exhumed/src/player.cpp
+++ b/source/games/exhumed/src/player.cpp
@@ -1420,7 +1420,8 @@ static void doPlayerRamses(Player* const pPlayer)
     if (nTotalPlayers <= 1)
     {
         const auto pPlayerActor = pPlayer->pActor;
-        pPlayerActor->spr.Angles = DRotator(nullAngle, (pSpiritSprite->spr.pos.XY() - pPlayerActor->spr.pos.XY()).Angle(), nullAngle);
+        pPlayerActor->spr.Angles.Yaw = (pSpiritSprite->spr.pos.XY() - pPlayerActor->spr.pos.XY()).Angle();
+        pPlayerActor->spr.Angles.Pitch = pPlayerActor->PrevAngles.Pitch;
         pPlayerActor->backupang();
         pPlayerActor->vel.Zero();
         pPlayer->vel.Zero();
@@ -1428,8 +1429,7 @@ static void doPlayerRamses(Player* const pPlayer)
         if (nFreeze < 1)
         {
             nFreeze = 1;
-            pPlayerActor->spr.Angles.Pitch = currentLevel->ex_ramses_horiz;
-            pPlayer->nDestVertPan = nullAngle;
+            pPlayer->nDestVertPan = currentLevel->ex_ramses_horiz;
             StopAllSounds();
             StopLocalSound();
             InitSpiritHead();
@@ -1708,6 +1708,7 @@ static bool doPlayerMovement(Player* const pPlayer)
             doPlayerMovingBlocks(pPlayer, nMove, spr_pos, spr_vel, spr_sect);
     }
 
+    // This should amplified 8x, not 2x, but it feels very heavy. Add a CVAR?
     pPlayer->nDestVertPan = maphoriz((pPlayerActor->spr.pos.Z - spr_pos.Z) * 2.);
     pPlayer->ototalvel = pPlayer->totalvel;
     pPlayer->totalvel = int((spr_pos.XY() - pPlayerActor->spr.pos.XY()).Length() * worldtoint);
@@ -2006,9 +2007,9 @@ static void doPlayerDeathPitch(Player* const pPlayer)
     {
         pPlayerActor->spr.Angles.Pitch -= maphoriz(pPlayer->dVertPan);
 
-        if (pPlayerActor->spr.Angles.Pitch.Degrees() <= -38)
+        if (pPlayerActor->spr.Angles.Pitch.Degrees() <= -40.156)
         {
-            pPlayerActor->spr.Angles.Pitch = DAngle::fromDeg(-38);
+            pPlayerActor->spr.Angles.Pitch = DAngle::fromDeg(-40.156);
         }
         else if (pPlayerActor->spr.Angles.Pitch.Sgn() >= 0 && !(pPlayerActor->sector()->Flag & kSectUnderwater))
         {
diff --git a/source/games/exhumed/src/ramses.cpp b/source/games/exhumed/src/ramses.cpp
index 845b61ed7..9d60e2b18 100644
--- a/source/games/exhumed/src/ramses.cpp
+++ b/source/games/exhumed/src/ramses.cpp
@@ -195,7 +195,9 @@ void DoSpiritHead()
     auto pSpiritSpr = pSpiritSprite;
     auto Worktile = GetWritablePixels(tileGetTextureID(kTileRamsesWorkTile));
 
-    PlayerList[0].input.actions |= SB_CENTERVIEW;
+    const auto pPlayer = &PlayerList[0];
+    const auto pPlayerActor = pPlayer->pActor;
+    pPlayerActor->spr.Angles.Pitch += deltaangle(pPlayerActor->spr.Angles.Pitch, pPlayer->nDestVertPan) * 0.25;
 
     switch (nHeadStage) 
     {