]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
fixed friendly fire giving score, added cvars for dmg&frags scoring method for how...
authordrjaska <drjaska83@gmail.com>
Fri, 3 Dec 2021 04:59:22 +0000 (06:59 +0200)
committerdrjaska <drjaska83@gmail.com>
Fri, 3 Dec 2021 04:59:22 +0000 (06:59 +0200)
gamemodes-server.cfg
qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qc
qcsrc/common/gamemodes/gamemode/mayhem/sv_mayhem.qh
qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qc
qcsrc/common/gamemodes/gamemode/tmayhem/sv_tmayhem.qh
qcsrc/server/world.qc

index 4ad27e58f221d4f3a5be2b5ab907dcee6afabc59..e00eae6ff53ed537b1cabdcb6ccfbc836608c470 100644 (file)
@@ -584,8 +584,12 @@ set g_duel_not_dm_maps 0 "when this is set, DM maps will NOT be listed in duel"
 set g_mayhem 0 "Mayhem: Compete for the most damage dealt and frags in this chaotic mayhem!"
 set g_tmayhem 0 "Team Mayhem: Compete with your team for the most damage dealt and frags in this chaotic mayhem!"
 
-set g_mayhem_scoringmethod 1 "1: 25% of the score is based on kills and 75% of it is based on damage. 2: 100% frags. 3: 100% damage."
-set g_tmayhem_scoringmethod 1 "1: 25% of the score is based on kills and 75% of it is based on damage. 2: 100% frags. 3: 100% damage."
+set g_mayhem_scoringmethod 1 "1: By default 25% of the score is based on kills and 75% of it is based on damage. 2: 100% frags. 3: 100% damage."
+set g_tmayhem_scoringmethod 1 "1: By default 25% of the score is based on kills and 75% of it is based on damage. 2: 100% frags. 3: 100% damage."
+set g_mayhem_scoringmethod_damage_weight 0.75 "for the first scoring method how much is damage equal to player's spawning health worth in score"
+set g_tmayhem_scoringmethod_damage_weight 0.75 "for the first scoring method how much is damage equal to player's spawning health worth in score"
+set g_mayhem_scoringmethod_frag_weight 0.25 "for the first scoring method how much is a frag worth in score"
+set g_tmayhem_scoringmethod_frag_weight 0.25 "for the first scoring method how much is a frag worth in score"
 
 set g_mayhem_fraglimit 30 "Team Mayhem basis for how many frags until the match ends, edit this over point_limit preferably"
 set g_tmayhem_fraglimit 50 "Team Mayhem basis for how many frags until the match ends, edit this over point_limit preferably"
index 4fb6f9ed0a009f9867fce01c47907fdbcd0eef10..1e2d801eda4fae22d5e9ce1737448f677a1f4fe5 100644 (file)
@@ -1,10 +1,16 @@
 #include "sv_mayhem.qh"
 
+float autocvar_g_mayhem_fraglimit;
+float autocvar_g_mayhem_visual_score_limit;
+float mayhempointmultiplier;
+
 bool autocvar_g_mayhem_regenerate;
 string autocvar_g_mayhem_weaponarena;
 bool autocvar_g_mayhem_powerups;
 bool autocvar_g_mayhem_selfdamage;
 int autocvar_g_mayhem_scoringmethod;
+float autocvar_g_mayhem_scoringmethod_damage_weight;
+float autocvar_g_mayhem_scoringmethod_frag_weight;
 bool autocvar_g_mayhem_pickup_items;
 bool autocvar_g_mayhem_pickup_items_remove_weapons_and_ammo;
 bool autocvar_g_mayhem_unlimited_ammo;
@@ -180,11 +186,11 @@ MUTATOR_HOOKFUNCTION(mayhem, PlayerDamage_SplitHealthArmor)
 
                        //non-friendly fire
                        if (frag_target != frag_attacker && IS_PLAYER(frag_attacker))
-                               GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * 0.75 * mayhempointmultiplier * (1/(start_health + start_armorvalue)));
+                               GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * autocvar_g_mayhem_scoringmethod_damage_weight * mayhempointmultiplier * (1/(start_health + start_armorvalue)));
                        
                        //friendly fire aka self damage
                        if (frag_target == frag_attacker && IS_PLAYER(frag_attacker))
