]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move more of weaponarena_random into its mutator file
authorMario <mario@smbclan.net>
Sat, 9 Jun 2018 13:21:57 +0000 (23:21 +1000)
committerMario <mario@smbclan.net>
Sat, 9 Jun 2018 13:21:57 +0000 (23:21 +1000)
qcsrc/common/mutators/mutator/weaponarena_random/sv_weaponarena_random.qc
qcsrc/common/mutators/mutator/weaponarena_random/sv_weaponarena_random.qh
qcsrc/server/g_damage.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/miscfunctions.qh
qcsrc/server/mutators/events.qh
qcsrc/server/teamplay.qc

index f4f7e344743319d65b57d19834c4c9110617d6c5..32b6f3930595ec6376b56e204b39bf46c5fc3db9 100644 (file)
@@ -3,6 +3,16 @@
 // WEAPONTODO: rename the cvars
 REGISTER_MUTATOR(weaponarena_random, true);
 
+MUTATOR_HOOKFUNCTION(weaponarena_random, SetStartItems)
+{
+       if(g_weaponarena)
+               g_weaponarena_random = cvar("g_weaponarena_random");
+       else
+               g_weaponarena_random = 0;
+       
+       g_weaponarena_random_with_blaster = cvar("g_weaponarena_random_with_blaster");
+}
+
 MUTATOR_HOOKFUNCTION(weaponarena_random, PlayerSpawn)
 {
     if (!g_weaponarena_random) return;
@@ -12,3 +22,54 @@ MUTATOR_HOOKFUNCTION(weaponarena_random, PlayerSpawn)
     STAT(WEAPONS, player) = W_RandomWeapons(player, STAT(WEAPONS, player), g_weaponarena_random);
     if (g_weaponarena_random_with_blaster) STAT(WEAPONS, player) |= WEPSET(BLASTER);
 }
+
+MUTATOR_HOOKFUNCTION(weaponarena_random, GiveFragsForKill)
+{
+       if(!g_weaponarena_random) return;
+       entity attacker = M_ARGV(0, entity);
+       entity targ = M_ARGV(1, entity);
+       float deathtype = M_ARGV(3, float);
+       entity wep_ent = M_ARGV(4, entity);
+       .entity weaponentity = wep_ent.weaponentity_fld;
+
+       if(targ == attacker) return; // not for suicides
+
+       // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
+       Weapon culprit = DEATH_WEAPONOF(deathtype);
+       if(!culprit) culprit = wep_ent.m_weapon;
+       else if(!(STAT(WEAPONS, attacker) & (culprit.m_wepset))) culprit = wep_ent.m_weapon;
+
+       if(g_weaponarena_random_with_blaster && culprit == WEP_BLASTER)
+       {
+               // no exchange
+       }
+       else
+       {
+               if(!GiveFrags_randomweapons)
+               {
+                       GiveFrags_randomweapons = new(GiveFrags_randomweapons);
+               }
+
+               if(warmup_stage)
+                       STAT(WEAPONS, GiveFrags_randomweapons) = WARMUP_START_WEAPONS;
+               else
+                       STAT(WEAPONS, GiveFrags_randomweapons) = start_weapons;
+
+               // all others (including the culprit): remove
+               STAT(WEAPONS, GiveFrags_randomweapons) &= ~STAT(WEAPONS, attacker);
+               STAT(WEAPONS, GiveFrags_randomweapons) &= ~(culprit.m_wepset);
+
+               // among the remaining ones, choose one by random
+               STAT(WEAPONS, GiveFrags_randomweapons) = W_RandomWeapons(GiveFrags_randomweapons, STAT(WEAPONS, GiveFrags_randomweapons), 1);
+
+               if(STAT(WEAPONS, GiveFrags_randomweapons))
+               {
+                       STAT(WEAPONS, attacker) |= STAT(WEAPONS, GiveFrags_randomweapons);
+                       STAT(WEAPONS, attacker) &= ~(culprit.m_wepset);
+               }
+       }
+
+       // after a frag, choose another random weapon set
+       if (!(STAT(WEAPONS, attacker) & WepSet_FromWeapon(wep_ent.m_weapon)))
+               W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker, weaponentity), weaponentity);
+}
index dcbc20342df2294a3e60be5426316d3362be9d0f..e496404902dcd9e3b4daa2267de2d1f004ffd36f 100644 (file)
@@ -61,51 +61,8 @@ void GiveFrags (entity attacker, entity targ, float f, int deathtype, .entity we
 
        GameRules_scoring_add(targ, DEATHS, 1);
 
-       if(targ != attacker) // not for suicides
-       if(g_weaponarena_random)
-       {
-               // after a frag, exchange the current weapon (or the culprit, if detectable) by a new random weapon
-               Weapon culprit = DEATH_WEAPONOF(deathtype);
-               if(!culprit) culprit = attacker.(weaponentity).m_weapon;
-               else if(!(STAT(WEAPONS, attacker) & (culprit.m_wepset))) culprit = attacker.(weaponentity).m_weapon;
-
-               if(g_weaponarena_random_with_blaster && culprit == WEP_BLASTER) // WEAPONTODO: Shouldn't this be in a mutator?
-               {
-                       // no exchange
-               }
-               else
-               {
-                       if(!GiveFrags_randomweapons)
-                       {
-                               GiveFrags_randomweapons = new(GiveFrags_randomweapons);
-                       }
-
-                       if(warmup_stage)
-                               STAT(WEAPONS, GiveFrags_randomweapons) = WARMUP_START_WEAPONS;
-                       else
-                               STAT(WEAPONS, GiveFrags_randomweapons) = start_weapons;
-
-                       // all others (including the culprit): remove
-                       STAT(WEAPONS, GiveFrags_randomweapons) &= ~STAT(WEAPONS, attacker);
-                       STAT(WEAPONS, GiveFrags_randomweapons) &= ~(culprit.m_wepset);
-
-                       // among the remaining ones, choose one by random
-                       STAT(WEAPONS, GiveFrags_randomweapons) = W_RandomWeapons(GiveFrags_randomweapons, STAT(WEAPONS, GiveFrags_randomweapons), 1);
-
-                       if(STAT(WEAPONS, GiveFrags_randomweapons))
-                       {
-                               STAT(WEAPONS, attacker) |= STAT(WEAPONS, GiveFrags_randomweapons);
-                               STAT(WEAPONS, attacker) &= ~(culprit.m_wepset);
-                       }
-               }
-
-               // after a frag, choose another random weapon set
-               if (!(STAT(WEAPONS, attacker) & WepSet_FromWeapon(attacker.(weaponentity).m_weapon)))
-                       W_SwitchWeapon_Force(attacker, w_getbestweapon(attacker, weaponentity), weaponentity);
-       }
-
        // FIXME fix the mess this is (we have REAL points now!)
-       if(MUTATOR_CALLHOOK(GiveFragsForKill, attacker, targ, f))
+       if(MUTATOR_CALLHOOK(GiveFragsForKill, attacker, targ, f, deathtype, attacker.(weaponentity)))
                f = M_ARGV(2, float);
 
        attacker.totalfrags += f;
index bbbefd5a88f11cbb32e959a313366da154c3de74..a09aec0f50bc3b7a80da6fa126cb5ad16239d5d3 100644 (file)
@@ -592,12 +592,6 @@ void readplayerstartcvars()
                g_weaponarena_list = strzone(substring(g_weaponarena_list, 0, strlen(g_weaponarena_list) - 3));
        }
 
