From 5e407e0d952589c8041fa4263e495dc09116e8db Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 20 May 2016 06:25:20 +1000 Subject: [PATCH] Clean up self uses in weapon dropping code, also switch EXACTTRIGGER_INIT over to 'this' --- .../gamemodes/gamemode/nexball/nexball.qc | 2 +- .../common/mutators/mutator/pinata/pinata.qc | 2 +- qcsrc/common/triggers/triggers.qc | 2 +- qcsrc/lib/warpzone/common.qh | 4 +- qcsrc/lib/warpzone/server.qc | 2 +- qcsrc/lib/warpzone/util_server.qc | 4 +- qcsrc/lib/warpzone/util_server.qh | 2 +- qcsrc/server/cl_impulse.qc | 2 +- qcsrc/server/mutators/events.qh | 10 +++- qcsrc/server/weapons/throwing.qc | 46 +++++++++---------- qcsrc/server/weapons/throwing.qh | 4 +- qcsrc/server/weapons/weaponsystem.qc | 1 - 12 files changed, 43 insertions(+), 38 deletions(-) diff --git a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc index d4cc871d9..b0872497d 100644 --- a/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc +++ b/qcsrc/common/gamemodes/gamemode/nexball/nexball.qc @@ -614,7 +614,7 @@ void SpawnGoal(entity this) { if(!g_nexball) { remove(this); return; } - WITHSELF(this, WarpZoneLib_ExactTrigger_Init()); + EXACTTRIGGER_INIT; if(this.team != GOAL_OUT && Team_TeamToNumber(this.team) != -1) { diff --git a/qcsrc/common/mutators/mutator/pinata/pinata.qc b/qcsrc/common/mutators/mutator/pinata/pinata.qc index 22ab9acae..62dd19e4f 100644 --- a/qcsrc/common/mutators/mutator/pinata/pinata.qc +++ b/qcsrc/common/mutators/mutator/pinata/pinata.qc @@ -6,7 +6,7 @@ MUTATOR_HOOKFUNCTION(pinata, PlayerDies) FOREACH(Weapons, it != WEP_Null, LAMBDA( if(frag_target.weapons & WepSet_FromWeapon(it)) if(PS(frag_target).m_switchweapon != it) - if(W_IsWeaponThrowable(it.m_id)) + if(W_IsWeaponThrowable(frag_target, it.m_id)) W_ThrowNewWeapon(frag_target, it.m_id, false, CENTER_OR_VIEWOFS(frag_target), randomvec() * 175 + '0 0 325'); )); diff --git a/qcsrc/common/triggers/triggers.qc b/qcsrc/common/triggers/triggers.qc index 4493138d0..776044573 100644 --- a/qcsrc/common/triggers/triggers.qc +++ b/qcsrc/common/triggers/triggers.qc @@ -24,7 +24,7 @@ void FixSize(entity e) void trigger_init(entity this) { string m = this.model; - WITHSELF(this, WarpZoneLib_ExactTrigger_Init()); + EXACTTRIGGER_INIT; if(m != "") { precache_model(m); diff --git a/qcsrc/lib/warpzone/common.qh b/qcsrc/lib/warpzone/common.qh index ebea01108..c82790095 100644 --- a/qcsrc/lib/warpzone/common.qh +++ b/qcsrc/lib/warpzone/common.qh @@ -108,9 +108,9 @@ float WarpZoneLib_MoveOutOfSolid(entity e); #define move_out_of_solid(e) WarpZoneLib_MoveOutOfSolid(e) float WarpZoneLib_ExactTrigger_Touch(); -void WarpZoneLib_ExactTrigger_Init(); +void WarpZoneLib_ExactTrigger_Init(entity this); // WARNING: this kills the trace globals #define EXACTTRIGGER_TOUCH if(WarpZoneLib_ExactTrigger_Touch()) return -#define EXACTTRIGGER_INIT WarpZoneLib_ExactTrigger_Init() +#define EXACTTRIGGER_INIT WarpZoneLib_ExactTrigger_Init(this) #endif diff --git a/qcsrc/lib/warpzone/server.qc b/qcsrc/lib/warpzone/server.qc index f8260b5ad..6a748eed4 100644 --- a/qcsrc/lib/warpzone/server.qc +++ b/qcsrc/lib/warpzone/server.qc @@ -761,7 +761,7 @@ spawnfunc(trigger_warpzone) this.scale = 1; string m; m = this.model; - WarpZoneLib_ExactTrigger_Init(); + WarpZoneLib_ExactTrigger_Init(this); if(m != "") { precache_model(m); diff --git a/qcsrc/lib/warpzone/util_server.qc b/qcsrc/lib/warpzone/util_server.qc index be232a281..73f09c0e0 100644 --- a/qcsrc/lib/warpzone/util_server.qc +++ b/qcsrc/lib/warpzone/util_server.qc @@ -9,8 +9,8 @@ #endif #include "common.qh" -void WarpZoneLib_ExactTrigger_Init() -{SELFPARAM(); +void WarpZoneLib_ExactTrigger_Init(entity this) +{ vector mi, ma; if (this.movedir == '0 0 0') if (this.angles != '0 0 0') diff --git a/qcsrc/lib/warpzone/util_server.qh b/qcsrc/lib/warpzone/util_server.qh index 75df5d862..5c94d4319 100644 --- a/qcsrc/lib/warpzone/util_server.qh +++ b/qcsrc/lib/warpzone/util_server.qh @@ -4,6 +4,6 @@ float WarpZoneLib_MoveOutOfSolid(entity e); float WarpZoneLib_ExactTrigger_Touch(); #ifdef SVQC -void WarpZoneLib_ExactTrigger_Init(); +void WarpZoneLib_ExactTrigger_Init(entity this); #endif #endif diff --git a/qcsrc/server/cl_impulse.qc b/qcsrc/server/cl_impulse.qc index 14779525f..3aa9cfeb7 100644 --- a/qcsrc/server/cl_impulse.qc +++ b/qcsrc/server/cl_impulse.qc @@ -248,7 +248,7 @@ IMPULSE(weapon_drop) { if (this.vehicle) return; if (IS_DEAD(this)) return; - W_ThrowWeapon(W_CalculateProjectileVelocity(this.velocity, v_forward * 750, false), '0 0 0', true); + W_ThrowWeapon(this, W_CalculateProjectileVelocity(this.velocity, v_forward * 750, false), '0 0 0', true); } IMPULSE(weapon_reload) diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index 8039d8348..fac7249c8 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -126,10 +126,16 @@ string format_message; MUTATOR_HOOKABLE(FormatMessage, EV_FormatMessage); /** returns true if throwing the current weapon shall not be allowed */ -MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon, EV_NO_ARGS); +#define EV_ForbidThrowCurrentWeapon(i, o) \ + /**/ i(entity, __self) \ + /**/ +MUTATOR_HOOKABLE(ForbidThrowCurrentWeapon, EV_ForbidThrowCurrentWeapon); /** returns true if dropping the current weapon shall not be allowed at any time including death */ -MUTATOR_HOOKABLE(ForbidDropCurrentWeapon, EV_NO_ARGS); +#define EV_ForbidDropCurrentWeapon(i, o) \ + /**/ i(entity, __self) \ + /**/ +MUTATOR_HOOKABLE(ForbidDropCurrentWeapon, EV_ForbidDropCurrentWeapon); /** */ MUTATOR_HOOKABLE(SetDefaultAlpha, EV_NO_ARGS); diff --git a/qcsrc/server/weapons/throwing.qc b/qcsrc/server/weapons/throwing.qc index c06b08c08..43285fb6a 100644 --- a/qcsrc/server/weapons/throwing.qc +++ b/qcsrc/server/weapons/throwing.qc @@ -32,7 +32,7 @@ void thrown_wep_think() // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo) -{SELFPARAM(); +{ float thisammo; string s; Weapon info = Weapons_from(wpn); @@ -97,11 +97,11 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto if(doreduce && g_weapon_stay == 2) { // if our weapon is loaded, give its load back to the player - int i = PS(self).m_weapon.m_id; - if(self.(weapon_load[i]) > 0) + int i = PS(own).m_weapon.m_id; + if(own.(weapon_load[i]) > 0) { - own.(ammotype) += self.(weapon_load[i]); - self.(weapon_load[i]) = -1; // schedule the weapon for reloading + own.(ammotype) += own.(weapon_load[i]); + own.(weapon_load[i]) = -1; // schedule the weapon for reloading } wep.(ammotype) = 0; @@ -109,11 +109,11 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto else if(doreduce) { // if our weapon is loaded, give its load back to the player - int i = PS(self).m_weapon.m_id; - if(self.(weapon_load[i]) > 0) + int i = PS(own).m_weapon.m_id; + if(own.(weapon_load[i]) > 0) { - own.(ammotype) += self.(weapon_load[i]); - self.(weapon_load[i]) = -1; // schedule the weapon for reloading + own.(ammotype) += own.(weapon_load[i]); + own.(weapon_load[i]) = -1; // schedule the weapon for reloading } thisammo = min(own.(ammotype), wep.(ammotype)); @@ -136,9 +136,9 @@ string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vecto } } -bool W_IsWeaponThrowable(bool w) +bool W_IsWeaponThrowable(entity this, int w) { - if (MUTATOR_CALLHOOK(ForbidDropCurrentWeapon)) + if (MUTATOR_CALLHOOK(ForbidDropCurrentWeapon, this)) return false; if (!autocvar_g_pickup_items) return false; @@ -165,35 +165,35 @@ bool W_IsWeaponThrowable(bool w) } // toss current weapon -void W_ThrowWeapon(vector velo, vector delta, float doreduce) -{SELFPARAM(); - Weapon w = PS(self).m_weapon; +void W_ThrowWeapon(entity this, vector velo, vector delta, float doreduce) +{ + Weapon w = PS(this).m_weapon; if (w == WEP_Null) return; // just in case - if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon)) + if(MUTATOR_CALLHOOK(ForbidThrowCurrentWeapon, this)) return; if(!autocvar_g_weapon_throwable) return; .entity weaponentity = weaponentities[0]; // TODO: unhardcode - if(self.(weaponentity).state != WS_READY) + if(this.(weaponentity).state != WS_READY) return; - if(!W_IsWeaponThrowable(w.m_id)) + if(!W_IsWeaponThrowable(this, w.m_id)) return; WepSet set = WepSet_FromWeapon(w); - if(!(self.weapons & set)) return; - self.weapons &= ~set; + if(!(this.weapons & set)) return; + this.weapons &= ~set; - W_SwitchWeapon_Force(self, w_getbestweapon(self)); - string a = W_ThrowNewWeapon(self, w.m_id, doreduce, self.origin + delta, velo); + W_SwitchWeapon_Force(this, w_getbestweapon(this)); + string a = W_ThrowNewWeapon(this, w.m_id, doreduce, this.origin + delta, velo); if(!a) return; - Send_Notification(NOTIF_ONE, self, MSG_MULTI, ITEM_WEAPON_DROP, a, w.m_id); + Send_Notification(NOTIF_ONE, this, MSG_MULTI, ITEM_WEAPON_DROP, a, w.m_id); } void SpawnThrownWeapon(entity this, vector org, float w) { if(this.weapons & WepSet_FromWeapon(PS(this).m_weapon)) - if(W_IsWeaponThrowable(PS(this).m_weapon.m_id)) + if(W_IsWeaponThrowable(this, PS(this).m_weapon.m_id)) W_ThrowNewWeapon(this, PS(this).m_weapon.m_id, false, org, randomvec() * 125 + '0 0 200'); } diff --git a/qcsrc/server/weapons/throwing.qh b/qcsrc/server/weapons/throwing.qh index 488791295..b0482da91 100644 --- a/qcsrc/server/weapons/throwing.qh +++ b/qcsrc/server/weapons/throwing.qh @@ -6,9 +6,9 @@ void thrown_wep_think(); // returns amount of ammo used as string, or -1 for failure, or 0 for no ammo count string W_ThrowNewWeapon(entity own, float wpn, float doreduce, vector org, vector velo); -float W_IsWeaponThrowable(float w); +bool W_IsWeaponThrowable(entity this, int w); // toss current weapon -void W_ThrowWeapon(vector velo, vector delta, float doreduce); +void W_ThrowWeapon(entity this, vector velo, vector delta, float doreduce); void SpawnThrownWeapon(entity this, vector org, float w); diff --git a/qcsrc/server/weapons/weaponsystem.qc b/qcsrc/server/weapons/weaponsystem.qc index f44b39290..53d421ab6 100644 --- a/qcsrc/server/weapons/weaponsystem.qc +++ b/qcsrc/server/weapons/weaponsystem.qc @@ -769,7 +769,6 @@ void W_Reload(entity actor, float sent_ammo_min, Sound sent_sound) void W_DropEvent(.void(Weapon) event, entity player, float weapon_type, entity weapon_item) { - SELFPARAM(); Weapon w = Weapons_from(weapon_type); weapon_dropevent_item = weapon_item; WITHSELF(player, w.event(w)); -- 2.39.2