-                               GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * 0.75 * mayhempointmultiplier * (1/(start_health + start_armorvalue)));
+                               GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_mayhem_scoringmethod_damage_weight * mayhempointmultiplier * (1/(start_health + start_armorvalue)));
                
                        //handle (environmental hazard) suiciding, check first if player has a registered attacker who most likely pushed them there to avoid punishing pushed players as pushers are already rewarded
                        //deathtypes:
@@ -199,7 +205,7 @@ MUTATOR_HOOKFUNCTION(mayhem, PlayerDamage_SplitHealthArmor)
                                frag_deathtype == DEATH_LAVA.m_id ||
                                frag_deathtype == DEATH_SLIME.m_id ||
                                frag_deathtype == DEATH_SWAMP.m_id))
-                                       GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * 0.75 * mayhempointmultiplier * (1/(start_health + start_armorvalue)));
+                                       GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_mayhem_scoringmethod_damage_weight * mayhempointmultiplier * (1/(start_health + start_armorvalue)));
                        return;
                }
        }
@@ -207,29 +213,60 @@ MUTATOR_HOOKFUNCTION(mayhem, PlayerDamage_SplitHealthArmor)
 
 MUTATOR_HOOKFUNCTION(mayhem, GiveFragsForKill, CBC_ORDER_FIRST)
 {
-       switch(autocvar_g_mayhem_scoringmethod)
-       {
-               //frags only
-               case 2:
-               {
-                                                                                                               //fix 999 score from 30 kills for example
-                       M_ARGV(2, float) = 1 * mayhempointmultiplier * 1.0001;
-                       return true;
-               }
-               
-               //damage only
-               case 3:
+       entity frag_attacker = M_ARGV(0, entity);
+       entity frag_target = M_ARGV(1, entity);
+       
+       if(frag_target == frag_attacker){
+               switch(autocvar_g_mayhem_scoringmethod)
                {
-                       M_ARGV(2, float) = 0;
-                       return true;
+                       //frags only
+                       case 2:
+                       {
+                                                                                                                       //fix 999 score from 30 kills for example
+                               M_ARGV(2, float) = -1 * mayhempointmultiplier * 1.0001;
+                               return true;
+                       }
+
+                       //damage only
+                       case 3:
+                       {
+                               M_ARGV(2, float) = 0;
+                               return true;
+                       }
+
+                       //combined damage and frags
+                       default:
+                       case 1:
+                       {
+                               M_ARGV(2, float) = -autocvar_g_mayhem_scoringmethod_frag_weight * mayhempointmultiplier * 1.0001;
+                               return true;
+                       }
                }
-               
-               //combined damage and frags
-               default:
-               case 1:
+       } else {
+               switch(autocvar_g_mayhem_scoringmethod)
                {
-                       M_ARGV(2, float) = 0.25 * mayhempointmultiplier * 1.0001;
-                       return true;
+                       //frags only
+                       case 2:
+                       {
+                                                                                                                       //fix 999 score from 30 kills for example
+                               M_ARGV(2, float) = 1 * mayhempointmultiplier * 1.0001;
+                               return true;
+                       }
+
+                       //damage only
+                       case 3:
+                       {
+                               M_ARGV(2, float) = 0;
+                               return true;
+                       }
+
+                       //combined damage and frags
+                       default:
+                       case 1:
+                       {
+                               M_ARGV(2, float) = autocvar_g_mayhem_scoringmethod_frag_weight * mayhempointmultiplier * 1.0001;
+                               return true;
+                       }
                }
        }
 }
index 9393b311f70d2df3b1576a3c430466b52f46765a..69b2878dfd26e8fb53d547c075b562e8117cef4f 100644 (file)
@@ -1,10 +1,7 @@
 #pragma once
 
 #include <common/mutators/base.qh>
-//someone who understands numbers better check if 2 following floats can be ints without imprecision, I'm scared of spaghettimonsters
-float autocvar_g_mayhem_fraglimit;
-float autocvar_g_mayhem_visual_score_limit;
-float mayhempointmultiplier = 1000/30;
+
 void mayhem_Initialize();
 
 REGISTER_MUTATOR(mayhem, false)
index 36db8b91c1cb2a73cf362005f4ff3ec5824e63c4..198bc587cc7a2c261d13df38cf6bc3093fb299b9 100644 (file)
@@ -1,5 +1,11 @@
 #include "sv_tmayhem.qh"
 
+float autocvar_g_tmayhem_fraglimit;
+float autocvar_g_tmayhem_visual_score_limit;
+float autocvar_g_tmayhem_score_leadlimit;
+bool autocvar_g_tmayhem_team_spawns;
+float tmayhempointmultiplier;
+
 // TODO? rename to teammayhem? requires checking alias and other string lengths
 int autocvar_g_tmayhem_teams;
 int autocvar_g_tmayhem_teams_override;
@@ -9,6 +15,8 @@ string autocvar_g_tmayhem_weaponarena;
 bool autocvar_g_tmayhem_powerups;
 bool autocvar_g_tmayhem_selfdamage;
 int autocvar_g_tmayhem_scoringmethod;
+float autocvar_g_tmayhem_scoringmethod_damage_weight;
+float autocvar_g_tmayhem_scoringmethod_frag_weight;
 bool autocvar_g_tmayhem_pickup_items;
 bool autocvar_g_tmayhem_pickup_items_remove_weapons_and_ammo;
 bool autocvar_g_tmayhem_unlimited_ammo;
@@ -189,11 +197,11 @@ MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor)
                        float excess = max(0, frag_damage - damage_take - damage_save);
 
                        //non-friendly fire