-       if(g_weaponarena)
-               g_weaponarena_random = cvar("g_weaponarena_random");
-       else
-               g_weaponarena_random = 0;
-       g_weaponarena_random_with_blaster = cvar("g_weaponarena_random_with_blaster");
-
        if (g_weaponarena)
        {
                g_weapon_stay = 0; // incompatible
index 41e725946a96cb43c1cd5febd0a04f76deb79359..16c5a1d4d48dd1f738d4c20621dc61310ad90d23 100644 (file)
@@ -168,8 +168,7 @@ float g_pickup_fuel_max;
 float g_pickup_weapons_anyway;
 float g_weaponarena;
 WepSet g_weaponarena_weapons;
-float g_weaponarena_random;
-float g_weaponarena_random_with_blaster;
+float g_weaponarena_random; // TODO
 string g_weaponarena_list;
 float g_weaponspeedfactor;
 float g_weaponratefactor;
index 3f35fe9eaa39e816f3a8bf9c063cc4977c735087..cf39f337bb15b48cbe9b8bc527ac5b1e822b1c23 100644 (file)
@@ -123,6 +123,8 @@ MUTATOR_HOOKABLE(ItemSound, EV_ItemSound);
     /** target     */ i(entity, MUTATOR_ARGV_1_entity) \
     /** frag score */ i(float, MUTATOR_ARGV_2_float) \
     /**            */ o(float, MUTATOR_ARGV_2_float) \
+    /** deathtype  */ i(float, MUTATOR_ARGV_3_float) \
+    /** wep entity */ i(entity, MUTATOR_ARGV_4_entity) \
     /**/
 MUTATOR_HOOKABLE(GiveFragsForKill, EV_GiveFragsForKill);
 
index 43aa4a26bd24e61d362d64dce55f33090ee88c9a..a137f4150e1546ccf3dc8ffee26824399085683d 100644 (file)
@@ -105,7 +105,7 @@ string getwelcomemessage(entity this)
        if(g_weaponarena)
        {
                if(g_weaponarena_random)
-                       modifications = strcat(modifications, ", ", ftos(g_weaponarena_random), " of ", g_weaponarena_list, " Arena");
+                       modifications = strcat(modifications, ", ", ftos(g_weaponarena_random), " of ", g_weaponarena_list, " Arena"); // TODO: somehow get this into the mutator
                else
                        modifications = strcat(modifications, ", ", g_weaponarena_list, " Arena");
        }