]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
New mutator: Killers Spawn Faster.
authorRudolf Polzer <divVerent@gmail.com>
Tue, 13 Jun 2023 13:10:59 +0000 (09:10 -0400)
committerRudolf Polzer <divVerent@gmail.com>
Tue, 13 Jun 2023 13:10:59 +0000 (09:10 -0400)
Should work in most game types, and increases one's respawn delay on every
death, while decreasing it when fragging someone.

qcsrc/common/mutators/mutator/_mod.inc
qcsrc/common/mutators/mutator/_mod.qh
qcsrc/common/mutators/mutator/killers_spawn_faster/_mod.inc [new file with mode: 0644]
qcsrc/common/mutators/mutator/killers_spawn_faster/_mod.qh [new file with mode: 0644]
qcsrc/common/mutators/mutator/killers_spawn_faster/sv_respawntime.qc [new file with mode: 0644]
qcsrc/common/mutators/mutator/killers_spawn_faster/sv_respawntime.qh [new file with mode: 0644]
qcsrc/server/client.qc
qcsrc/server/mutators/events.qh
qcsrc/server/scores.qc

index c463c429f0c0eec1c0c1ffa89487a79158a9ae1a..34f7fe79a2684bcadf64977e0d22a76a58274215 100644 (file)
@@ -16,6 +16,7 @@
 #include <common/mutators/mutator/invincibleproj/_mod.inc>
 #include <common/mutators/mutator/itemstime/_mod.inc>
 #include <common/mutators/mutator/kick_teamkiller/_mod.inc>
+#include <common/mutators/mutator/killers_spawn_faster/_mod.inc>
 #include <common/mutators/mutator/melee_only/_mod.inc>
 #include <common/mutators/mutator/midair/_mod.inc>
 #include <common/mutators/mutator/multijump/_mod.inc>
index 3b4eba7cb65a6a4fa93d97e515d6bb19a7f7b347..23ee03dd7291d5569b2e8d3a59594e71a6f4c3b6 100644 (file)
@@ -16,6 +16,7 @@
 #include <common/mutators/mutator/invincibleproj/_mod.qh>
 #include <common/mutators/mutator/itemstime/_mod.qh>
 #include <common/mutators/mutator/kick_teamkiller/_mod.qh>
+#include <common/mutators/mutator/killers_spawn_faster/_mod.qh>
 #include <common/mutators/mutator/melee_only/_mod.qh>
 #include <common/mutators/mutator/midair/_mod.qh>
 #include <common/mutators/mutator/multijump/_mod.qh>
