From d10bc3e0bfad39bddd8a16c4a180f48d8edb457b Mon Sep 17 00:00:00 2001 From: terencehill Date: Sun, 13 Mar 2022 11:53:30 +0100 Subject: [PATCH] Slightly optimize Spawn Near Teammate code mainly for readability --- .../sv_spawn_near_teammate.qc | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/qcsrc/common/mutators/mutator/spawn_near_teammate/sv_spawn_near_teammate.qc b/qcsrc/common/mutators/mutator/spawn_near_teammate/sv_spawn_near_teammate.qc index c2a3250d8..5d663e876 100644 --- a/qcsrc/common/mutators/mutator/spawn_near_teammate/sv_spawn_near_teammate.qc +++ b/qcsrc/common/mutators/mutator/spawn_near_teammate/sv_spawn_near_teammate.qc @@ -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) -- 2.39.2