From: TimePath Date: Mon, 18 Sep 2017 12:00:36 +0000 (+1000) Subject: Mutator: Stale-move negation X-Git-Tag: xonotic-v0.8.5~2428^2~2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6aa2f1b51ba27c7c675219799eaab5108627750f;p=xonotic%2Fxonotic-data.pk3dir.git Mutator: Stale-move negation The more often a weapon is used, the less effective it becomes --- 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