From 123a2aeb0c53addf29611e4e2cb27d4dae8ad968 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 29 Sep 2016 12:48:50 +1000 Subject: [PATCH] Send alpha as part of weapon state, rather than when firing --- qcsrc/common/weapons/all.qc | 2 -- qcsrc/common/weapons/all.qh | 6 ++++++ qcsrc/common/weapons/weapon/arc.qc | 16 +++++++++++++--- qcsrc/common/weapons/weapon/fireball.qc | 2 +- qcsrc/common/weapons/weapon/seeker.qc | 2 +- qcsrc/common/wepent.qc | 5 +++++ qcsrc/server/weapons/weaponsystem.qc | 24 ++++++++++++------------ 7 files changed, 38 insertions(+), 19 deletions(-) diff --git a/qcsrc/common/weapons/all.qc b/qcsrc/common/weapons/all.qc index 1faa1a045..99b232730 100644 --- a/qcsrc/common/weapons/all.qc +++ b/qcsrc/common/weapons/all.qc @@ -563,7 +563,6 @@ NET_HANDLE(wframe, bool isNew) anim_set(wepent, a, !restartanim, restartanim, restartanim); wepent.state = ReadByte(); wepent.weapon_nextthink = ReadFloat(); - wepent.alpha = ReadByte() / 255; switch (wepent.state) { case WS_RAISE: @@ -594,7 +593,6 @@ void wframe_send(entity actor, entity weaponentity, vector a, bool restartanim) WriteByte(channel, restartanim); WriteByte(channel, weaponentity.state); WriteFloat(channel, weaponentity.weapon_nextthink); - WriteByte(channel, weaponentity.m_alpha * 255); } #endif diff --git a/qcsrc/common/weapons/all.qh b/qcsrc/common/weapons/all.qh index 9570e8c56..90cbe28db 100644 --- a/qcsrc/common/weapons/all.qh +++ b/qcsrc/common/weapons/all.qh @@ -333,6 +333,12 @@ vector weaponentity_glowmod(Weapon wep, entity actor, int c) return g; } +#ifdef SVQC +.entity gunaligns[5]; +#else +entity gunaligns[5]; +#endif + //.int weapon; // current weapon .string weaponname; // name of .weapon diff --git a/qcsrc/common/weapons/weapon/arc.qc b/qcsrc/common/weapons/weapon/arc.qc index 0a2754f06..6cee61981 100644 --- a/qcsrc/common/weapons/weapon/arc.qc +++ b/qcsrc/common/weapons/weapon/arc.qc @@ -159,6 +159,7 @@ bool W_Arc_Beam_Send(entity this, entity to, int sf) if(drawlocal) { sf &= ~ARC_SF_LOCALMASK; } WriteByte(MSG_ENTITY, sf); + WriteByte(MSG_ENTITY, weaponslot(this.weaponentity_fld)); if(sf & ARC_SF_SETTINGS) // settings information { @@ -674,7 +675,7 @@ void W_Arc_Beam_Think(entity this) this.beam_type = new_beam_type; } - this.owner.beam_prev = time; + this.owner.(weaponentity).beam_prev = time; this.nextthink = time; } @@ -682,7 +683,7 @@ void W_Arc_Beam(float burst, entity actor, .entity weaponentity) { // only play fire sound if 1 sec has passed since player let go the fire button - if(time - actor.beam_prev > 1) + if(time - actor.(weaponentity).beam_prev > 1) sound(actor, CH_WEAPON_A, SND_ARC_FIRE, VOL_BASE, ATTN_NORM); entity beam = actor.(weaponentity).arc_beam = new(W_Arc_Beam); @@ -1297,13 +1298,22 @@ void Remove_ArcBeam(entity this) NET_HANDLE(ENT_CLIENT_ARC_BEAM, bool isnew) { int sf = ReadByte(); + int slot = ReadByte(); entity flash; if(isnew) { int gunalign = W_GunAlign(NULL, STAT(GUNALIGN)); - this.beam_shotorigin = arc_shotorigin[gunalign]; + this.beam_shotorigin = arc_shotorigin[gunalign]; // quick + for(int j = 1; j < 5; ++j) + { + if(gunaligns[j] == viewmodels[slot]) + { + this.beam_shotorigin = arc_shotorigin[j - 1]; // accurate + break; + } + } // set other main attributes of the beam this.draw = Draw_ArcBeam; diff --git a/qcsrc/common/weapons/weapon/fireball.qc b/qcsrc/common/weapons/weapon/fireball.qc index c2b93747c..7ba71aaa7 100644 --- a/qcsrc/common/weapons/weapon/fireball.qc +++ b/qcsrc/common/weapons/weapon/fireball.qc @@ -314,7 +314,7 @@ void W_Fireball_Attack2(entity actor, .entity weaponentity) vector f_diff; float c; - c = actor.bulletcounter % 4; + c = actor.(weaponentity).bulletcounter % 4; switch(c) { case 0: diff --git a/qcsrc/common/weapons/weapon/seeker.qc b/qcsrc/common/weapons/weapon/seeker.qc index fb2236232..ca5ecf4dd 100644 --- a/qcsrc/common/weapons/weapon/seeker.qc +++ b/qcsrc/common/weapons/weapon/seeker.qc @@ -337,7 +337,7 @@ void W_Seeker_Fire_Flac(Weapon thiswep, entity actor, .entity weaponentity) W_DecreaseAmmo(thiswep, actor, WEP_CVAR(seeker, flac_ammo), weaponentity); - c = actor.bulletcounter % 4; + c = actor.(weaponentity).bulletcounter % 4; switch(c) { case 0: diff --git a/qcsrc/common/wepent.qc b/qcsrc/common/wepent.qc index 036867888..cfd846d0c 100644 --- a/qcsrc/common/wepent.qc +++ b/qcsrc/common/wepent.qc @@ -15,6 +15,7 @@ MACRO_END .Weapon w_m_switchingweapon; .Weapon w_m_weapon; //.float w_weapon_nextthink; +.float w_m_alpha; // #define PROP(public, fld, set, sv, cl) #define WEPENT_NETPROPS(PROP) PROP(false, sv_entnum, WEPENT_SET_NORMAL, {}, {}) /* sentinel */ \ @@ -29,6 +30,10 @@ MACRO_END PROP(false, m_weapon, WEPENT_SET_NORMAL, \ { WriteByte(chan, this.m_weapon.m_id); }, \ { (viewmodels[this.m_wepent_slot]).activeweapon = Weapons_from(ReadByte()); }) \ + \ + PROP(false, m_alpha, WEPENT_SET_NORMAL, \ + { WriteByte(chan, this.m_alpha * 16); }, \ + { (viewmodels[this.m_wepent_slot]).alpha = ReadByte() / 16; }) \ \ /**/ diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index 3b8047efa..458383500 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -290,7 +290,7 @@ bool weapon_prepareattack_check(Weapon thiswep, entity actor, .entity weaponenti { int slot = weaponslot(weaponentity); // don't fire if previous attack is not finished - if (ATTACK_FINISHED(actor, slot) > time + actor.weapon_frametime * 0.5) return false; + if (ATTACK_FINISHED(actor, slot) > time + actor.(weaponentity).weapon_frametime * 0.5) return false; entity this = actor.(weaponentity); // don't fire while changing weapon if (this.state != WS_READY) return false; @@ -310,14 +310,14 @@ void weapon_prepareattack_do(entity actor, .entity weaponentity, bool secondary, if (attacktime >= 0) { int slot = weaponslot(weaponentity); - if (ATTACK_FINISHED(actor, slot) < time - actor.weapon_frametime * 1.5) + if (ATTACK_FINISHED(actor, slot) < time - this.weapon_frametime * 1.5) { ATTACK_FINISHED(actor, slot) = time; // dprint("resetting attack finished to ", ftos(time), "\n"); } ATTACK_FINISHED(actor, slot) = ATTACK_FINISHED(actor, slot) + attacktime * W_WeaponRateFactor(actor); } - actor.bulletcounter += 1; + actor.(weaponentity).bulletcounter += 1; // dprint("attack finished ", ftos(ATTACK_FINISHED(actor, slot)), "\n"); } @@ -381,8 +381,8 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void( this.weapon_nextthink = time; // dprint("started firing at ", ftos(time), "\n"); } - if (this.weapon_nextthink < time - actor.weapon_frametime * 1.5 - || this.weapon_nextthink > time + actor.weapon_frametime * 1.5) + if (this.weapon_nextthink < time - this.weapon_frametime * 1.5 + || this.weapon_nextthink > time + this.weapon_frametime * 1.5) { this.weapon_nextthink = time; // dprint("reset weapon animation timer at ", ftos(time), "\n"); @@ -401,8 +401,8 @@ void weapon_thinkf(entity actor, .entity weaponentity, WFRAME fr, float t, void( if ((fr == WFRAME_FIRE1 || fr == WFRAME_FIRE2) && t) { - bool primary_melee = boolean(fr == WFRAME_FIRE1 && (actor.(weaponentity).m_weapon.spawnflags & WEP_TYPE_MELEE_PRI)); - bool secondary_melee = boolean(fr == WFRAME_FIRE2 && (actor.(weaponentity).m_weapon.spawnflags & WEP_TYPE_MELEE_SEC)); + bool primary_melee = boolean(fr == WFRAME_FIRE1 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_PRI)); + bool secondary_melee = boolean(fr == WFRAME_FIRE2 && (this.m_weapon.spawnflags & WEP_TYPE_MELEE_SEC)); int act = (primary_melee || secondary_melee) ? ANIMACTION_MELEE : ANIMACTION_SHOOT @@ -434,14 +434,14 @@ void W_WeaponFrame(Player actor, .entity weaponentity) TC(Player, actor); TC(PlayerState, PS(actor)); entity this = actor.(weaponentity); - if (frametime) actor.weapon_frametime = frametime; + if (frametime) this.weapon_frametime = frametime; if (!this || actor.health < 1) return; // Dead player can't use weapons and injure impulse commands if (forbidWeaponUse(actor)) { - if (actor.(weaponentity).state != WS_CLEAR) + if (this.state != WS_CLEAR) { Weapon wpn = this.m_weapon; w_ready(wpn, actor, weaponentity, PHYS_INPUT_BUTTON_ATCK(actor) | (PHYS_INPUT_BUTTON_ATCK2(actor) << 1)); @@ -484,7 +484,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity) // the two weapon entities will notice this has changed and update their models this.m_weapon = newwep; this.weaponname = newwep.mdl; - actor.bulletcounter = 0; + this.bulletcounter = 0; actor.ammo_field = newwep.ammo_field; newwep.wr_setup(newwep, actor); this.state = WS_RAISE; @@ -516,7 +516,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity) entity oldwep = this.m_weapon; // set up weapon switch think in the future, and start drop anim - if (INDEPENDENT_ATTACK_FINISHED || ATTACK_FINISHED(actor, weaponslot(weaponentity)) <= time + actor.weapon_frametime * 0.5) + if (INDEPENDENT_ATTACK_FINISHED || ATTACK_FINISHED(actor, weaponslot(weaponentity)) <= time + this.weapon_frametime * 0.5) { sound(actor, CH_WEAPON_SINGLE, SND_WEAPON_SWITCH, VOL_BASE, ATTN_NORM); this.state = WS_DROP; @@ -585,7 +585,7 @@ void W_WeaponFrame(Player actor, .entity weaponentity) } } - if (time + actor.weapon_frametime * 0.5 >= this.weapon_nextthink) + if (time + this.weapon_frametime * 0.5 >= this.weapon_nextthink) { if (this.weapon_think) { -- 2.39.2