From: Mario Date: Mon, 1 Oct 2018 05:30:21 +0000 (+1000) Subject: Use the weapon instead of its ID in accuracy_add X-Git-Tag: xonotic-v0.8.5~1801 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=c66a78d068945e0dce54d7eb640395c782207fb0 Use the weapon instead of its ID in accuracy_add --- diff --git a/qcsrc/common/mutators/mutator/overkill/okrpc.qc b/qcsrc/common/mutators/mutator/overkill/okrpc.qc index 859d8dc995..50c842d984 100644 --- a/qcsrc/common/mutators/mutator/overkill/okrpc.qc +++ b/qcsrc/common/mutators/mutator/overkill/okrpc.qc @@ -14,7 +14,7 @@ void W_OverkillRocketPropelledChainsaw_Explode(entity this, entity directhitenti { // if chainsaw hit something, it removed fired damage (so that direct hit is 100%) // now that we also damaged something by explosion we'd go over 100% so let's add the fired damage back - accuracy_add(this.realowner, DEATH_WEAPONOF(this.projectiledeathtype).m_id, WEP_CVAR(okrpc, damage), 0); + accuracy_add(this.realowner, DEATH_WEAPONOF(this.projectiledeathtype), WEP_CVAR(okrpc, damage), 0); } delete(this); @@ -71,7 +71,7 @@ void W_OverkillRocketPropelledChainsaw_Think(entity this) // We remove it here so that a direct hit that passes through and doesn't damage anything by the explosion later is still 100%. float fired_damage = WEP_CVAR_PRI(okrpc, damage2) - WEP_CVAR_PRI(okrpc, damage); float hit_damage = WEP_CVAR_PRI(okrpc, damage2); - accuracy_add(this.realowner, DEATH_WEAPONOF(this.projectiledeathtype).m_id, fired_damage, hit_damage); + accuracy_add(this.realowner, DEATH_WEAPONOF(this.projectiledeathtype), fired_damage, hit_damage); } this.m_chainsaw_damage += WEP_CVAR_PRI(okrpc, damage2); } diff --git a/qcsrc/common/weapons/weapon/arc.qc b/qcsrc/common/weapons/weapon/arc.qc index b284759269..35bb1e3db1 100644 --- a/qcsrc/common/weapons/weapon/arc.qc +++ b/qcsrc/common/weapons/weapon/arc.qc @@ -473,7 +473,7 @@ void W_Arc_Beam_Think(entity this) { accuracy_add( own, - WEP_ARC.m_id, + WEP_ARC, 0, rootdamage * coefficient * falloff ); diff --git a/qcsrc/common/weapons/weapon/fireball.qc b/qcsrc/common/weapons/weapon/fireball.qc index 84113b7020..ea7f5b8aea 100644 --- a/qcsrc/common/weapons/weapon/fireball.qc +++ b/qcsrc/common/weapons/weapon/fireball.qc @@ -42,7 +42,7 @@ void W_Fireball_Explode(entity this, entity directhitentity) dir = normalize(e.origin + e.view_ofs - this.origin); if(accuracy_isgooddamage(this.realowner, e)) - accuracy_add(this.realowner, WEP_FIREBALL.m_id, 0, WEP_CVAR_PRI(fireball, bfgdamage) * points); + accuracy_add(this.realowner, WEP_FIREBALL, 0, WEP_CVAR_PRI(fireball, bfgdamage) * points); Damage(e, this, this.realowner, WEP_CVAR_PRI(fireball, bfgdamage) * points, this.projectiledeathtype | HITTYPE_BOUNCE | HITTYPE_SPLASH, this.weaponentity_fld, e.origin + e.view_ofs, WEP_CVAR_PRI(fireball, bfgforce) * dir); Send_Effect(EFFECT_FIREBALL_BFGDAMAGE, e.origin, -1 * dir, 1); diff --git a/qcsrc/common/weapons/weapon/shockwave.qc b/qcsrc/common/weapons/weapon/shockwave.qc index b09140b6c8..7e60667e53 100644 --- a/qcsrc/common/weapons/weapon/shockwave.qc +++ b/qcsrc/common/weapons/weapon/shockwave.qc @@ -106,7 +106,7 @@ void W_Shockwave_Melee_Think(entity this) // handle accuracy if(accuracy_isgooddamage(this.realowner, target_victim)) - { accuracy_add(this.realowner, WEP_SHOCKWAVE.m_id, 0, swing_damage); } + { accuracy_add(this.realowner, WEP_SHOCKWAVE, 0, swing_damage); } #ifdef DEBUG_SHOCKWAVE LOG_INFOF( @@ -573,7 +573,7 @@ void W_Shockwave_Attack(Weapon thiswep, entity actor, .entity weaponentity) ); if(accuracy_isgooddamage(actor, head)) - accuracy_add(actor, thiswep.m_id, 0, final_damage); + accuracy_add(actor, thiswep, 0, final_damage); #ifdef DEBUG_SHOCKWAVE LOG_INFOF( diff --git a/qcsrc/common/weapons/weapon/shotgun.qc b/qcsrc/common/weapons/weapon/shotgun.qc index 4a3ab17034..8faac3d5d0 100644 --- a/qcsrc/common/weapons/weapon/shotgun.qc +++ b/qcsrc/common/weapons/weapon/shotgun.qc @@ -95,7 +95,7 @@ void W_Shotgun_Melee_Think(entity this) this.realowner.origin + this.realowner.view_ofs, v_forward * WEP_CVAR_SEC(shotgun, force)); - if(accuracy_isgooddamage(this.realowner, target_victim)) { accuracy_add(this.realowner, WEP_SHOTGUN.m_id, 0, swing_damage); } + if(accuracy_isgooddamage(this.realowner, target_victim)) { accuracy_add(this.realowner, WEP_SHOTGUN, 0, swing_damage); } // draw large red flash for debugging //te_customflash(targpos, 200, 2, '15 0 0'); diff --git a/qcsrc/common/weapons/weapon/vaporizer.qc b/qcsrc/common/weapons/weapon/vaporizer.qc index 414459c2b3..cefa4558f2 100644 --- a/qcsrc/common/weapons/weapon/vaporizer.qc +++ b/qcsrc/common/weapons/weapon/vaporizer.qc @@ -105,7 +105,7 @@ NET_HANDLE(TE_CSQC_VAPORBEAMPARTICLE, bool isNew) void W_RocketMinsta_Explosion(entity actor, .entity weaponentity, vector loc) { if(accuracy_canbegooddamage(actor)) - accuracy_add(actor, WEP_DEVASTATOR.m_id, autocvar_g_rm_damage, 0); + accuracy_add(actor, WEP_DEVASTATOR, autocvar_g_rm_damage, 0); entity dmgent = spawn(); dmgent.owner = dmgent.realowner = actor; setorigin(dmgent, loc); diff --git a/qcsrc/server/g_damage.qc b/qcsrc/server/g_damage.qc index c238b93f6e..e9ab3d79ac 100644 --- a/qcsrc/server/g_damage.qc +++ b/qcsrc/server/g_damage.qc @@ -1053,7 +1053,7 @@ float RadiusDamageForSource (entity inflictor, vector inflictororigin, vector in RadiusDamage_running = 0; if(!DEATH_ISSPECIAL(deathtype)) - accuracy_add(attacker, DEATH_WEAPONOF(deathtype).m_id, 0, min(coredamage, stat_damagedone)); + accuracy_add(attacker, DEATH_WEAPONOF(deathtype), 0, min(coredamage, stat_damagedone)); return total_damage_to_creatures; } @@ -1182,7 +1182,7 @@ float Fire_AddDamage(entity e, entity o, float d, float t, float dt) } } if(accuracy_isgooddamage(o, e)) - accuracy_add(o, DEATH_WEAPONOF(dt).m_id, 0, max(0, totaldamage - mindamage)); + accuracy_add(o, DEATH_WEAPONOF(dt), 0, max(0, totaldamage - mindamage)); return max(0, totaldamage - mindamage); // can never be negative, but to make sure } else @@ -1196,7 +1196,7 @@ float Fire_AddDamage(entity e, entity o, float d, float t, float dt) e.fire_owner = o; e.fire_hitsound = false; if(accuracy_isgooddamage(o, e)) - accuracy_add(o, DEATH_WEAPONOF(dt).m_id, 0, d); + accuracy_add(o, DEATH_WEAPONOF(dt), 0, d); return d; } } diff --git a/qcsrc/server/weapons/accuracy.qc b/qcsrc/server/weapons/accuracy.qc index 8cd7ab66c3..8a7bac1b9f 100644 --- a/qcsrc/server/weapons/accuracy.qc +++ b/qcsrc/server/weapons/accuracy.qc @@ -61,30 +61,31 @@ void accuracy_resend(entity e) //.float hit_time; .float fired_time; -void accuracy_add(entity this, int w, int fired, int hit) +void accuracy_add(entity this, Weapon w, int fired, int hit) { if (IS_INDEPENDENT_PLAYER(this)) return; entity a = CS(this).accuracy; if (!a) return; if (!hit && !fired) return; - if (w == WEP_Null.m_id) return; - w -= WEP_FIRST; - int b = accuracy_byte(a.accuracy_hit[w], a.accuracy_fired[w]); - if (hit) a.accuracy_hit [w] += hit; - if (fired) a.accuracy_fired[w] += fired; + if (w == WEP_Null) return; + int wepid = w.m_id; + wepid -= WEP_FIRST; + int b = accuracy_byte(a.accuracy_hit[wepid], a.accuracy_fired[wepid]); + if (hit) a.accuracy_hit [wepid] += hit; + if (fired) a.accuracy_fired[wepid] += fired; if (hit && STAT(HIT_TIME, a) != time) { // only run this once per frame - a.accuracy_cnt_hit[w] += 1; + a.accuracy_cnt_hit[wepid] += 1; STAT(HIT_TIME, a) = time; } if (fired && a.fired_time != time) { // only run this once per frame - a.accuracy_cnt_fired[w] += 1; + a.accuracy_cnt_fired[wepid] += 1; a.fired_time = time; } - if (b == accuracy_byte(a.accuracy_hit[w], a.accuracy_fired[w])) return; // no change - int sf = 1 << (w % 24); + if (b == accuracy_byte(a.accuracy_hit[wepid], a.accuracy_fired[wepid])) return; // no change + int sf = 1 << (wepid % 24); a.SendFlags |= sf; FOREACH_CLIENT(IS_SPEC(it) && it.enemy == this, { CS(it).accuracy.SendFlags |= sf; }); } diff --git a/qcsrc/server/weapons/accuracy.qh b/qcsrc/server/weapons/accuracy.qh index d24ee1cf50..627698aa21 100644 --- a/qcsrc/server/weapons/accuracy.qh +++ b/qcsrc/server/weapons/accuracy.qh @@ -25,7 +25,7 @@ void accuracy_free(entity e); void accuracy_resend(entity e); // update accuracy stats -void accuracy_add(entity e, float w, float fired, float hit); +void accuracy_add(entity e, Weapon w, float fired, float hit); // helper bool accuracy_isgooddamage(entity attacker, entity targ); diff --git a/qcsrc/server/weapons/tracing.qc b/qcsrc/server/weapons/tracing.qc index 570d976db1..a1d16b50b0 100644 --- a/qcsrc/server/weapons/tracing.qc +++ b/qcsrc/server/weapons/tracing.qc @@ -57,7 +57,7 @@ void W_SetupShot_Dir_ProjectileSize_Range(entity ent, .entity weaponentity, vect // track max damage if (IS_PLAYER(ent) && accuracy_canbegooddamage(ent)) - accuracy_add(ent, wep.m_id, maxdamage, 0); + accuracy_add(ent, wep, maxdamage, 0); if(IS_PLAYER(ent)) W_HitPlotAnalysis(ent, wep, v_forward, v_right, v_up); @@ -266,7 +266,7 @@ void FireRailgunBullet (entity this, .entity weaponentity, vector start, vector //explosion = spawn(); // Find all non-hit players the beam passed close by - if(deathtype == WEP_VAPORIZER.m_id || deathtype == WEP_VORTEX.m_id) + if(deathtype == WEP_VAPORIZER.m_id || deathtype == WEP_VORTEX.m_id) // WEAPONTODO { FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != this, { if(!it.railgunhit) @@ -321,7 +321,8 @@ void FireRailgunBullet (entity this, .entity weaponentity, vector start, vector IL_CLEAR(g_railgunhit); // calculate hits and fired shots for hitscan - accuracy_add(this, this.(weaponentity).m_weapon.m_id, 0, min(bdamage, totaldmg)); + if(this.(weaponentity)) + accuracy_add(this, this.(weaponentity).m_weapon, 0, min(bdamage, totaldmg)); trace_endpos = endpoint; trace_ent = endent; @@ -421,7 +422,7 @@ void fireBullet(entity this, .entity weaponentity, vector start, vector dir, flo // do not exceed 100% float added_damage = min(damage - total_damage, damage * solid_penetration_left); total_damage += damage * solid_penetration_left; - accuracy_add(this, this.(weaponentity).m_weapon.m_id, 0, added_damage); + accuracy_add(this, this.(weaponentity).m_weapon, 0, added_damage); } }