]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Slightly optimize Spawn Near Teammate code mainly for readability
authorterencehill <piuntn@gmail.com>
Sun, 13 Mar 2022 10:53:30 +0000 (11:53 +0100)
committerterencehill <piuntn@gmail.com>
Sun, 13 Mar 2022 10:53:30 +0000 (11:53 +0100)
qcsrc/common/mutators/mutator/spawn_near_teammate/sv_spawn_near_teammate.qc

index c2a3250d8062ed47988623e92de6b8e707690e6b..5d663e876dff2bd4e9a37940b4d90143102df4ba 100644 (file)
@@ -54,6 +54,7 @@ MUTATOR_HOOKFUNCTION(spawn_near_teammate, Spawn_Score)
        M_ARGV(2, vector) = spawn_score;
 }
 
+vector snt_ofs[6];
 MUTATOR_HOOKFUNCTION(spawn_near_teammate, PlayerSpawn)
 {
        if (!teamplay) return;
@@ -116,30 +117,16 @@ MUTATOR_HOOKFUNCTION(spawn_near_teammate, PlayerSpawn)
                        // test different spots close to mate - trace upwards so it works on uneven surfaces
                        // don't spawn in front of player or directly behind to avoid players shooting each other
                        // test the potential spots in pairs (first pair is better than second and so on) but don't prefer one side
+                       snt_ofs[0] = up * 64 + right * 128 - forward * 64;
+                       snt_ofs[1] = up * 64 - right * 128 - forward * 64;
+                       snt_ofs[2] = up * 64 + right * 192;
+                       snt_ofs[3] = up * 64 - right * 192;
+                       snt_ofs[4] = up * 64 + right * 64 - forward * 128;
+                       snt_ofs[5] = up * 64 - right * 64 - forward * 128;
                        RandomSelection_Init();
                        for(int i = 0; i < 6; ++i)
                        {
-                               switch(i)
-                               {
-                                       case 0:
-                                               tracebox(it.origin, STAT(PL_MIN, player), STAT(PL_MAX, player), it.origin - forward * 64 + right * 128 + up * 64, MOVE_NOMONSTERS, it);
-                                               break;
-                                       case 1:
-                                               tracebox(it.origin, STAT(PL_MIN, player), STAT(PL_MAX, player), it.origin - forward * 64 - right * 128 + up * 64, MOVE_NOMONSTERS, it);
-                                               break;
-                                       case 2:
-                                               tracebox(it.origin, STAT(PL_MIN, player), STAT(PL_MAX, player), it.origin + right * 192 + up * 64, MOVE_NOMONSTERS, it);
-                                               break;
-                                       case 3:
-                                               tracebox(it.origin, STAT(PL_MIN, player), STAT(PL_MAX, player), it.origin - right * 192 + up * 64, MOVE_NOMONSTERS, it);
-                                               break;
-                                       case 4:
-                                               tracebox(it.origin, STAT(PL_MIN, player), STAT(PL_MAX, player), it.origin - forward * 128 + right * 64 + up * 64, MOVE_NOMONSTERS, it);
-                                               break;
-                                       case 5:
-                                               tracebox(it.origin, STAT(PL_MIN, player), STAT(PL_MAX, player), it.origin - forward * 128 - right * 64 + up * 64, MOVE_NOMONSTERS, it);
-                                               break;
-                               }
+                               tracebox(it.origin, STAT(PL_MIN, player), STAT(PL_MAX, player), it.origin + snt_ofs[i], MOVE_NOMONSTERS, it);
 
                                vector horizontal_trace_endpos = trace_endpos;
                                //te_lightning1(NULL, it.origin, horizontal_trace_endpos);
@@ -179,7 +166,7 @@ MUTATOR_HOOKFUNCTION(spawn_near_teammate, PlayerSpawn)
                                RandomSelection_Add(it, 0, string_null, vectical_trace_endpos, 1, 1);
                                //te_lightning1(NULL, vectical_trace_endpos, vectical_trace_endpos + forward * 10);
 
-LABEL(skip)
+                               LABEL(skip)
                                if (i % 2 == 1 && RandomSelection_chosen_ent)
                                {
                                        if (autocvar_g_spawn_near_teammate_ignore_spawnpoint_closetodeath)