]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_client.qc
Weapons: store switchweapon as direct weapon reference
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_client.qc
index 47aff4a0b0c4dacad39a7263b960b63cc0984c06..fddaa09cbd422b87acb0258832f1f3bdcb89aaa8 100644 (file)
 #include "bot/navigation.qh"
 
 #include "../common/ent_cs.qh"
-#include "../common/vehicles/all.qh"
+#include "../common/state.qh"
+
 #include "../common/triggers/teleporters.qh"
 
+#include "../common/vehicles/all.qh"
+
 #include "weapons/hitplot.qh"
 #include "weapons/weaponsystem.qh"
 
@@ -186,7 +189,9 @@ putting a client as observer in the server
 */
 void FixPlayermodel(entity player);
 void PutObserverInServer()
-{SELFPARAM();
+{
+       SELFPARAM();
+       PlayerState_detach(this);
        entity  spot;
     self.hud = HUD_NORMAL;
 
@@ -438,6 +443,7 @@ void PutClientInServer()
        if (IS_OBSERVER(this)) {
                PutObserverInServer();
        } else if (IS_PLAYER(this)) {
+               PlayerState_attach(this);
                accuracy_resend(this);
 
                if (this.team < 0)
@@ -570,8 +576,6 @@ void PutClientInServer()
                this.bot_attack = true;
                this.monster_attack = true;
 
-               this.spider_slowness = 0;
-
                this.BUTTON_ATCK = this.BUTTON_JUMP = this.BUTTON_ATCK2 = false;
 
                if (this.killcount == FRAGS_SPECTATOR) {
@@ -619,7 +623,7 @@ void PutClientInServer()
                        remove(spot); // usefull for checking if there are spawnpoints, that let drop through the floor
                }
 
-               this.switchweapon = w_getbestweapon(this);
+               PS(this).m_switchweapon = w_getbestweapon(this);
                this.cnt = -1; // W_LastWeapon will not complain
                this.weapon = 0;
                this.weaponname = "";
@@ -632,6 +636,8 @@ void PutClientInServer()
        }
 }
 
+void ClientInit_misc();
+
 .float ebouncefactor, ebouncestop; // electro's values
 // TODO do we need all these fields, or should we stop autodetecting runtime
 // changes and just have a console command to update this?
@@ -640,7 +646,15 @@ bool ClientInit_SendEntity(entity this, entity to, int sf)
        WriteHeader(MSG_ENTITY, _ENT_CLIENT_INIT);
        return = true;
        msg_entity = to;
+       // MSG_INIT replacement
+       // TODO: make easier to use
        Registry_send_all();
+       W_PROP_reload(MSG_ONE, to);
+       ClientInit_misc();
+       MUTATOR_CALLHOOK(Ent_Init);
+}
+void ClientInit_misc()
+{
        int channel = MSG_ONE;
        WriteHeader(channel, ENT_CLIENT_INIT);
        WriteByte(channel, g_nexball_meter_period * 32);
@@ -658,19 +672,8 @@ bool ClientInit_SendEntity(entity this, entity to, int sf)
        else
                WriteString(channel, "");
        WriteByte(channel, self.count * 255.0); // g_balance_armor_blockpercent
-       WriteCoord(channel, self.bouncefactor); // g_balance_mortar_bouncefactor // WEAPONTODO
-       WriteCoord(channel, self.bouncestop); // g_balance_mortar_bouncestop
-       WriteCoord(channel, self.ebouncefactor); // g_balance_mortar_bouncefactor
-       WriteCoord(channel, self.ebouncestop); // g_balance_mortar_bouncestop
-       WriteByte(channel, WEP_CVAR(vortex, secondary)); // client has to know if it should zoom or not // WEAPONTODO
-       WriteByte(channel, WEP_CVAR(rifle, secondary)); // client has to know if it should zoom or not // WEAPONTODO
        WriteByte(channel, serverflags); // client has to know if it should zoom or not
-       WriteByte(channel, WEP_CVAR(minelayer, limit)); // minelayer max mines // WEAPONTODO
-       WriteByte(channel, WEP_CVAR_SEC(hagar, load_max)); // hagar max loadable rockets // WEAPONTODO
        WriteCoord(channel, autocvar_g_trueaim_minrange);
-       WriteByte(channel, WEP_CVAR(porto, secondary)); // WEAPONTODO
-
-       MUTATOR_CALLHOOK(Ent_Init);
 }
 
 void ClientInit_CheckUpdate()
@@ -681,26 +684,6 @@ void ClientInit_CheckUpdate()
                self.count = autocvar_g_balance_armor_blockpercent;
                self.SendFlags |= 1;
        }
