]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/spawn_near_teammate/sv_spawn_near_teammate.qc
Reduce name space of resource constants and variables (RESOURCE_* --> RES_*, resour...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / spawn_near_teammate / sv_spawn_near_teammate.qc
index ee75728630e2e5623f988e1d7efaf7b31d9f37d7..644206049a3bdcf4b31d4ceee1906b3eb72e2e11 100644 (file)
@@ -2,6 +2,7 @@
 
 #include <lib/float.qh>
 
+string autocvar_g_spawn_near_teammate;
 float autocvar_g_spawn_near_teammate_distance;
 int autocvar_g_spawn_near_teammate_ignore_spawnpoint;
 int autocvar_g_spawn_near_teammate_ignore_spawnpoint_max;
@@ -10,7 +11,7 @@ float autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay_death;
 bool autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health;
 bool autocvar_g_spawn_near_teammate_ignore_spawnpoint_closetodeath;
 
-REGISTER_MUTATOR(spawn_near_teammate, cvar("g_spawn_near_teammate"));
+REGISTER_MUTATOR(spawn_near_teammate, expr_evaluate(autocvar_g_spawn_near_teammate));
 
 .entity msnt_lookat;
 
@@ -20,20 +21,19 @@ REGISTER_MUTATOR(spawn_near_teammate, cvar("g_spawn_near_teammate"));
 
 MUTATOR_HOOKFUNCTION(spawn_near_teammate, Spawn_Score)
 {
+       if (!teamplay) return;
+
        entity player = M_ARGV(0, entity);
        entity spawn_spot = M_ARGV(1, entity);
        vector spawn_score = M_ARGV(2, vector);
 
-       if(autocvar_g_spawn_near_teammate_ignore_spawnpoint == 1 || (autocvar_g_spawn_near_teammate_ignore_spawnpoint == 2 && player.cvar_cl_spawn_near_teammate))
+       if(autocvar_g_spawn_near_teammate_ignore_spawnpoint == 1 || (autocvar_g_spawn_near_teammate_ignore_spawnpoint == 2 && CS(player).cvar_cl_spawn_near_teammate))
                return;
 
        spawn_spot.msnt_lookat = NULL;
 
-       if(!teamplay)
-               return;
-
        RandomSelection_Init();
-       FOREACH_CLIENT(IS_PLAYER(it) && it != player && SAME_TEAM(it, player) && !IS_DEAD(it), LAMBDA(
+       FOREACH_CLIENT(IS_PLAYER(it) && it != player && SAME_TEAM(it, player) && !IS_DEAD(it), {
                if(vdist(spawn_spot.origin - it.origin, >, autocvar_g_spawn_near_teammate_distance))
                        continue;
                if(vdist(spawn_spot.origin - it.origin, <, 48))
@@ -41,7 +41,7 @@ MUTATOR_HOOKFUNCTION(spawn_near_teammate, Spawn_Score)
                if(!checkpvs(spawn_spot.origin, it))
                        continue;
                RandomSelection_AddEnt(it, 1, 1);
-       ));
+       });
 
        if(RandomSelection_chosen_ent)
        {
@@ -56,7 +56,8 @@ MUTATOR_HOOKFUNCTION(spawn_near_teammate, Spawn_Score)
 
 MUTATOR_HOOKFUNCTION(spawn_near_teammate, PlayerSpawn)
 {
-       if(!teamplay) { return; }
+       if (!teamplay) return;
+
        entity player = M_ARGV(0, entity);
        entity spawn_spot = M_ARGV(1, entity);
 
@@ -76,7 +77,7 @@ MUTATOR_HOOKFUNCTION(spawn_near_teammate, PlayerSpawn)
                return; // at least 1 team has only 1 player, let's not give the bigger team too much of an advantage!
 
        // Note: when entering this, fixangle is already set.
-       if(autocvar_g_spawn_near_teammate_ignore_spawnpoint == 1 || (autocvar_g_spawn_near_teammate_ignore_spawnpoint == 2 && player.cvar_cl_spawn_near_teammate))
+       if(autocvar_g_spawn_near_teammate_ignore_spawnpoint == 1 || (autocvar_g_spawn_near_teammate_ignore_spawnpoint == 2 && CS(player).cvar_cl_spawn_near_teammate))
        {
                if(autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay_death)
                        player.msnt_timer = time + autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay_death;
@@ -85,12 +86,12 @@ MUTATOR_HOOKFUNCTION(spawn_near_teammate, PlayerSpawn)
                vector best_pos = '0 0 0';
                float best_dist2 = FLOAT_MAX;
                int tested = 0;
-               FOREACH_CLIENT_RANDOM(IS_PLAYER(it), LAMBDA(
+               FOREACH_CLIENT_RANDOM(IS_PLAYER(it), {
                        if (autocvar_g_spawn_near_teammate_ignore_spawnpoint_max && tested >= autocvar_g_spawn_near_teammate_ignore_spawnpoint_max) break;
 
                        if (PHYS_INPUT_BUTTON_CHAT(it)) continue;
-                       if (!SAME_TEAM(player, it)) continue;
-                       if (autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health && it.health < autocvar_g_balance_health_regenstable) continue;
+                       if (DIFF_TEAM(player, it)) continue;
+                       if (autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health && GetResourceAmount(it, RES_HEALTH) < autocvar_g_balance_health_regenstable) continue;
                        if (IS_DEAD(it)) continue;
                        if (time < it.msnt_timer) continue;
                        if (time < it.spawnshieldtime) continue;
@@ -196,7 +197,7 @@ LABEL(skip)
                                        break; // don't test the other spots near this teammate, go to the next one
                                }
                        }
-               ));
+               });
 
                if(autocvar_g_spawn_near_teammate_ignore_spawnpoint_closetodeath)
                if(best_mate)