diff --git a/qcsrc/common/mutators/mutator/killers_spawn_faster/_mod.inc b/qcsrc/common/mutators/mutator/killers_spawn_faster/_mod.inc
new file mode 100644 (file)
index 0000000..3eb6608
--- /dev/null
@@ -0,0 +1,4 @@
+// generated file; do not modify
+#ifdef SVQC
+    #include <common/mutators/mutator/killers_spawn_faster/sv_respawntime.qc>
+#endif
diff --git a/qcsrc/common/mutators/mutator/killers_spawn_faster/_mod.qh b/qcsrc/common/mutators/mutator/killers_spawn_faster/_mod.qh
new file mode 100644 (file)
index 0000000..6105ab2
--- /dev/null
@@ -0,0 +1,4 @@
+// generated file; do not modify
+#ifdef SVQC
+    #include <common/mutators/mutator/killers_spawn_faster/sv_respawntime.qh>
+#endif
diff --git a/qcsrc/common/mutators/mutator/killers_spawn_faster/sv_respawntime.qc b/qcsrc/common/mutators/mutator/killers_spawn_faster/sv_respawntime.qc
new file mode 100644 (file)
index 0000000..6ca25cd
--- /dev/null
@@ -0,0 +1,68 @@
+#include "sv_respawntime.qh"
+
+AUTOCVAR(g_killers_spawn_faster, bool, false, "Killers spawn faster: a mutator that penalizes dying, and rewards killing, by adjusting time to respawn");
+AUTOCVAR(g_killers_spawn_faster_frag_modifier, float, -0.2, "Killers spawn faster: respawntime factor change when fragging someone");
+AUTOCVAR(g_killers_spawn_faster_death_modifier, float, 0.5, "Killers spawn faster: respawntime factor change when dying");
+REGISTER_MUTATOR(mutator_killers_spawn_faster, autocvar_g_killers_spawn_faster);
+
+float killers_spawn_faster_adjust(float base, float adj) {
+       if (adj < 0) {
+               adj *= base;
+       }
+       return base + adj;
+}
+
+MUTATOR_HOOKFUNCTION(mutator_killers_spawn_faster, BuildMutatorsString) {
+       M_ARGV(0, string) = strcat(M_ARGV(0, string), ":KillersSpawnFaster");
+}
+
+MUTATOR_HOOKFUNCTION(mutator_killers_spawn_faster, BuildMutatorsPrettyString) {
+       M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Killers spawn faster");
+}
+
+MUTATOR_HOOKFUNCTION(mutator_killers_spawn_faster, ClientConnect) {
+       entity player = M_ARGV(0, entity);
+       player.killers_spawn_faster_factor = 1;
+       LOG_DEBUGF("Newly spawned player %i with respawntime factor %f", player, player.killers_spawn_faster_factor);
+}
+
+MUTATOR_HOOKFUNCTION(mutator_killers_spawn_faster, PlayerDies) {
+       // Note: this runs BEFORE CalculateRespawnTime.
+       entity attacker = M_ARGV(1, entity);
+       entity target = M_ARGV(2, entity);
+       if (target.classname == "body") {
+               error("WAT");
+               return false;
+       }
+       attacker.killers_spawn_faster_factor = killers_spawn_faster_adjust(
+               attacker.killers_spawn_faster_factor,
+               autocvar_g_killers_spawn_faster_frag_modifier);
+       LOG_DEBUGF("Killer player %i now has respawntime factor %f", attacker, attacker.killers_spawn_faster_factor);
+}
+
+MUTATOR_HOOKFUNCTION(mutator_killers_spawn_faster, CalculateRespawnTime) {
+       entity player = M_ARGV(0, entity);
+       float sdelay = M_ARGV(1, float);
+       sdelay *= player.killers_spawn_faster_factor;
+       LOG_DEBUGF("Adjusted player %i respawntime to %f", player, sdelay);
+       M_ARGV(1, float) = sdelay;
+}
+
+MUTATOR_HOOKFUNCTION(mutator_killers_spawn_faster, PlayerDied) {
+       // Note: this runs AFTER CalculateRespawnTime.
+       entity player = M_ARGV(0, entity);
+       if (player.classname == "body") {
+               error("WAT");
+               return false;
+       }
+       player.killers_spawn_faster_factor = killers_spawn_faster_adjust(
+               player.killers_spawn_faster_factor,
+               autocvar_g_killers_spawn_faster_death_modifier);
+       LOG_DEBUGF("Dying player %i now has respawntime factor %f", player, player.killers_spawn_faster_factor);
+}
+
+MUTATOR_HOOKFUNCTION(mutator_killers_spawn_faster, PlayerScore_Clear) {
+       entity player = M_ARGV(0, entity);
+       player.killers_spawn_faster_factor = 1;
+       LOG_DEBUGF("Restarted player %i now has respawntime factor %f", player, player.killers_spawn_faster_factor);
+}
diff --git a/qcsrc/common/mutators/mutator/killers_spawn_faster/sv_respawntime.qh b/qcsrc/common/mutators/mutator/killers_spawn_faster/sv_respawntime.qh
new file mode 100644 (file)
index 0000000..04dd4d8
--- /dev/null
@@ -0,0 +1,3 @@
+#pragma once
+
+.float killers_spawn_faster_factor;
index 0a8846d5d166ee6750dc83fd4e0da570c8d4c0ab..5c34e26b3194858901917e55b39bc2a9aab1f6bf 100644 (file)
@@ -1340,9 +1340,6 @@ void UpdateChatBubble(entity this)
 
 void calculate_player_respawn_time(entity this)
 {
-       if(MUTATOR_CALLHOOK(CalculateRespawnTime, this))
-               return;
-
        float gametype_setting_tmp;
        float sdelay_max = GAMETYPE_DEFAULTED_SETTING(respawn_delay_max);
        float sdelay_small = GAMETYPE_DEFAULTED_SETTING(respawn_delay_small);
@@ -1405,6 +1402,10 @@ void calculate_player_respawn_time(entity this)
        else  // NOTE: this case implies sdelay_large_count > sdelay_small_count.
                sdelay = sdelay_small + (sdelay_large - sdelay_small) * (pcount - sdelay_small_count) / (sdelay_large_count - sdelay_small_count);
 
+       if(MUTATOR_CALLHOOK(CalculateRespawnTime, this, sdelay))
+               return;
+       sdelay = M_ARGV(1, float);
+
        if(waves)
                this.respawn_time = ceil((time + sdelay) / waves) * waves;
        else
index ce9f958266efbfc203192a3fb07b01b65dc78680..f468dce548cb5976fb22b202c4029a07500203ac 100644 (file)
@@ -63,6 +63,12 @@ MUTATOR_HOOKABLE(reset_map_global, EV_reset_map_global);
     /**/
 MUTATOR_HOOKABLE(reset_map_players, EV_reset_map_players);
 
+/** called when entering play after observing, or switching teams */
+#define EV_PlayerScore_Clear(i, o) \
+    /** player */ i(entity, MUTATOR_ARGV_0_entity) \
+    /**/
+MUTATOR_HOOKABLE(PlayerScore_Clear, EV_PlayerScore_Clear);
+
 /** returns 1 if clearing player score shall not be allowed */
 #define EV_ForbidPlayerScore_Clear(i, o) \
     /**/
@@ -1206,7 +1212,9 @@ MUTATOR_HOOKABLE(HavocBot_Aim, EV_HavocBot_Aim);
 
 /** return true to skip respawn time calculations */
 #define EV_CalculateRespawnTime(i, o) \
-    /** player */ i(entity, MUTATOR_ARGV_0_entity) \
+    /** player */      i(entity, MUTATOR_ARGV_0_entity) \
+    /** spawn delay */ i(float, MUTATOR_ARGV_1_float) \
+    /** spawn delay */ o(float, MUTATOR_ARGV_1_float) \
     /**/
 MUTATOR_HOOKABLE(CalculateRespawnTime, EV_CalculateRespawnTime);
 
index 5e1c8d9db567b67fd8f3635803cd6dd4266fbd25..bdbeebffc6c048ba5984b7bd62404d8b9819d60d 100644 (file)
@@ -284,6 +284,8 @@ float PlayerScore_Clear(entity player)
 {
        entity sk;
 
+       MUTATOR_CALLHOOK(PlayerScore_Clear, player);
+
        if(teamscores_entities_count)
                return 0;