-       if(self.bouncefactor != autocvar_g_balance_mortar_bouncefactor) // WEAPONTODO
-       {
-               self.bouncefactor = autocvar_g_balance_mortar_bouncefactor;
-               self.SendFlags |= 1;
-       }
-       if(self.bouncestop != autocvar_g_balance_mortar_bouncestop)
-       {
-               self.bouncestop = autocvar_g_balance_mortar_bouncestop;
-               self.SendFlags |= 1;
-       }
-       if(self.ebouncefactor != autocvar_g_balance_electro_secondary_bouncefactor)
-       {
-               self.ebouncefactor = autocvar_g_balance_electro_secondary_bouncefactor;
-               self.SendFlags |= 1;
-       }
-       if(self.ebouncestop != autocvar_g_balance_electro_secondary_bouncestop)
-       {
-               self.ebouncestop = autocvar_g_balance_electro_secondary_bouncestop;
-               self.SendFlags |= 1;
-       }
 }
 
 void ClientInit_Spawn()
@@ -965,6 +948,8 @@ void FixClientCvars(entity e)
                stuffcmd(e, "cl_cmd settemp cl_prydoncursor_notrace 0\n");
        if(autocvar_sv_gentle)
                stuffcmd(e, "cl_cmd settemp cl_gentle 1\n");
+
+       MUTATOR_CALLHOOK(FixClientCvars, e);
 }
 
 float PlayerInIDList(entity p, string idlist)
@@ -1018,7 +1003,9 @@ Called when a client connects to the server
 */
 void DecodeLevelParms ();
 void ClientConnect ()
-{SELFPARAM();
+{
+       SELFPARAM();
+       ClientState_attach(this);
        float t;
 
        if(IS_CLIENT(self))
@@ -1047,7 +1034,8 @@ void ClientConnect ()
                player_count = 0;
        }
 
-       if(IS_REAL_CLIENT(self)) { PlayerStats_PlayerBasic_CheckUpdate(self); }
+       // TODO: xonstat elo.txt support, until then just 404s
+       if(false && IS_REAL_CLIENT(self)) { PlayerStats_PlayerBasic_CheckUpdate(self); }
 
        PlayerScore_Attach(self);
        ClientData_Attach();
@@ -1199,7 +1187,7 @@ void ClientConnect ()
                        Send_Notification(NOTIF_ONE_ONLY, self, MSG_CENTER, CENTER_MOTD, getwelcomemessage());
                }
 
-               if(autocvar_g_bugrigs || (g_weaponarena_weapons == WEPSET(TUBA)))
+               if(g_weaponarena_weapons == WEPSET(TUBA))
                        stuffcmd(self, "cl_cmd settemp chase_active 1\n");
        }
 
@@ -1236,7 +1224,9 @@ Called when a client disconnects from the server
 .entity chatbubbleentity;
 void ReadyCount();
 void ClientDisconnect ()