-                       if (frag_target != frag_attacker && IS_PLAYER(frag_attacker))
+                       if (IS_PLAYER(frag_attacker) && !SAME_TEAM(frag_target, frag_attacker))
                                GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * tmayhempointmultiplier * (1/(start_health + start_armorvalue)));
 
                        //friendly fire or self damage
-                       if (frag_target == frag_attacker && IS_PLAYER(frag_attacker))
+                       if (frag_target == frag_attacker && IS_PLAYER(frag_attacker) || SAME_TEAM(frag_target, frag_attacker))
                                GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * tmayhempointmultiplier * (1/(start_health + start_armorvalue)));
 
                        //handle (environmental hazard) suiciding, check first if player has a registered attacker who most likely pushed them there to avoid punishing pushed players as pushers are already rewarded
@@ -208,7 +216,7 @@ MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor)
                                frag_deathtype == DEATH_CAMP.m_id ||
                                frag_deathtype == DEATH_LAVA.m_id ||
                                frag_deathtype == DEATH_SLIME.m_id))
-                                       GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * 0.75 * tmayhempointmultiplier * (1/(start_health + start_armorvalue)));
+                                       GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * tmayhempointmultiplier * (1/(start_health + start_armorvalue)));
                        return;
                }
                
@@ -226,12 +234,12 @@ MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor)
                        float excess = max(0, frag_damage - damage_take - damage_save);
 
                        //non-friendly fire
-                       if (frag_target != frag_attacker && IS_PLAYER(frag_attacker))
-                               GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * 0.75 * tmayhempointmultiplier * (1/(start_health + start_armorvalue)));
+                       if (IS_PLAYER(frag_attacker) && !SAME_TEAM(frag_target, frag_attacker))
+                               GameRules_scoring_add_team(frag_attacker, SCORE, (frag_damage - excess) * autocvar_g_tmayhem_scoringmethod_damage_weight * tmayhempointmultiplier * (1/(start_health + start_armorvalue)));
                        
                        //friendly fire or self damage
-                       if (frag_target == frag_attacker && IS_PLAYER(frag_attacker))
-                               GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * 0.75 * tmayhempointmultiplier * (1/(start_health + start_armorvalue)));
+                       if (frag_target == frag_attacker && IS_PLAYER(frag_attacker) || SAME_TEAM(frag_target, frag_attacker))
+                               GameRules_scoring_add_team(frag_attacker, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_tmayhem_scoringmethod_damage_weight * tmayhempointmultiplier * (1/(start_health + start_armorvalue)));
                
                        //handle (environmental hazard) suiciding, check first if player has a registered attacker who most likely pushed them there to avoid punishing pushed players as pushers are already rewarded
                        //deathtypes:
@@ -245,7 +253,7 @@ MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor)
                                frag_deathtype == DEATH_CAMP.m_id ||
                                frag_deathtype == DEATH_LAVA.m_id ||
                                frag_deathtype == DEATH_SLIME.m_id))
-                                       GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * 0.75 * tmayhempointmultiplier * (1/(start_health + start_armorvalue)));
+                                       GameRules_scoring_add_team(frag_target, SCORE, (-1 * (frag_damage - excess)) * autocvar_g_tmayhem_scoringmethod_damage_weight * tmayhempointmultiplier * (1/(start_health + start_armorvalue)));
                        return;
                }
        }
