]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/client.qc
Fix respawning instantly while jump button is held and respawning is forced
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / client.qc
index b2fee6690928925ca3f173494a012c3161d3ee68..e42807ec5de086baf5572a1c23f3398b165b6a3d 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <common/effects/qc/globalsound.qh>
 
+#include "../common/triggers/func/conveyor.qh"
 #include "../common/triggers/teleporters.qh"
 
 #include "../common/vehicles/all.qh"
@@ -295,6 +296,8 @@ void PutObserverInServer(entity this)
        accuracy_resend(this);
 
        this.spectatortime = time;
+       if(this.bot_attack)
+               IL_REMOVE(g_bot_targets, this);
        this.bot_attack = false;
     this.hud = HUD_NORMAL;
        TRANSMUTE(Observer, this);
@@ -631,11 +634,15 @@ void PutClientInServer(entity this)
                this.oldorigin = this.origin;
                this.prevorigin = this.origin;
                this.lastteleporttime = time; // prevent insane speeds due to changing origin
+               if(this.conveyor)
+                       IL_REMOVE(g_conveyed, this);
                this.conveyor = NULL; // prevent conveyors at the previous location from moving a freshly spawned player
                this.hud = HUD_NORMAL;
 
                this.event_damage = PlayerDamage;
 
+               if(!this.bot_attack)
+                       IL_PUSH(g_bot_targets, this);
                this.bot_attack = true;
                this.monster_attack = true;
 
@@ -938,10 +945,8 @@ void ClientKill_TeamChange (entity this, float targetteam) // 0 = don't change,
                        this.killindicator.count = bound(0, ceil(killtime), 10);
                        //sprint(this, strcat("^1You'll be dead in ", ftos(this.killindicator.cnt), " seconds\n"));
 
-                       FOREACH_ENTITY_ENT(enemy, this,
+                       IL_EACH(g_clones, it.enemy == this && !(it.effects & CSQCMODEL_EF_RESPAWNGHOST),
                        {
-                               if(it.classname != "body")
-                                       continue;
                                it.killindicator = spawn();
                                it.killindicator.owner = it;
                                it.killindicator.scale = 0.5;
@@ -1137,7 +1142,10 @@ void ClientConnect(entity this)
 
        this.netname_previous = strzone(this.netname);
 
-       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((teamplay && IS_PLAYER(this)) ? APP_TEAM_ENT(this, INFO_JOIN_CONNECT_TEAM) : INFO_JOIN_CONNECT), this.netname);
+       if(teamplay && IS_PLAYER(this))
+               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_JOIN_CONNECT_TEAM), this.netname);
+       else
+               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_JOIN_CONNECT, this.netname);
 
        stuffcmd(this, clientstuff, "\n");
        stuffcmd(this, "cl_particles_reloadeffects\n"); // TODO do we still need this?
@@ -1200,7 +1208,7 @@ void ClientConnect(entity this)
        if (IS_REAL_CLIENT(this))
                sv_notice_join(this);
 
-       FOREACH_ENTITY_FLOAT(init_for_player_needed, true, {
+       IL_EACH(g_initforplayer, it.init_for_player, {
                it.init_for_player(it, this);
        });
 
@@ -1861,31 +1869,34 @@ void ShowRespawnCountdown(entity this)
        }
 }
 
-.int team_selected;
-void LeaveSpectatorMode(entity this)
+.bool team_selected;
+bool ShowTeamSelection(entity this)
 {
        if(!teamplay || autocvar_g_campaign || autocvar_g_balance_teams || this.team_selected || (this.wasplayer && autocvar_g_changeteam_banned) || this.team_forced > 0)
-       {
-               TRANSMUTE(Player, this);
-
-               SetSpectatee(this, NULL);
+               return false;
+       stuffcmd(this, "menu_showteamselect\n");
+       return true;
+}
+void Join(entity this)
+{
+       TRANSMUTE(Player, this);
 
-               if(autocvar_g_campaign || autocvar_g_balance_teams)
-                       JoinBestTeam(this, false, true);
+       if(!this.team_selected)
+       if(autocvar_g_campaign || autocvar_g_balance_teams)
+               JoinBestTeam(this, false, true);
 
-               if(autocvar_g_campaign)
-                       campaign_bots_may_start = true;
+       if(autocvar_g_campaign)
+               campaign_bots_may_start = true;
 
-               Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_PREVENT_JOIN);
+       Kill_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CPID_PREVENT_JOIN);
 
