From 6aa2f1b51ba27c7c675219799eaab5108627750f Mon Sep 17 00:00:00 2001 From: TimePath Date: Mon, 18 Sep 2017 22:00:36 +1000 Subject: [PATCH] Mutator: Stale-move negation The more often a weapon is used, the less effective it becomes --- qcsrc/common/mutators/mutator/_mod.inc | 1 + qcsrc/common/mutators/mutator/_mod.qh | 1 + .../mutator/stale_move_negation/_mod.inc | 4 ++ .../mutator/stale_move_negation/_mod.qh | 4 ++ .../sv_stale_move_negation.qc | 49 +++++++++++++++++++ .../sv_stale_move_negation.qh | 1 + 6 files changed, 60 insertions(+) create mode 100644 qcsrc/common/mutators/mutator/stale_move_negation/_mod.inc create mode 100644 qcsrc/common/mutators/mutator/stale_move_negation/_mod.qh create mode 100644 qcsrc/common/mutators/mutator/stale_move_negation/sv_stale_move_negation.qc create mode 100644 qcsrc/common/mutators/mutator/stale_move_negation/sv_stale_move_negation.qh diff --git a/qcsrc/common/mutators/mutator/_mod.inc b/qcsrc/common/mutators/mutator/_mod.inc index eeb93ba5e..1ba168f07 100644 --- a/qcsrc/common/mutators/mutator/_mod.inc +++ b/qcsrc/common/mutators/mutator/_mod.inc @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/common/mutators/mutator/_mod.qh b/qcsrc/common/mutators/mutator/_mod.qh index 956c0d975..e7859d3cb 100644 --- a/qcsrc/common/mutators/mutator/_mod.qh +++ b/qcsrc/common/mutators/mutator/_mod.qh @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/common/mutators/mutator/stale_move_negation/_mod.inc b/qcsrc/common/mutators/mutator/stale_move_negation/_mod.inc new file mode 100644 index 000000000..0e940580c --- /dev/null +++ b/qcsrc/common/mutators/mutator/stale_move_negation/_mod.inc @@ -0,0 +1,4 @@ +// generated file; do not modify +#ifdef SVQC + #include +#endif diff --git a/qcsrc/common/mutators/mutator/stale_move_negation/_mod.qh b/qcsrc/common/mutators/mutator/stale_move_negation/_mod.qh new file mode 100644 index 000000000..a2c60b4d2 --- /dev/null +++ b/qcsrc/common/mutators/mutator/stale_move_negation/_mod.qh @@ -0,0 +1,4 @@ +// generated file; do not modify +#ifdef SVQC + #include +#endif diff --git a/qcsrc/common/mutators/mutator/stale_move_negation/sv_stale_move_negation.qc b/qcsrc/common/mutators/mutator/stale_move_negation/sv_stale_move_negation.qc new file mode 100644 index 000000000..7d5f829a0 --- /dev/null +++ b/qcsrc/common/mutators/mutator/stale_move_negation/sv_stale_move_negation.qc @@ -0,0 +1,49 @@ +#include "sv_stale_move_negation.qh" + +AUTOCVAR(g_smneg, bool, false, "Stale-move negation: penalize repeated use of the same weapon"); +AUTOCVAR(g_smneg_bonus, bool, true, "Stale-move negation: allow weapons to become stronger than their baseline"); +AUTOCVAR(g_smneg_bonus_asymptote, float, 4, "Stale-move negation: damage = infinity at this bonus level"); +AUTOCVAR(g_smneg_cooldown_factor, float, 1 / 4, "Stale-move negation: penalty cooldown factor"); +REGISTER_MUTATOR(mutator_smneg, autocvar_g_smneg); + +MUTATOR_HOOKFUNCTION(mutator_smneg, BuildMutatorsString) { + M_ARGV(0, string) = strcat(M_ARGV(0, string), ":StaleMoveNegation"); +} + +MUTATOR_HOOKFUNCTION(mutator_smneg, BuildMutatorsPrettyString) { + M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Stale-move negation"); +} + +.float x_smneg_weight[Weapons_MAX]; + +float smneg_multiplier(float weight) { + float a = autocvar_g_smneg_bonus_asymptote; + float x = max( + (!autocvar_g_smneg_bonus ? 0 : (-a + .1)), + weight / cvar("g_balance_health_start") + ); + float z = (M_PI / 5) * a; + float f = (x > 0) + ? (atan(z / x) / (M_PI / 2)) + : (tan(-(x / z)) + 1); + return f; +} + +MUTATOR_HOOKFUNCTION(mutator_smneg, Damage_Calculate) { + float deathtype = M_ARGV(3, float); + Weapon w = DEATH_WEAPONOF(deathtype); + if (w == WEP_Null) return; + + entity frag_attacker = M_ARGV(1, entity); + entity c = CS(frag_attacker); + float weight = c.x_smneg_weight[w.m_id]; + float f = smneg_multiplier(weight); + float frag_damage = M_ARGV(4, float) = f * M_ARGV(4, float); + M_ARGV(6, vector) = f * M_ARGV(6, vector); // force + + c.x_smneg_weight[w.m_id] = weight + frag_damage; + float restore = frag_damage * autocvar_g_smneg_cooldown_factor; + FOREACH(Weapons, it != WEP_Null && it != w, { + c.x_smneg_weight[it.m_id] -= restore; + }); +} diff --git a/qcsrc/common/mutators/mutator/stale_move_negation/sv_stale_move_negation.qh b/qcsrc/common/mutators/mutator/stale_move_negation/sv_stale_move_negation.qh new file mode 100644 index 000000000..6f70f09be --- /dev/null +++ b/qcsrc/common/mutators/mutator/stale_move_negation/sv_stale_move_negation.qh @@ -0,0 +1 @@ +#pragma once -- 2.39.2