From 131662840ac7cad02ff400422171f08841d8db9b Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Fri, 16 Oct 2020 18:33:38 +0200 Subject: [PATCH] code cleanup of strafe% feature --- qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc | 6 ++--- qcsrc/server/strafe.qc | 27 +++++++------------ qcsrc/server/strafe.qh | 6 ++++- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc index 20f834017..d19686ff0 100644 --- a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc +++ b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc @@ -141,7 +141,7 @@ MUTATOR_HOOKFUNCTION(cts, PlayerPhysics) CS(player).movement_y = -M_SQRT1_2 * wishspeed; } } - calculate_strafe_efficiency(player, CS(player).movement); + player.strafe_efficiency_average += calculate_strafe_efficiency(player, CS(player).movement); } MUTATOR_HOOKFUNCTION(cts, reset_map_global) @@ -155,7 +155,7 @@ MUTATOR_HOOKFUNCTION(cts, reset_map_global) FOREACH_CLIENT(true, { it.strafe_efficiency_best = -2; - PlayerScore_Set(it, SP_CTS_STRAFE, it.strafe_efficiency_best * 10000); + PlayerScore_Set(it, SP_CTS_STRAFE, -20000); if(it.race_place) { @@ -206,7 +206,7 @@ MUTATOR_HOOKFUNCTION(cts, ClientConnect) player.strafe_efficiency_average = player.strafe_efficiency_tics = 0; player.strafe_efficiency_best = -2; - PlayerScore_Set(player, SP_CTS_STRAFE, player.strafe_efficiency_best * 10000); + PlayerScore_Set(player, SP_CTS_STRAFE, -20000); } } diff --git a/qcsrc/server/strafe.qc b/qcsrc/server/strafe.qc index bd68105e0..483bb65c8 100644 --- a/qcsrc/server/strafe.qc +++ b/qcsrc/server/strafe.qc @@ -6,14 +6,8 @@ .float race_checkpoint; -.float strafe_efficiency_average; -.float strafe_efficiency_tics; -.float strafe_efficiency_best; - -void calculate_strafe_efficiency(entity strafeplayer, vector movement) +float calculate_strafe_efficiency(entity strafeplayer, vector movement) { - float efficiency = 0; - if(strafeplayer) { // physics @@ -30,9 +24,7 @@ void calculate_strafe_efficiency(entity strafeplayer, vector movement) int direction; int keys_fwd; float wishangle = 0; - float moveangle; bool fwd = true; - float bestangle; // determine whether the player is pressing forwards or backwards keys if(movement.x > 0) @@ -152,13 +144,12 @@ void calculate_strafe_efficiency(entity strafeplayer, vector movement) wishangle = -wishangle; } - moveangle = angle + wishangle; - - // best angle to strafe at - bestangle = (speed > maxspeed ? acos(maxspeed / speed) : 0) * RAD2DEG; - if(speed > 0 && !swimming && strafeplayer.race_checkpoint > 0) // only calculate a new average if all conditions are met { + float efficiency = 0; + float moveangle = angle + wishangle; + float bestangle = (speed > maxspeed ? acos(maxspeed / speed) : 0) * RAD2DEG; // best angle to strafe at + ++strafeplayer.strafe_efficiency_tics; if(fabs(vlen(vec2(movement))) > 0) { @@ -169,18 +160,18 @@ void calculate_strafe_efficiency(entity strafeplayer, vector movement) } else { - if((moveangle) >= bestangle) + if(moveangle >= bestangle) { efficiency = 1 - (moveangle - bestangle) / (90 - bestangle); } - else if((moveangle) <= -bestangle) + else if(moveangle <= -bestangle) { efficiency = 1 - (moveangle + bestangle) / (-90 + bestangle); } } } + return efficiency; } - - strafeplayer.strafe_efficiency_average += efficiency; } + return 0; } diff --git a/qcsrc/server/strafe.qh b/qcsrc/server/strafe.qh index 51ab72c99..bc6ae74f3 100644 --- a/qcsrc/server/strafe.qh +++ b/qcsrc/server/strafe.qh @@ -1,3 +1,7 @@ #pragma once -void calculate_strafe_efficiency(entity, vector); +.float strafe_efficiency_average; +.float strafe_efficiency_tics; +.float strafe_efficiency_best; + +float calculate_strafe_efficiency(entity, vector); -- 2.39.2