From: Mario Date: Thu, 29 Sep 2016 12:36:00 +0000 (+1000) Subject: Fix animations when weapon states do not match X-Git-Tag: xonotic-v0.8.2~326^2~86 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=81e79f1ce3aa18a1353b845f12e940da475720ab;p=xonotic%2Fxonotic-data.pk3dir.git Fix animations when weapon states do not match --- diff --git a/qcsrc/client/view.qc b/qcsrc/client/view.qc index 36c0d1bc8..27921b182 100644 --- a/qcsrc/client/view.qc +++ b/qcsrc/client/view.qc @@ -281,6 +281,8 @@ void viewmodel_animate(entity this) .float weapon_eta_last; .float weapon_switchdelay; +.string name_last; + void viewmodel_draw(entity this) { if(!this.activeweapon || !autocvar_r_drawviewmodel) @@ -294,7 +296,7 @@ void viewmodel_draw(entity this) wasinvehicle = invehicle; Weapon wep = this.activeweapon; int c = entcs_GetClientColors(current_player); - vector g = weaponentity_glowmod(wep, NULL, c); + vector g = weaponentity_glowmod(wep, NULL, c, this); entity me = CSQCModel_server2csqc(player_localentnum - 1); int fx = ((me.csqcmodel_effects & EFMASK_CHEAP) | EF_NODEPTHTEST) @@ -309,12 +311,11 @@ void viewmodel_draw(entity this) CSQCModel_Effects_Apply(e); } { - static string name_last; string name = wep.mdl; - bool swap = name != name_last; + bool swap = name != this.name_last; // if (swap) { - name_last = name; + this.name_last = name; CL_WeaponEntity_SetModel(this, name, swap); this.viewmodel_origin = this.origin; this.viewmodel_angles = this.angles; diff --git a/qcsrc/common/mutators/mutator/nix/sv_nix.qc b/qcsrc/common/mutators/mutator/nix/sv_nix.qc index 9ea34f289..01b8a50c5 100644 --- a/qcsrc/common/mutators/mutator/nix/sv_nix.qc +++ b/qcsrc/common/mutators/mutator/nix/sv_nix.qc @@ -172,7 +172,11 @@ void NIX_GiveCurrentWeapon(entity this) { if(WEP_CVAR_SEC(vortex, chargepool)) this.vortex_chargepool_ammo = 1; - this.vortex_charge = WEP_CVAR(vortex, charge_start); + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + this.(weaponentity).vortex_charge = WEP_CVAR(vortex, charge_start); + } } // set last change info diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 12e26ac4e..071ac4c56 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -326,10 +326,10 @@ STATIC_INIT(register_weapons_done) .entity weaponchild; .entity exteriorweaponentity; -vector weaponentity_glowmod(Weapon wep, entity actor, int c) +vector weaponentity_glowmod(Weapon wep, entity actor, int c, entity wepent) { vector g; - if (!(g = wep.wr_glow(wep, actor))) g = colormapPaletteColor(c & 0x0F, true) * 2; + if (!(g = wep.wr_glow(wep, actor, wepent))) g = colormapPaletteColor(c & 0x0F, true) * 2; return g; } diff --git a/qcsrc/common/weapons/weapon.qh b/qcsrc/common/weapons/weapon.qh index d16d733d5..fc1167218 100644 --- a/qcsrc/common/weapons/weapon.qh +++ b/qcsrc/common/weapons/weapon.qh @@ -118,7 +118,7 @@ CLASS(Weapon, Object) return false; } /** (CLIENT) weapon specific glow */ - METHOD(Weapon, wr_glow, vector(Weapon this, entity actor)) { return '0 0 0'; } + METHOD(Weapon, wr_glow, vector(Weapon this, entity actor, entity wepent)) { return '0 0 0'; } /** (SERVER) the weapon is dropped */ METHOD(Weapon, wr_drop, void(Weapon this, entity actor)) {} /** (SERVER) a weapon is picked up */ diff --git a/qcsrc/common/weapons/weapon/vortex.qc b/qcsrc/common/weapons/weapon/vortex.qc index 660c7549f..351f8fc27 100644 --- a/qcsrc/common/weapons/weapon/vortex.qc +++ b/qcsrc/common/weapons/weapon/vortex.qc @@ -78,10 +78,10 @@ float autocvar_g_weapon_charge_colormod_blue_half; float autocvar_g_weapon_charge_colormod_green_half; float autocvar_g_weapon_charge_colormod_hdrmultiplier; -METHOD(Vortex, wr_glow, vector(Vortex this, entity actor)) +METHOD(Vortex, wr_glow, vector(Vortex this, entity actor, entity wepent)) { if (!STAT(WEP_CVAR_vortex_charge, actor)) return '0 0 0'; - float charge = STAT(VORTEX_CHARGE, actor); + float charge = wepent.vortex_charge; float animlimit = STAT(WEP_CVAR_vortex_charge_animlimit, actor); vector g; g.x = autocvar_g_weapon_charge_colormod_hdrmultiplier * autocvar_g_weapon_charge_colormod_red_half * min(1, charge / animlimit); @@ -155,7 +155,7 @@ MUTATOR_HOOKFUNCTION(vortex_charge, GetPressedKeys) xyspeed = min(xyspeed, WEP_CVAR(vortex, charge_maxspeed)); float f = (xyspeed - WEP_CVAR(vortex, charge_minspeed)) / (WEP_CVAR(vortex, charge_maxspeed) - WEP_CVAR(vortex, charge_minspeed)); // add the extra charge - player.vortex_charge = min(1, player.vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH); + player.(weaponentity).vortex_charge = min(1, player.(weaponentity).vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH); } } @@ -176,8 +176,8 @@ void W_Vortex_Attack(Weapon thiswep, entity actor, .entity weaponentity, float i if(WEP_CVAR(vortex, charge)) { - charge = WEP_CVAR(vortex, charge_mindmg) / mydmg + (1 - WEP_CVAR(vortex, charge_mindmg) / mydmg) * actor.vortex_charge; - actor.vortex_charge *= WEP_CVAR(vortex, charge_shot_multiplier); // do this AFTER setting mydmg/myforce + charge = WEP_CVAR(vortex, charge_mindmg) / mydmg + (1 - WEP_CVAR(vortex, charge_mindmg) / mydmg) * actor.(weaponentity).vortex_charge; + actor.(weaponentity).vortex_charge *= WEP_CVAR(vortex, charge_shot_multiplier); // do this AFTER setting mydmg/myforce // O RLY? -- divVerent // YA RLY -- FruitieX } @@ -226,17 +226,23 @@ METHOD(Vortex, wr_aim, void(entity thiswep, entity actor)) } METHOD(Vortex, wr_think, void(entity thiswep, entity actor, .entity weaponentity, int fire)) { - if(WEP_CVAR(vortex, charge) && actor.vortex_charge < WEP_CVAR(vortex, charge_limit)) - actor.vortex_charge = min(1, actor.vortex_charge + WEP_CVAR(vortex, charge_rate) * frametime / W_TICSPERFRAME); + if(WEP_CVAR(vortex, charge) && actor.(weaponentity).vortex_charge < WEP_CVAR(vortex, charge_limit)) + actor.(weaponentity).vortex_charge = min(1, actor.(weaponentity).vortex_charge + WEP_CVAR(vortex, charge_rate) * frametime / W_TICSPERFRAME); + + if(weaponslot(weaponentity) == 0) + actor.vortex_charge = actor.(weaponentity).vortex_charge; if(WEP_CVAR_SEC(vortex, chargepool)) - if(actor.vortex_chargepool_ammo < 1) + if(actor.(weaponentity).vortex_chargepool_ammo < 1) { if(actor.vortex_chargepool_pauseregen_finished < time) - actor.vortex_chargepool_ammo = min(1, actor.vortex_chargepool_ammo + WEP_CVAR_SEC(vortex, chargepool_regen) * frametime / W_TICSPERFRAME); + actor.(weaponentity).vortex_chargepool_ammo = min(1, actor.(weaponentity).vortex_chargepool_ammo + WEP_CVAR_SEC(vortex, chargepool_regen) * frametime / W_TICSPERFRAME); actor.pauseregen_finished = max(actor.pauseregen_finished, time + WEP_CVAR_SEC(vortex, chargepool_pause_regen)); } + if(weaponslot(weaponentity) == 0) + actor.vortex_chargepool_ammo = actor.(weaponentity).vortex_chargepool_ammo; + if(autocvar_g_balance_vortex_reload_ammo && actor.clip_load < min(WEP_CVAR_PRI(vortex, ammo), WEP_CVAR_SEC(vortex, ammo))) { // forced reload thiswep.wr_reload(thiswep, actor, weaponentity); } else @@ -253,10 +259,10 @@ METHOD(Vortex, wr_think, void(entity thiswep, entity actor, .entity weaponentity { if(WEP_CVAR(vortex, charge)) { - actor.vortex_charge_rottime = time + WEP_CVAR(vortex, charge_rot_pause); + actor.(weaponentity).vortex_charge_rottime = time + WEP_CVAR(vortex, charge_rot_pause); float dt = frametime / W_TICSPERFRAME; - if(actor.vortex_charge < 1) + if(actor.(weaponentity).vortex_charge < 1) { if(WEP_CVAR_SEC(vortex, chargepool)) { @@ -265,12 +271,12 @@ METHOD(Vortex, wr_think, void(entity thiswep, entity actor, .entity weaponentity // always deplete if secondary is held actor.vortex_chargepool_ammo = max(0, actor.vortex_chargepool_ammo - WEP_CVAR_SEC(vortex, ammo) * dt); - dt = min(dt, (1 - actor.vortex_charge) / WEP_CVAR(vortex, charge_rate)); + dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate)); actor.vortex_chargepool_pauseregen_finished = time + WEP_CVAR_SEC(vortex, chargepool_pause_regen); dt = min(dt, actor.vortex_chargepool_ammo); dt = max(0, dt); - actor.vortex_charge += dt * WEP_CVAR(vortex, charge_rate); + actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate); } } @@ -278,7 +284,7 @@ METHOD(Vortex, wr_think, void(entity thiswep, entity actor, .entity weaponentity { if(fire & 2) // only eat ammo when the button is pressed { - dt = min(dt, (1 - actor.vortex_charge) / WEP_CVAR(vortex, charge_rate)); + dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate)); if(!(actor.items & IT_UNLIMITED_WEAPON_AMMO)) { // if this weapon is reloadable, decrease its load. Else decrease the player's ammo @@ -302,14 +308,14 @@ METHOD(Vortex, wr_think, void(entity thiswep, entity actor, .entity weaponentity } } } - actor.vortex_charge += dt * WEP_CVAR(vortex, charge_rate); + actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate); } } else { - dt = min(dt, (1 - actor.vortex_charge) / WEP_CVAR(vortex, charge_rate)); - actor.vortex_charge += dt * WEP_CVAR(vortex, charge_rate); + dt = min(dt, (1 - actor.(weaponentity).vortex_charge) / WEP_CVAR(vortex, charge_rate)); + actor.(weaponentity).vortex_charge += dt * WEP_CVAR(vortex, charge_rate); } } } @@ -355,6 +361,14 @@ METHOD(Vortex, wr_resetplayer, void(entity thiswep, entity actor)) actor.vortex_chargepool_ammo = 1; } actor.vortex_charge = WEP_CVAR(vortex, charge_start); + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + actor.(weaponentity).vortex_charge = WEP_CVAR(vortex, charge_start); + + if (WEP_CVAR_SEC(vortex, chargepool)) + actor.(weaponentity).vortex_chargepool_ammo = 1; + } } actor.vortex_lasthit = 0; } diff --git a/qcsrc/common/wepent.qc b/qcsrc/common/wepent.qc index cfd846d0c..0d18908c4 100644 --- a/qcsrc/common/wepent.qc +++ b/qcsrc/common/wepent.qc @@ -16,6 +16,7 @@ MACRO_END .Weapon w_m_weapon; //.float w_weapon_nextthink; .float w_m_alpha; +.float w_vortex_charge; // #define PROP(public, fld, set, sv, cl) #define WEPENT_NETPROPS(PROP) PROP(false, sv_entnum, WEPENT_SET_NORMAL, {}, {}) /* sentinel */ \ @@ -34,6 +35,10 @@ MACRO_END PROP(false, m_alpha, WEPENT_SET_NORMAL, \ { WriteByte(chan, this.m_alpha * 16); }, \ { (viewmodels[this.m_wepent_slot]).alpha = ReadByte() / 16; }) \ + \ + PROP(false, vortex_charge, WEPENT_SET_NORMAL, \ + { WriteByte(chan, this.vortex_charge * 16); }, \ + { (viewmodels[this.m_wepent_slot]).vortex_charge = ReadByte() / 16; }) \ \ /**/ diff --git a/qcsrc/common/wepent.qh b/qcsrc/common/wepent.qh index 77296018d..0064b1f61 100644 --- a/qcsrc/common/wepent.qh +++ b/qcsrc/common/wepent.qh @@ -3,6 +3,8 @@ REGISTER_NET_LINKED(ENT_CLIENT_WEPENT) REGISTER_NET_TEMP(CLIENT_WEPENT) +.float vortex_charge; + #ifdef SVQC bool wepent_send(entity this, entity to, int sf); diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index d6805263c..2023cb0e6 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -2445,8 +2445,12 @@ void PlayerPreThink (entity this) // WEAPONTODO: Add a weapon request for this // rot vortex charge to the charge limit - if (WEP_CVAR(vortex, charge_rot_rate) && this.vortex_charge > WEP_CVAR(vortex, charge_limit) && this.vortex_charge_rottime < time) - this.vortex_charge = bound(WEP_CVAR(vortex, charge_limit), this.vortex_charge - WEP_CVAR(vortex, charge_rot_rate) * frametime / W_TICSPERFRAME, 1); + for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot) + { + .entity weaponentity = weaponentities[slot]; + if (WEP_CVAR(vortex, charge_rot_rate) && this.(weaponentity).vortex_charge > WEP_CVAR(vortex, charge_limit) && this.(weaponentity).vortex_charge_rottime < time) + this.(weaponentity).vortex_charge = bound(WEP_CVAR(vortex, charge_limit), this.(weaponentity).vortex_charge - WEP_CVAR(vortex, charge_rot_rate) * frametime / W_TICSPERFRAME, 1); + } if (frametime) player_anim(this); diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index 47531ecbb..f3a72412b 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -45,7 +45,7 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto wep.owner = wep.enemy = own; wep.flags |= FL_TOSSED; wep.colormap = own.colormap; - wep.glowmod = weaponentity_glowmod(info, own, own.clientcolors); + wep.glowmod = weaponentity_glowmod(info, own, own.clientcolors, own.(weaponentity)); W_DropEvent(wr_drop,own,wpn,wep); diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index 0dffe0289..f5330d08e 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -158,7 +158,7 @@ void CL_ExteriorWeaponentity_Think(entity this) else this.alpha = 1; Weapon wep = this.owner.(weaponentity).m_weapon; - if (wep) this.glowmod = weaponentity_glowmod(wep, this.owner, this.owner.clientcolors); + if (wep) this.glowmod = weaponentity_glowmod(wep, this.owner, this.owner.clientcolors, this.owner.(weaponentity)); this.colormap = this.owner.colormap; CSQCMODEL_AUTOUPDATE(this);