entity player = M_ARGV(0, entity);
entity spawn_spot = M_ARGV(1, entity);
+ //LOG_INFOF("PlayerSpawn for player: %s %v spawn_spot: %v\n", player.netname, player.origin, spawn_spot.origin);
+
int num_red = 0, num_blue = 0, num_yellow = 0, num_pink = 0;
FOREACH_CLIENT(IS_PLAYER(it),
{
player.msnt_timer = time + autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay_death;
entity best_mate = NULL;
- vector best_spot = '0 0 0';
- float pc = 0, best_dist = 0, dist = 0;
- FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
- if((autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health >= 0 && it.health >= autocvar_g_balance_health_regenstable) || autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health == 0)
- if(!IS_DEAD(it))
- if(it.msnt_timer < time)
- if(SAME_TEAM(player, it))
- if(time > it.spawnshieldtime) // spawn shielding
- if(!forbidWeaponUse(it))
- if(STAT(FROZEN, it) == 0)
- if(it != player)
+ vector best_pos = '0 0 0';
+ float best_dist = 0;
+ FOREACH_CLIENT_RANDOM(IS_PLAYER(it), LAMBDA(
+ //LOG_INFOF(" for client: %s %v\n", it.netname, it.origin);
+ if (!SAME_TEAM(player, it)) continue;
+ if (autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health >= 0 && it.health < autocvar_g_balance_health_regenstable) continue;
+ if (IS_DEAD(it)) continue;
+ if (time < it.msnt_timer) continue;
+ if (time < it.spawnshieldtime) continue;
+ if (forbidWeaponUse(it)) continue;
+ if (it == player) continue;
+
+ vector horiz_vel = vec2(it.velocity);
+ if (vdist(horiz_vel, >, 450))
+ fixedmakevectors(vectoangles(horiz_vel));
+ else
+ fixedmakevectors(it.angles); // .angles is the angle of the model - usually/always 0 pitch
+
+ // 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
+ for(int i = 0; i < 6; ++i)
{
- tracebox(it.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - '0 0 100', MOVE_NOMONSTERS, it);
- if(trace_fraction != 1.0)
- if(!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY))
+ switch(i)
{
- pc = pointcontents(trace_endpos + '0 0 1');
- if(pc == CONTENT_EMPTY)
+ case 0:
+ tracebox(it.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - v_forward * 64 + v_right * 128 + v_up * 64, MOVE_NOMONSTERS, it);
+ break;
+ case 1:
+ tracebox(it.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - v_forward * 64 - v_right * 128 + v_up * 64, MOVE_NOMONSTERS, it);
+ break;
+ case 2:
+ tracebox(it.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin + v_right * 192 + v_up * 64, MOVE_NOMONSTERS, it);
+ break;
+ case 3:
+ tracebox(it.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - v_right * 192 + v_up * 64, MOVE_NOMONSTERS, it);
+ break;
+ case 4:
+ tracebox(it.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - v_forward * 128 + v_right * 64 + v_up * 64, MOVE_NOMONSTERS, it);
+ break;
+ case 5:
+ tracebox(it.origin, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - v_forward * 128 - v_right * 64 + v_up * 64, MOVE_NOMONSTERS, it);
+ break;
+
+ }
+ vector horizontal_trace_endpos = trace_endpos;
+ //te_lightning1(NULL, it.origin, horizontal_trace_endpos);
+ if(trace_fraction != 1.0) continue;
+
+ // 400 is about the height of a typical laser jump (in overkill)
+ // not traceline because we need space for the whole player, not just his origin
+ tracebox(horizontal_trace_endpos, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), horizontal_trace_endpos - '0 0 400', MOVE_NORMAL, it);
+ vector vectical_trace_endpos = trace_endpos;
+ //te_lightning1(NULL, horizontal_trace_endpos, vectical_trace_endpos);
+ if (trace_startsolid) continue; // inside another player
+ if (trace_fraction == 1.0) continue; // above void or too high
+ if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY) continue;
+ if (pointcontents(vectical_trace_endpos) != CONTENT_EMPTY) continue; // this also prevents spawning in water which i assume would be annoying
+ if (tracebox_hits_trigger_hurt(horizontal_trace_endpos, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), vectical_trace_endpos)) continue;
+
+ // make sure the spawned player will have floor ahead (or at least a wall - he shouldn't fall as soon as he starts moving)
+ vector floor_test_start = vectical_trace_endpos + v_up * STAT(PL_MAX, NULL).z + v_forward * STAT(PL_MAX, NULL).x; // top front of player's bbox - highest point we know is not inside solid
+ traceline(floor_test_start, floor_test_start + v_forward * 100 - v_up * 128, MOVE_NOMONSTERS, it);
+ //te_beam(NULL, floor_test_start, trace_endpos);
+ if (trace_fraction == 1.0) continue;
+
+ if (autocvar_g_nades) {
+ bool nade_in_range = false;
+ IL_EACH(g_projectiles, it.classname == "nade",
{
- if(vdist(it.velocity, >, 5))
- fixedmakevectors(vectoangles(it.velocity));
- else
- fixedmakevectors(it.angles);
-
- for(pc = 0; pc < 4; ++pc) // test 4 diffrent spots close to mate
- {
- switch(pc)
- {
- case 0:
- tracebox(it.origin , STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin + v_right * 128, MOVE_NOMONSTERS, it);
- break;
- case 1:
- tracebox(it.origin , STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - v_right * 128 , MOVE_NOMONSTERS, it);
- break;
- case 2:
- tracebox(it.origin , STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin + v_right * 128 - v_forward * 64, MOVE_NOMONSTERS, it);
- break;
- case 3:
- tracebox(it.origin , STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - v_right * 128 - v_forward * 64, MOVE_NOMONSTERS, it);
- break;
- //case 4:
- //tracebox(it.origin , STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), it.origin - v_forward * 128, MOVE_NOMONSTERS, it);
- //break;
- }
-
- if(trace_fraction == 1.0)
- {
- traceline(trace_endpos + '0 0 4', trace_endpos - '0 0 100', MOVE_NOMONSTERS, it);
- if(trace_fraction != 1.0)
- {
- if(autocvar_g_spawn_near_teammate_ignore_spawnpoint_closetodeath)
- {
- dist = vlen(trace_endpos - player.msnt_deathloc);
- if(dist < best_dist || best_dist == 0)
- {
- best_dist = dist;
- best_spot = trace_endpos;
- best_mate = it;
- }
- }
- else
- {
- setorigin(player, trace_endpos);
- player.angles = it.angles;
- player.angles_z = 0; // never spawn tilted even if the spot says to
- it.msnt_timer = time + autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay;
- return;
- }
- }
- }
+ if (vdist(it.origin - vectical_trace_endpos, <, autocvar_g_nades_nade_radius)) {
+ nade_in_range = true;
+ break;
}
+ });
+ if (nade_in_range) continue;
+ }
+
+ if(autocvar_g_spawn_near_teammate_ignore_spawnpoint_closetodeath)
+ {
+ float dist = vlen(vectical_trace_endpos - player.msnt_deathloc);
+ //LOG_INFOF(" dist: %f, best_dist %f\n", dist, best_dist);
+ if(dist < best_dist || best_dist == 0)
+ {
+ //LOG_INFOF(" new best dist - pos: %v\n", vectical_trace_endpos);
+ best_dist = dist;
+ best_pos = vectical_trace_endpos;
+ best_mate = it;
}
}
+ else
+ {
+ setorigin(player, vectical_trace_endpos);
+ player.angles = it.angles;
+ player.angles_z = 0; // never spawn tilted even if the spot says to
+ it.msnt_timer = time + autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay;
+ //LOG_INFOF(" PlayerSpawn return %v\n", player.origin);
+ return;
+ }
}
));
if(autocvar_g_spawn_near_teammate_ignore_spawnpoint_closetodeath)
if(best_dist)
{
- setorigin(player, best_spot);
+ setorigin(player, best_pos);
player.angles = best_mate.angles;
player.angles_z = 0; // never spawn tilted even if the spot says to
best_mate.msnt_timer = time + autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay;