]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
add a field for the current switching-to weapon. Finally fixes #648
authorRudolf Polzer <divverent@xonotic.org>
Sun, 4 Sep 2011 17:10:41 +0000 (19:10 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Sun, 4 Sep 2011 17:14:16 +0000 (19:14 +0200)
qcsrc/client/View.qc
qcsrc/client/hud.qh
qcsrc/client/main.qh
qcsrc/common/constants.qh
qcsrc/server/cl_client.qc
qcsrc/server/cl_weapons.qc
qcsrc/server/cl_weaponsystem.qc
qcsrc/server/defs.qh
qcsrc/server/g_world.qc

index 443c6c7fa6f4be07459ce5b83144579a8ef85a1d..ade5155c46ff2e7c26e50070c05e31b269982085 100644 (file)
@@ -544,8 +544,16 @@ void CSQC_UpdateView(float w, float h)
        }
 
        ColorTranslateMode = autocvar_cl_stripcolorcodes;
+
+       // next WANTED weapon (for HUD)
        switchweapon = getstati(STAT_SWITCHWEAPON);
+
+       // currently switching-to weapon (for crosshair)
+       switchingweapon = getstati(STAT_SWITCHINGWEAPON);
+
+       // actually active weapon (for zoom)
        activeweapon = getstati(STAT_ACTIVEWEAPON);
+
        f = (serverflags & SERVERFLAG_TEAMPLAY);
        if(f != teamplay)
        {
@@ -553,9 +561,12 @@ void CSQC_UpdateView(float w, float h)
                HUD_InitScores();
        }
 