@@ -253,29 +261,60 @@ MUTATOR_HOOKFUNCTION(tmayhem, PlayerDamage_SplitHealthArmor)
 
 MUTATOR_HOOKFUNCTION(tmayhem, GiveFragsForKill, CBC_ORDER_FIRST)
 {
-       switch(autocvar_g_tmayhem_scoringmethod)
-       {
-               //frags only
-               case 2:
-               {
-                                                                                                               //fix 999 score from 30 kills for example
-                       M_ARGV(2, float) = 1 * tmayhempointmultiplier * 1.0001;
-                       return true;
-               }
-               
-               //damage only
-               case 3:
+       entity frag_attacker = M_ARGV(0, entity);
+       entity frag_target = M_ARGV(1, entity);
+       
+       if(SAME_TEAM(frag_target, frag_attacker)){
+               switch(autocvar_g_tmayhem_scoringmethod)
                {
-                       M_ARGV(2, float) = 0;
-                       return true;
+                       //frags only
+                       case 2:
+                       {
+                                                                                                                       //fix 999 score from 30 kills for example
+                               M_ARGV(2, float) = -1 * tmayhempointmultiplier * 1.0001;
+                               return true;
+                       }
+
+                       //damage only
+                       case 3:
+                       {
+                               M_ARGV(2, float) = 0;
+                               return true;
+                       }
+
+                       //combined damage and frags
+                       default:
+                       case 1:
+                       {
+                               M_ARGV(2, float) = -autocvar_g_tmayhem_scoringmethod_frag_weight * tmayhempointmultiplier * 1.0001;
+                               return true;
+                       }
                }
-               
-               //combined damage and frags
-               default:
-               case 1:
+       } else {
+               switch(autocvar_g_tmayhem_scoringmethod)
                {
-                       M_ARGV(2, float) = 0.25 * tmayhempointmultiplier * 1.0001;
-                       return true;
+                       //frags only
+                       case 2:
+                       {
+                                                                                                                       //fix 999 score from 30 kills for example
+                               M_ARGV(2, float) = 1 * tmayhempointmultiplier * 1.0001;
+                               return true;
+                       }
+
+                       //damage only
+                       case 3:
+                       {
+                               M_ARGV(2, float) = 0;
+                               return true;
+                       }
+
+                       //combined damage and frags
+                       default:
+                       case 1:
+                       {
+                               M_ARGV(2, float) = autocvar_g_tmayhem_scoringmethod_frag_weight * tmayhempointmultiplier * 1.0001;
+                               return true;
+                       }
                }
        }
 }
index d8dbcdf76df7646a090ba42616678cf1aaed39d1..c31967fad40db617df61c281f575b2b6bfb855ef 100644 (file)
@@ -1,12 +1,7 @@
 #pragma once
 
 #include <common/mutators/base.qh>
-//someone who understands numbers better check if 2 following floats can be ints without imprecision, I'm scared of spaghettimonsters
-float autocvar_g_tmayhem_fraglimit;
-float autocvar_g_tmayhem_visual_score_limit;
-float autocvar_g_tmayhem_score_leadlimit;
-bool autocvar_g_tmayhem_team_spawns;
-float tmayhempointmultiplier = 1000/50;
+
 void tmayhem_Initialize();
 
 REGISTER_MUTATOR(tmayhem, false)
index 279bb7d53e35c4422c07950acb636e977e8c96df..e59d0c9d89216bfbdb2734e7dbb845217f9138a1 100644 (file)
@@ -388,7 +388,11 @@ void cvar_changes_init()
                BADCVAR("leadlimit_and_fraglimit");
                BADCVAR("leadlimit_override");
                BADCVAR("g_mayhem_scoringmethod");
+               BADCVAR("g_mayhem_scoringmethod_damage_weight");
+               BADCVAR("g_mayhem_scoringmethod_frag_weight");
                BADCVAR("g_tmayhem_scoringmethod");
+               BADCVAR("g_tmayhem_scoringmethod_damage_weight");
+               BADCVAR("g_tmayhem_scoringmethod_frag_weight");
                BADCVAR("pausable");
                BADCVAR("sv_announcer");
                BADCVAR("sv_checkforpacketsduringsleep");