]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
When switching from spectator to observer don't place the camera in a random spawnpoi...
authorterencehill <piuntn@gmail.com>
Thu, 10 Feb 2022 22:35:22 +0000 (23:35 +0100)
committerterencehill <piuntn@gmail.com>
Fri, 11 Feb 2022 22:44:24 +0000 (23:44 +0100)
qcsrc/common/minigames/sv_minigames.qc
qcsrc/server/client.qc
qcsrc/server/client.qh
qcsrc/server/clientkill.qc
qcsrc/server/command/sv_cmd.qc

index a1fb3631dd8b4c634787b8a93c855b5934ab8de3..57f6f46b6153570fe0b4c276875d07664191b539 100644 (file)
@@ -148,7 +148,7 @@ int minigame_addplayer(entity minigame_session, entity player)
                Net_LinkEntity(player_pointer, false, 0, minigame_SendEntity);
 
                if ( !IS_OBSERVER(player) && autocvar_sv_minigames_observer )
-                       PutObserverInServer(player, true);
+                       PutObserverInServer(player, true, true);
                if ( autocvar_sv_minigames_observer == 2 )
                        Player_SetForcedTeamIndex(player, TEAM_FORCE_SPECTATOR);
 
index daabb84c9cc9e9ee10bb6a4371cd73d4d39185f6..3af147c21374c52f3cec6aa3cc2e3c1d09b432f0 100644 (file)
@@ -235,7 +235,7 @@ void setplayermodel(entity e, string modelname)
 }
 
 /** putting a client as observer in the server */
-void PutObserverInServer(entity this, bool is_forced)
+void PutObserverInServer(entity this, bool is_forced, bool use_spawnpoint)
 {
        bool mutator_returnvalue = MUTATOR_CALLHOOK(MakePlayerObserver, this, is_forced);
        PlayerState_detach(this);
@@ -257,12 +257,18 @@ void PutObserverInServer(entity this, bool is_forced)
                entcs_update_players(this);
        }
 
-       entity spot = SelectSpawnPoint(this, true);
-       if (!spot) LOG_FATAL("No spawnpoints for observers?!?");
-       this.angles = vec2(spot.angles);
+       if (use_spawnpoint)
+       {
+               entity 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));
+       }
+       else // change origin to restore previous view origin
+               setorigin(this, this.origin + STAT(PL_VIEW_OFS, this) - STAT(PL_CROUCH_VIEW_OFS, this));
        this.fixangle = true;
-       // offset it so that the spectator spawns higher off the ground, looks better this way
-       setorigin(this, spot.origin + STAT(PL_VIEW_OFS, this));
+
        if (IS_REAL_CLIENT(this))
        {
                msg_entity = this;
@@ -809,6 +815,7 @@ void PutClientInServer(entity this)
        if (game_stopped)
                TRANSMUTE(Observer, this);
 
+       bool use_spawnpoint = (!this.enemy); // check this.enemy here since SetSpectatee will clear it
        SetSpectatee(this, NULL);
 
        // reset player keys
@@ -818,7 +825,7 @@ void PutClientInServer(entity this)
        MUTATOR_CALLHOOK(PutClientInServer, this);
 
        if (IS_OBSERVER(this)) {
-               PutObserverInServer(this, false);
+               PutObserverInServer(this, false, use_spawnpoint);
        } else if (IS_PLAYER(this)) {
                PutPlayerInServer(this);
        }
@@ -1797,7 +1804,7 @@ bool SpectateSet(entity this)
        accuracy_resend(this);
 
        if(!SpectateUpdate(this))
-               PutObserverInServer(this, false);
+               PutObserverInServer(this, false, true);
 
        return true;
 }
@@ -2300,7 +2307,7 @@ void ObserverOrSpectatorThink(entity this)
                                TRANSMUTE(Observer, this);
                                PutClientInServer(this);
                        } else if(!SpectateUpdate(this) && !SpectateNext(this)) {
-                               PutObserverInServer(this, false);
+                               PutObserverInServer(this, false, true);
                                this.would_spectate = true;
                        }
                }
@@ -2326,7 +2333,7 @@ void ObserverOrSpectatorThink(entity this)
                        }
                }
                if(is_spec && !SpectateUpdate(this))
-                       PutObserverInServer(this, false);
+                       PutObserverInServer(this, false, true);
        }
        if (is_spec)
                this.flags |= FL_CLIENT | FL_NOTARGET;
@@ -2697,7 +2704,7 @@ void PlayerPostThink (entity this)
                                if (IS_PLAYER(this) && autocvar_sv_maxidle_playertospectator > 0)
                                {
                                        Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_MOVETOSPEC_IDLING, this.netname, maxidle_time);
-                                       PutObserverInServer(this, true);
+                                       PutObserverInServer(this, true, true);
                                }
                                else
                                {
index 8f7b9c4f3224be1655e2b73cdaa5553e62f7957f..cca687aeb6d2447293171adebd68dc49ca180353 100644 (file)
@@ -385,7 +385,7 @@ bool Spectate(entity this, entity pl);
 
 void ClientInit_Spawn();
 
-void PutObserverInServer(entity this, bool is_forced);
+void PutObserverInServer(entity this, bool is_forced, bool use_spawnpoint);
 
 void SetSpectatee(entity this, entity spectatee);
 void SetSpectatee_status(entity this, int spectatee_num);
index 474f15af1e5f4ca7da6ee0c70c942c430cdbcf34..296a95bfe5f384c9d8428626f0a1cbd0282fff2f 100644 (file)
@@ -25,7 +25,7 @@ void ClientKill_Now_TeamChange(entity this)
        {
                if (blockSpectators)
                        Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
-               PutObserverInServer(this, false);
+               PutObserverInServer(this, false, true);
        }
        else
        {
index ca6b268e23708a51b5fdb000e295fa4226512657..e09458f79a1ab1590a7186a14cadf1fbc1c343fe 100644 (file)
@@ -191,7 +191,7 @@ void GameCommand_allspec(int request, int argc)
                        string reason = argv(1);
                        int n = 0;
                        FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
-                               PutObserverInServer(it, true);
+                               PutObserverInServer(it, true, true);
                                ++n;
                        });
                        if (n)   bprint(strcat("Successfully forced all (", ftos(n), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n"));
@@ -1016,7 +1016,7 @@ void GameCommand_moveplayer(int request, int argc)
                                                string pl_name = playername(client.netname, client.team, false);
                                                if (!IS_SPEC(client) && !IS_OBSERVER(client))
                                                {
-                                                       PutObserverInServer(client, true);
+                                                       PutObserverInServer(client, true, true);
 
                                                        successful = strcat(successful, (successful ? ", " : ""), pl_name);
                                                }