-{SELFPARAM();
+{
+       SELFPARAM();
+       ClientState_detach(this);
        if(self.vehicle)
            vehicles_exit(VHEF_RELEASE);
 
@@ -1617,7 +1607,8 @@ void player_regen ()
        {
                if(self.vehicle)
                        vehicles_exit(VHEF_RELEASE);
-               self.event_damage(self, self, 1, DEATH_ROT.m_id, self.origin, '0 0 0');
+               if(self.event_damage)
+                       self.event_damage(self, self, 1, DEATH_ROT.m_id, self.origin, '0 0 0');
        }
 
        if (!(self.items & IT_UNLIMITED_WEAPON_AMMO))
@@ -1666,8 +1657,8 @@ spectate mode routines
 ======================
 */
 
-void SpectateCopy(entity spectatee)
-{SELFPARAM();
+void SpectateCopy(entity this, entity spectatee)
+{
        MUTATOR_CALLHOOK(SpectateCopy, spectatee, self);
        self.armortype = spectatee.armortype;
        self.armorvalue = spectatee.armorvalue;
@@ -1689,7 +1680,7 @@ void SpectateCopy(entity spectatee)
        self.invincible_finished = spectatee.invincible_finished;
        self.pressedkeys = spectatee.pressedkeys;
        self.weapons = spectatee.weapons;
-       self.switchweapon = spectatee.switchweapon;
+       PS(self).m_switchweapon = PS(spectatee).m_switchweapon;
        self.switchingweapon = spectatee.switchingweapon;
        self.weapon = spectatee.weapon;
        self.vortex_charge = spectatee.vortex_charge;
@@ -1752,7 +1743,7 @@ bool SpectateUpdate()
                return false;
        }
 
-       SpectateCopy(self.enemy);
+       SpectateCopy(this, this.enemy);
 
        return true;
 }
@@ -2014,7 +2005,7 @@ void ObserverThink()
 {SELFPARAM();
        if ( self.impulse )
        {
-               MinigameImpulse(self.impulse);
+               MinigameImpulse(self, self.impulse);
                self.impulse = 0;
        }
        float prefered_movetype;
@@ -2049,7 +2040,7 @@ void SpectatorThink()
 {SELFPARAM();
        if ( self.impulse )
        {
-               if(MinigameImpulse(self.impulse))
+               if(MinigameImpulse(self, self.impulse))
                        self.impulse = 0;
        }
        if (self.flags & FL_JUMPRELEASED) {
@@ -2324,22 +2315,6 @@ void PlayerPreThink ()
 
                if(frametime)
                {
-                       if(self.weapon == WEP_VORTEX.m_id && WEP_CVAR(vortex, charge))
-                       {
-                               self.weaponentity_glowmod_x = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
-                               self.weaponentity_glowmod_y = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
-                               self.weaponentity_glowmod_z = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_half * min(1, self.vortex_charge / WEP_CVAR(vortex, charge_animlimit));
-
-                               if(self.vortex_charge > WEP_CVAR(vortex, charge_animlimit))
-                               {
-                                       self.weaponentity_glowmod_x = self.weaponentity_glowmod.x + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
-                                       self.weaponentity_glowmod_y = self.weaponentity_glowmod.y + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_green_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
-                                       self.weaponentity_glowmod_z = self.weaponentity_glowmod.z + autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_blue_full * (self.vortex_charge - WEP_CVAR(vortex, charge_animlimit)) / (1 - WEP_CVAR(vortex, charge_animlimit));
-                               }
-                       }
-                       else
-                               self.weaponentity_glowmod = colormapPaletteColor(self.clientcolors & 0x0F, true) * 2;
-
                        player_powerups();
                }
 
@@ -2429,8 +2404,8 @@ void PlayerPreThink ()
                        if (!self.crouch)
                        {
                                self.crouch = true;
-                               self.view_ofs = self.stat_pl_crouch_view_ofs;
-                               setsize (self, self.stat_pl_crouch_min, self.stat_pl_crouch_max);
+                               self.view_ofs = STAT(PL_CROUCH_VIEW_OFS, self);
+                               setsize (self, STAT(PL_CROUCH_MIN, self), STAT(PL_CROUCH_MAX, self));
                                // setanim(self, self.anim_duck, false, true, true); // this anim is BROKEN anyway
                        }
                }
@@ -2438,12 +2413,12 @@ void PlayerPreThink ()
                {
                        if (self.crouch)
                        {
-                               tracebox(self.origin, self.stat_pl_min, self.stat_pl_max, self.origin, false, self);
+                               tracebox(self.origin, STAT(PL_MIN, self), STAT(PL_MAX, self), self.origin, false, self);
                                if (!trace_startsolid)
                                {
                                        self.crouch = false;
-                                       self.view_ofs = self.stat_pl_view_ofs;
-                                       setsize (self, self.stat_pl_min, self.stat_pl_max);
+                                       self.view_ofs = STAT(PL_VIEW_OFS, self);
+                                       setsize (self, STAT(PL_MIN, self), STAT(PL_MAX, self));
                                }
                        }
                }
@@ -2509,6 +2484,8 @@ void PlayerPreThink ()
        if(self.spectatee_status != oldspectatee_status)
        {
                ClientData_Touch(self);
+               if(g_race || g_cts)
+                       race_InitSpectator();
        }
 
        if(self.teamkill_soundtime)
@@ -2516,21 +2493,18 @@ void PlayerPreThink ()
        {
                self.teamkill_soundtime = 0;
 
-               setself(self.teamkill_soundsource);
-               entity oldpusher = self.pusher;
-               self.pusher = this;
-
-               PlayerSound(playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
-
-               self.pusher = oldpusher;
-               setself(this);
+               entity e = self.teamkill_soundsource;
+               entity oldpusher = e.pusher;
+               e.pusher = this;
+               PlayerSound(e, playersound_teamshoot, CH_VOICE, VOICETYPE_LASTATTACKER_ONLY);
+               e.pusher = oldpusher;
        }
 
        if(self.taunt_soundtime)
        if(time > self.taunt_soundtime)
        {
                self.taunt_soundtime = 0;
-               PlayerSound(playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
+               PlayerSound(self, playersound_taunt, CH_VOICE, VOICETYPE_AUTOTAUNT);
        }
 
        target_voicescript_next(self);
@@ -2541,6 +2515,28 @@ void PlayerPreThink ()
                self.clip_load = self.clip_size = 0;
 }
 
+void DrownPlayer(entity this)
+{
+       if(this.deadflag != DEAD_NO)
+               return;
+
+       if (this.waterlevel != WATERLEVEL_SUBMERGED)
+       {
+               if(this.air_finished < time)
+                       PlayerSound(this, playersound_gasp, CH_PLAYER, VOICETYPE_PLAYERSOUND);
+               this.air_finished = time + autocvar_g_balance_contents_drowndelay;
+               this.dmg = 2;
+       }
+       else if (this.air_finished < time)
+       {       // drown!
+               if (this.pain_finished < time)
+               {
+                       Damage (this, world, world, autocvar_g_balance_contents_playerdamage_drowning * autocvar_g_balance_contents_damagerate, DEATH_DROWN.m_id, this.origin, '0 0 0');
+                       this.pain_finished = time + 0.5;
+               }
+       }
+}
+
 /*
 =============
 PlayerPostThink
@@ -2592,10 +2588,11 @@ void PlayerPostThink ()
        //CheckPlayerJump();
 
        if(IS_PLAYER(self)) {
+               DrownPlayer(self);
                CheckRules_Player();
                UpdateChatBubble();
                if (self.impulse)
-                       ImpulseCommands();
+                       ImpulseCommands(self);
                if (intermission_running)
                        return;         // intermission or finale
                GetPressedKeys();