-       if(last_weapon != activeweapon) {
+       if(last_switchweapon != switchweapon) {
                weapontime = time;
-               last_weapon = activeweapon;
+               last_switchweapon = switchweapon;
+       }
+       if(last_activeweapon != activeweapon) {
+               last_activeweapon = activeweapon;
 
                e = get_weaponinfo(activeweapon);
                if(e.netname != "")
@@ -1031,7 +1042,7 @@ void CSQC_UpdateView(float w, float h)
                        float wcross_scale, wcross_blur;
 
                        if (autocvar_crosshair_per_weapon || autocvar_crosshair_color_per_weapon) {
-                               e = get_weaponinfo(activeweapon);
+                               e = get_weaponinfo(switchingweapon);
                                if (e && e.netname != "")
                                {
                                        wcross_wep = e.netname;
@@ -1160,7 +1171,7 @@ void CSQC_UpdateView(float w, float h)
 
                        f = autocvar_crosshair_effect_speed;
                        if(f < 0)
-                               f *= -1 * g_weaponswitchdelay; // anim starts when weapon has been lowered and new weapon comes up
+                               f *= -2 * g_weaponswitchdelay; // anim starts when weapon has been lowered and new weapon comes up
                        if(wcross_scale != wcross_scale_goal_prev || wcross_alpha != wcross_alpha_goal_prev || wcross_color != wcross_color_goal_prev)
                        {
                                wcross_changedonetime = time + f;
@@ -1283,6 +1294,14 @@ void CSQC_UpdateView(float w, float h)
                                                        ring_image = "gfx/crosshair_ring.tga";
                                        }
 
+                                       // if in weapon switch animation, fade ring out/in
+                                       if(g_weaponswitchdelay > 0)
+                                       {
+                                               f = (time - wcross_name_changestarttime) / g_weaponswitchdelay;
+                                               if(f > 0 && f < 2)
+                                                       ring_alpha *= fabs(1 - f);
+                                       }
+
                                        if (autocvar_crosshair_ring_inner && ring_inner_value) // lets draw a ring inside a ring so you can ring while you ring
                                                DrawCircleClippedPic(wcross_origin, wcross_size_x * ring_scale, ring_inner_image, ring_inner_value, ring_inner_rgb, wcross_alpha * ring_inner_alpha, DRAWFLAG_ADDITIVE);
 
index ca9296799e8ecb6134645387c1e66fcaf1267859..120db4d0c223896bf209771a52fb3eed59fa65dd 100644 (file)
@@ -28,7 +28,8 @@ float complain_weapon_time;
 float ps_primary, ps_secondary;
 float ts_primary, ts_secondary;
 
-float last_weapon;
+float last_switchweapon;
+float last_activeweapon;
 float weapontime;
 float weaponprevtime;
 
index c9f23b93bfdee87f9c35575078d2e46c6e132b6d..9ea50c02b33d285aabce80a91a0504e470b2977f 100644 (file)
@@ -117,6 +117,7 @@ float spectatorbutton_zoom;
 float button_attack2;
 
 float activeweapon;
+float switchingweapon;
 float switchweapon;
 float current_viewzoom;
 float zoomin_effect;
index 67cf32a86ad0344d9ab683381034aa0ea1200abc..e13a1071b9be470ba2f4d875cf8a6307b52fce35 100644 (file)
@@ -323,6 +323,7 @@ const float STAT_HIT_TIME = 54;
 const float STAT_TYPEHIT_TIME = 55;
 const float STAT_LAYED_MINES = 56;
 const float STAT_HAGAR_LOAD = 57;
+const float STAT_SWITCHINGWEAPON = 58;
 
 // see DP source, quakedef.h
 const float STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW = 222;
index 6ebee9fa1de67cfcdbd00e7d58ea429521593dc0..f22b3b28a34f0416024a6c9a6580334506ba3c63 100644 (file)
@@ -705,6 +705,7 @@ void PutObserverInServer (void)
        self.model = "";
        self.modelindex = 0;
        self.weapon = 0;
+       self.switchingweapon = 0;
        self.weaponmodel = "";
        self.weaponentity = world;
        self.exteriorweaponentity = world;
@@ -1110,6 +1111,7 @@ void PutClientInServer (void)
                self.switchweapon = w_getbestweapon(self);
                self.cnt = self.switchweapon;
                self.weapon = 0;
+               self.switchingweapon = 0;
 
                if(!self.alivetime)
                        self.alivetime = time;
@@ -2306,6 +2308,7 @@ void SpectateCopy(entity spectatee) {
        self.pressedkeys = spectatee.pressedkeys;
        self.weapons = spectatee.weapons;
        self.switchweapon = spectatee.switchweapon;
+       self.switchingweapon = spectatee.switchingweapon;
        self.weapon = spectatee.weapon;
        self.nex_charge = spectatee.nex_charge;
        self.nex_chargepool_ammo = spectatee.nex_chargepool_ammo;
index 658fe54d32901b2b689df87a6424ad47c05d9288..afe3088d431cd40507f61ce543442da20f80fa8c 100644 (file)
@@ -330,6 +330,7 @@ void W_WeaponFrame()
        if(!self.switchweapon)
        {
                self.weapon = 0;
+               self.switchingweapon = 0;
                self.weaponentity.state = WS_CLEAR;
                self.weaponname = "";
                self.items &~= IT_AMMO;
@@ -346,6 +347,9 @@ void W_WeaponFrame()
        {
                if (self.weaponentity.state == WS_CLEAR)
                {
+                       // end switching!
+                       self.switchingweapon = self.switchweapon;
+
                        //setanim(self, self.anim_draw, FALSE, TRUE, TRUE);
                        self.weaponentity.state = WS_RAISE;
                        weapon_action(self.switchweapon, WR_SETUP);
@@ -366,8 +370,16 @@ void W_WeaponFrame()
                        weapon_thinkf(WFRAME_IDLE, autocvar_g_balance_weaponswitchdelay, w_ready);
                        weapon_boblayer1(PLAYER_WEAPONSELECTION_SPEED, '0 0 0');
                }
+               else if (self.weaponentity.state == WS_DROP)
+               {
+                       // in dropping phase we can switch at any time
+                       self.switchingweapon = self.switchweapon;
+               }
                else if (self.weaponentity.state == WS_READY)
                {
+                       // start switching!
+                       self.switchingweapon = self.switchweapon;
+
 #ifndef INDEPENDENT_ATTACK_FINISHED
                        if(ATTACK_FINISHED(self) <= time + self.weapon_frametime * 0.5)
                        {
index d1db16d4ca462feaf5c5796cff015b372b0dd190..0b73f36144994867b931c422980d4b348e28348f 100644 (file)
@@ -1003,7 +1003,10 @@ float client_hasweapon(entity cl, float wpn, float andammo, float complain)
 void w_clear()
 {
        if (self.weapon != -1)
+       {
                self.weapon = 0;
+               self.switchingweapon = 0;
+       }
        if (self.weaponentity)
        {
                self.weaponentity.state = WS_CLEAR;
@@ -1029,6 +1032,7 @@ void weapon_setup(float windex)
 
        // the two weapon entities will notice this has changed and update their models
        self.weapon = windex;
+       self.switchingweapon = windex; // to make sure
        self.weaponname = e.mdl;
        self.bulletcounter = 0;
 };
index a619f1ca20465bd58e095fece58b376c39e5a93e..6c57cf06dc04e82ba8cb5fb1876c57b98a2206bf 100644 (file)
@@ -202,7 +202,11 @@ void setanim(entity e, vector anim, float looping, float override, float restart
 .entity weaponentity;
 .entity exteriorweaponentity;
 .vector weaponentity_glowmod;
-.float switchweapon;
+
+//.float weapon; // current weapon
+.float switchweapon; // weapon requested to switch to
+.float switchingweapon; // weapon currently being switched to (is copied from switchweapon once switch is possible)
+
 .float autoswitch;
 float weapon_action(float wpn, float wrequest);
 float client_hasweapon(entity cl, float wpn, float andammo, float complain);
index c03decbd2e56684f396f86d56d300f3bc7195198..b9552673e889107ad89f7ec5eea76f9124427d2c 100644 (file)
@@ -809,6 +809,7 @@ void spawnfunc_worldspawn (void)
 
        addstat(STAT_WEAPONS, AS_INT, weapons);
        addstat(STAT_SWITCHWEAPON, AS_INT, switchweapon);
+       addstat(STAT_SWITCHINGWEAPON, AS_INT, switchingweapon);
        addstat(STAT_GAMESTARTTIME, AS_FLOAT, stat_game_starttime);
        addstat(STAT_ALLOW_OLDNEXBEAM, AS_INT, stat_allow_oldnexbeam);
        Nagger_Init();