From 95122a2bce27bf7528b1c229d14b7d6849f3d2e4 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 23 Sep 2024 19:40:32 +0000 Subject: [PATCH] Make observers view from predefined locations if available --- .gitlab-ci.yml | 2 +- qcsrc/server/cheats.qc | 5 +++++ qcsrc/server/client.qc | 19 +++++++++++++++++-- qcsrc/server/client.qh | 7 ++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3d2d310a0..c0057d597 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -36,7 +36,7 @@ test_compilation_units: test_sv_game: stage: test script: - - export EXPECT=82b429be1301d38fbe0af0c60511ceed + - export EXPECT=13aa630f559c7683195b8c8d5e0a1522 - qcsrc/tools/sv_game-hashtest.sh - exit $? diff --git a/qcsrc/server/cheats.qc b/qcsrc/server/cheats.qc index 9ec7cc69a..f7c55af4c 100644 --- a/qcsrc/server/cheats.qc +++ b/qcsrc/server/cheats.qc @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -125,6 +126,10 @@ spawnfunc(info_autoscreenshot) } if(this.target != "") InitializeEntity(this, info_autoscreenshot_findtarget, INITPRIO_FINDTARGET); + + tracebox(this.origin, PL_CROUCH_MIN_CONST, PL_CROUCH_MAX_CONST, this.origin, MOVE_WORLDONLY, this); + if(!trace_startsolid) + IL_PUSH(g_observepoints, this); } float CheatImpulse(entity this, int imp) diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index bd7ab6a9b..92256c58f 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -238,6 +238,16 @@ void setplayermodel(entity e, string modelname) UpdatePlayerSounds(e); } +entity SelectObservePoint(entity this) +{ + RandomSelection_Init(); + IL_EACH(g_observepoints, true, + { + RandomSelection_AddEnt(it, 1, 1); + }); + return RandomSelection_chosen_ent; +} + /** putting a client as observer in the server */ void PutObserverInServer(entity this, bool is_forced, bool use_spawnpoint) { @@ -265,11 +275,16 @@ void PutObserverInServer(entity this, bool is_forced, bool use_spawnpoint) if (use_spawnpoint) { - entity spot = SelectSpawnPoint(this, true); + // first try to find a random "nice" location to view from + entity spot = SelectObservePoint(this); + bool is_observepoint = (spot != NULL); + if(!spot) // otherwise just use the player spawn points + spot = SelectSpawnPoint(this, true); if (!spot) LOG_FATAL("No spawnpoints for observers?!?"); + this.angles = vec2(spot.angles); // offset it so that the spectator spawns higher off the ground, looks better this way - setorigin(this, spot.origin + STAT(PL_VIEW_OFS, this)); + setorigin(this, spot.origin + (is_observepoint ? '0 0 0' : autocvar_sv_player_viewoffset)); } else // change origin to restore previous view origin setorigin(this, this.origin + STAT(PL_VIEW_OFS, this) - STAT(PL_CROUCH_VIEW_OFS, this)); diff --git a/qcsrc/server/client.qh b/qcsrc/server/client.qh index 815e26390..28f454522 100644 --- a/qcsrc/server/client.qh +++ b/qcsrc/server/client.qh @@ -370,7 +370,12 @@ void FixClientCvars(entity e); .void(entity this, entity player) init_for_player; IntrusiveList g_initforplayer; -STATIC_INIT(g_initforplayer) { g_initforplayer = IL_NEW(); } +IntrusiveList g_observepoints; +STATIC_INIT(client_lists) +{ + g_initforplayer = IL_NEW(); + g_observepoints = IL_NEW(); +} void play_countdown(entity this, float finished, Sound samp); void player_powerups_remove_all(entity this); -- 2.39.2