From: Rudolf Polzer Date: Sun, 4 Sep 2011 17:10:41 +0000 (+0200) Subject: add a field for the current switching-to weapon. Finally fixes #648 X-Git-Tag: xonotic-v0.5.0~1 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b8ce8a17a89e18316825f8129defbf61d6cfc4ec;p=xonotic%2Fxonotic-data.pk3dir.git add a field for the current switching-to weapon. Finally fixes #648 --- diff --git a/qcsrc/client/View.qc b/qcsrc/client/View.qc index 443c6c7fa..ade5155c4 100644 --- a/qcsrc/client/View.qc +++ b/qcsrc/client/View.qc @@ -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); diff --git a/qcsrc/client/hud.qh b/qcsrc/client/hud.qh index ca9296799..120db4d0c 100644 --- a/qcsrc/client/hud.qh +++ b/qcsrc/client/hud.qh @@ -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; diff --git a/qcsrc/client/main.qh b/qcsrc/client/main.qh index c9f23b93b..9ea50c02b 100644 --- a/qcsrc/client/main.qh +++ b/qcsrc/client/main.qh @@ -117,6 +117,7 @@ float spectatorbutton_zoom; float button_attack2; float activeweapon; +float switchingweapon; float switchweapon; float current_viewzoom; float zoomin_effect; diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 67cf32a86..e13a1071b 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -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; diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 6ebee9fa1..f22b3b28a 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -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; diff --git a/qcsrc/server/cl_weapons.qc b/qcsrc/server/cl_weapons.qc index 658fe54d3..afe3088d4 100644 --- a/qcsrc/server/cl_weapons.qc +++ b/qcsrc/server/cl_weapons.qc @@ -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) { diff --git a/qcsrc/server/cl_weaponsystem.qc b/qcsrc/server/cl_weaponsystem.qc index d1db16d4c..0b73f3614 100644 --- a/qcsrc/server/cl_weaponsystem.qc +++ b/qcsrc/server/cl_weaponsystem.qc @@ -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; }; diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index a619f1ca2..6c57cf06d 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -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); diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index c03decbd2..b9552673e 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -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();