From ec3e4d2d8483e44f06082ab5acadc54e001054bc Mon Sep 17 00:00:00 2001 From: rtldg <55846624+rtldg@users.noreply.github.com> Date: Fri, 23 Jul 2021 09:15:23 +0000 Subject: [PATCH] add angle diff to Shavit_GetReplayButtons --- addons/sourcemod/scripting/include/shavit.inc | 10 +++++- addons/sourcemod/scripting/shavit-hud.sp | 34 ++++++++++++++----- addons/sourcemod/scripting/shavit-replay.sp | 4 +++ 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/addons/sourcemod/scripting/include/shavit.inc b/addons/sourcemod/scripting/include/shavit.inc index e72a9bd8..4e209145 100644 --- a/addons/sourcemod/scripting/include/shavit.inc +++ b/addons/sourcemod/scripting/include/shavit.inc @@ -534,6 +534,12 @@ stock int GetSpectatorTarget(int client, int fallback = -1) return target; } +stock float GetAngleDiff(float current, float previous) +{ + float diff = current - previous; + return diff - 360.0 * RoundToFloor((diff + 180.0) / 360.0); +} + /** * Called before shavit-core processes the client's usercmd. * Before this is called, safety checks (fake/dead clients) happen. @@ -1558,9 +1564,11 @@ native int Shavit_GetReplayStarter(int ent); * Really, this is only useful for things like replay props. * * @param ent Replay entity. + * @param anglediff The angle difference between the previous and current y angles. + * * @return buttons */ -native int Shavit_GetReplayButtons(int ent); +native int Shavit_GetReplayButtons(int ent, float& anglediff); /** * Retrieves a replay's frame count. diff --git a/addons/sourcemod/scripting/shavit-hud.sp b/addons/sourcemod/scripting/shavit-hud.sp index db8c838c..77abfaaa 100644 --- a/addons/sourcemod/scripting/shavit-hud.sp +++ b/addons/sourcemod/scripting/shavit-hud.sp @@ -392,9 +392,7 @@ void MakeAngleDiff(int client, float newAngle) { gF_PreviousAngle[client] = gF_Angle[client]; gF_Angle[client] = newAngle; - - float fAngleDiff = newAngle - gF_PreviousAngle[client]; - gF_AngleDiff[client] = fAngleDiff - 360.0 * RoundToFloor((fAngleDiff + 180.0) / 360.0); + gF_AngleDiff[client] = GetAngleDiff(newAngle, gF_PreviousAngle[client]); } public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float vel[3], float angles[3], TimerStatus status, int track, int style) @@ -1590,7 +1588,19 @@ void UpdateKeyOverlay(int client, Panel panel, bool &draw) return; } - int buttons = IsValidClient(target) ? gI_Buttons[target] : Shavit_GetReplayButtons(target); + float fAngleDiff; + int buttons; + + if (IsValidClient(target)) + { + fAngleDiff = gF_AngleDiff[target]; + buttons = gI_Buttons[target]; + } + else + { + buttons = Shavit_GetReplayButtons(target, fAngleDiff); + } + int style = (gB_Replay && Shavit_IsReplayEntity(target))? Shavit_GetReplayBotStyle(target):Shavit_GetBhopStyle(target); if(!(0 <= style < gI_Styles)) @@ -1607,8 +1617,6 @@ void UpdateKeyOverlay(int client, Panel panel, bool &draw) FormatEx(sPanelLine, 64, " %d%s%d\n", gI_ScrollCount[target], (gI_ScrollCount[target] > 9)? " ":" ", gI_LastScrollCount[target]); } - float fAngleDiff = IsValidClient(target) ? gF_AngleDiff[target] : 0.0; - Format(sPanelLine, 128, "%s[%s] [%s]\n%s %s %s\n%s  %s  %s\n %s  %s", sPanelLine, (buttons & IN_JUMP) > 0? "J":"ー", (buttons & IN_DUCK) > 0? "C":"ー", (fAngleDiff > 0) ? "←":" ", (buttons & IN_FORWARD) > 0 ? "W":"ー", (fAngleDiff < 0) ? "→":"", @@ -1656,8 +1664,18 @@ void UpdateCenterKeys(int client) return; } - int buttons = IsValidClient(target) ? gI_Buttons[target] : Shavit_GetReplayButtons(target); - float fAngleDiff = IsValidClient(target) ? gF_AngleDiff[target] : 0.0; + float fAngleDiff; + int buttons; + + if (IsValidClient(target)) + { + fAngleDiff = gF_AngleDiff[target]; + buttons = gI_Buttons[target]; + } + else + { + buttons = Shavit_GetReplayButtons(target, fAngleDiff); + } char sCenterText[80]; FormatEx(sCenterText, sizeof(sCenterText), " %s  %s\n%s  %s  %s\n%s  %s  %s\n %s  %s", diff --git a/addons/sourcemod/scripting/shavit-replay.sp b/addons/sourcemod/scripting/shavit-replay.sp index 899c8a89..56def3d0 100644 --- a/addons/sourcemod/scripting/shavit-replay.sp +++ b/addons/sourcemod/scripting/shavit-replay.sp @@ -1264,7 +1264,11 @@ public int Native_GetReplayButtons(Handle handler, int numParams) } frame_t aFrame; + gA_BotInfo[bot].aCache.aFrames.GetArray(gA_BotInfo[bot].iTick ? gA_BotInfo[bot].iTick-1 : 0, aFrame, 6); + float prevAngle = aFrame.ang[1]; gA_BotInfo[bot].aCache.aFrames.GetArray(gA_BotInfo[bot].iTick, aFrame, 6); + + SetNativeCellRef(2, GetAngleDiff(aFrame.ang[1], prevAngle)); return aFrame.buttons; }