-               PutClientInServer(this);
-               PlayerScore_Clear(this);
+       PutClientInServer(this);
 
-               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, ((teamplay && this.team != -1) ? APP_TEAM_ENT(this, INFO_JOIN_PLAY_TEAM) : INFO_JOIN_PLAY), this.netname);
-               this.team_selected = false;
-       }
+       if(teamplay && this.team != -1)
+               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_JOIN_PLAY_TEAM), this.netname);
        else
-               stuffcmd(this, "menu_showteamselect\n");
+               Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_JOIN_PLAY, this.netname);
+       this.team_selected = false;
 }
 
 /**
@@ -1906,7 +1917,7 @@ int nJoinAllowed(entity this, entity ignore)
                        return 0;
        }
 
-       if(this.team_forced < 0)
+       if(this && this.team_forced < 0)
                return 0; // forced spectators can never join
 
        // TODO simplify this
@@ -1927,7 +1938,7 @@ int nJoinAllowed(entity this, entity ignore)
                free_slots = min(maxclients - totalClients, autocvar_g_maxplayers - currentlyPlaying);
 
        static float join_prevent_msg_time = 0;
-       if(ignore && !free_slots && time > join_prevent_msg_time)
+       if(this && ignore && !free_slots && time > join_prevent_msg_time)
        {
                Send_Notification(NOTIF_ONE_ONLY, this, MSG_CENTER, CENTER_JOIN_PREVENT);
                join_prevent_msg_time = time + 3;
@@ -2000,12 +2011,13 @@ void PrintWelcomeMessage(entity this)
        }
 }
 
-bool spawnAllowed(entity this)
+bool joinAllowed(entity this)
 {
        if (this.version_mismatch) return false;
+       if (!nJoinAllowed(this, this)) return false;
        if (teamplay && lockteams) return false;
+       if (ShowTeamSelection(this)) return false;
        if (MUTATOR_CALLHOOK(ForbidSpawn, this)) return false;
-       if (!nJoinAllowed(this, this)) return false;
        return true;
 }
 
@@ -2018,7 +2030,7 @@ void ObserverThink(entity this)
        }
 
        if (this.flags & FL_JUMPRELEASED) {
-               if (PHYS_INPUT_BUTTON_JUMP(this) && spawnAllowed(this)) {
+               if (PHYS_INPUT_BUTTON_JUMP(this) && joinAllowed(this)) {
                        this.flags &= ~FL_JUMPRELEASED;
                        this.flags |= FL_SPAWNING;
                } else if(PHYS_INPUT_BUTTON_ATCK(this) && !this.version_mismatch) {
@@ -2036,7 +2048,7 @@ void ObserverThink(entity this)
                        if(this.flags & FL_SPAWNING)
                        {
                                this.flags &= ~FL_SPAWNING;
-                               LeaveSpectatorMode(this);
+                               Join(this);
                                return;
                        }
                }
@@ -2059,7 +2071,7 @@ void SpectatorThink(entity this)
        }
 
        if (this.flags & FL_JUMPRELEASED) {
-               if (PHYS_INPUT_BUTTON_JUMP(this) && spawnAllowed(this)) {
+               if (PHYS_INPUT_BUTTON_JUMP(this) && joinAllowed(this)) {
                        this.flags &= ~FL_JUMPRELEASED;
                        this.flags |= FL_SPAWNING;
                } else if(PHYS_INPUT_BUTTON_ATCK(this) || this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209)) {
@@ -2094,7 +2106,7 @@ void SpectatorThink(entity this)
                        if(this.flags & FL_SPAWNING)
                        {
                                this.flags &= ~FL_SPAWNING;
-                               LeaveSpectatorMode(this);
+                               Join(this);
                                return;
                        }
                }
@@ -2321,7 +2333,7 @@ void PlayerPreThink (entity this)
                                        {
                                                if ((this.respawn_flags & RESPAWN_FORCE) && !(this.respawn_time < this.respawn_time_max))
                                                        this.deadflag = DEAD_RESPAWNING;
-                                               else if (!button_pressed || (this.respawn_flags & RESPAWN_FORCE))
+                                               else if (!button_pressed || (time >= this.respawn_time_max && (this.respawn_flags & RESPAWN_FORCE)))
                                                        this.deadflag = DEAD_DEAD;
                                                break;
                                        }