From 7e6d7254e4168c510a7e73fdaece96d0427470ec Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 24 Feb 2017 20:20:42 +1000 Subject: [PATCH] Clean up fusion reactor's target validation function and give it a mutator hook --- qcsrc/common/turrets/turret/fusionreactor.qc | 40 +++++++++----------- qcsrc/server/mutators/events.qh | 13 +++++++ 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/qcsrc/common/turrets/turret/fusionreactor.qc b/qcsrc/common/turrets/turret/fusionreactor.qc index 163bffb9d..3c468535c 100644 --- a/qcsrc/common/turrets/turret/fusionreactor.qc +++ b/qcsrc/common/turrets/turret/fusionreactor.qc @@ -4,29 +4,23 @@ #ifdef SVQC bool turret_fusionreactor_firecheck(entity this) { - if (this.attack_finished_single[0] > time) - return false; - - if (IS_DEAD(this.enemy)) - return false; - - if (this.enemy == NULL) - return false; - - if (this.ammo < this.shot_dmg) - return false; - - if (this.enemy.ammo >= this.enemy.ammo_max) - return false; - - if(vdist(this.enemy.origin - this.origin, >, this.target_range)) - return false; - - if(this.team != this.enemy.team) - return false; - - if(!(this.enemy.ammo_flags & TFL_AMMO_ENERGY)) - return false; + entity targ = this.enemy; + + switch(MUTATOR_CALLHOOK(FusionReactor_ValidTarget, this, targ)) + { + case MUT_FUSREAC_TARG_VALID: { return true; } + case MUT_FUSREAC_TARG_INVALID: { return false; } + } + + if((this.attack_finished_single[0] > time) + || (!targ) + || (IS_DEAD(targ)) + || (this.ammo < this.shot_dmg) + || (targ.ammo >= targ.ammo_max) + || (vdist(targ.origin - this.origin, >, this.target_range)) + || (this.team != targ.team) + || (!(targ.ammo_flags & TFL_AMMO_ENERGY)) + ) { return false; } return true; } diff --git a/qcsrc/server/mutators/events.qh b/qcsrc/server/mutators/events.qh index 7f30dbba8..9550daadc 100644 --- a/qcsrc/server/mutators/events.qh +++ b/qcsrc/server/mutators/events.qh @@ -928,3 +928,16 @@ MUTATOR_HOOKABLE(ChatMessageTo, EV_ChatMessageTo); /** return true to just restart the match, for modes that don't support readyrestart */ MUTATOR_HOOKABLE(ReadyRestart_Deny, EV_NO_ARGS); + +/** called when a fusion reactor is validating its target */ +#define EV_FusionReactor_ValidTarget(i, o) \ + /** turret */ i(entity, MUTATOR_ARGV_0_entity) \ + /** target */ i(entity, MUTATOR_ARGV_1_entity) \ + /**/ +MUTATOR_HOOKABLE(FusionReactor_ValidTarget, EV_FusionReactor_ValidTarget); + +enum { + MUT_FUSREAC_TARG_CONTINUE, // return this flag to make the function continue as normal + MUT_FUSREAC_TARG_VALID, // return this flag to make the function return true (valid target) + MUT_FUSREAC_TARG_INVALID // return this flag to make the function return false (invalid target) +}; -- 2.39.2