From 020a0922086bf04cf4e1fa5eb8bdb4ce606503cc Mon Sep 17 00:00:00 2001 From: Freddy Date: Mon, 12 Mar 2018 15:32:27 +0100 Subject: [PATCH] trigger_gravity: use .active instead of .state, remove magic numbers --- qcsrc/common/triggers/spawnflags.qh | 12 ++++++++---- qcsrc/common/triggers/trigger/gravity.qc | 16 ++++++++++------ .../common/triggers/trigger/relay_activators.qc | 8 +------- qcsrc/common/triggers/triggers.qc | 9 +++++++-- qcsrc/common/triggers/triggers.qh | 1 + 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/qcsrc/common/triggers/spawnflags.qh b/qcsrc/common/triggers/spawnflags.qh index f91b037fb..eaf791468 100644 --- a/qcsrc/common/triggers/spawnflags.qh +++ b/qcsrc/common/triggers/spawnflags.qh @@ -5,6 +5,10 @@ const int START_ENABLED = BIT(0); const int ON_MAPLOAD = BIT(1); const int NOSPLASH = BIT(8); // generic anti-splashdamage spawnflag +// triggers +const int SPAWNFLAG_NOMESSAGE = BIT(0); +const int SPAWNFLAG_NOTOUCH = BIT(0); // why are these the same? + // bobbing const int BOBBING_XAXIS = BIT(0); const int BOBBING_YAXIS = BIT(1); @@ -96,13 +100,13 @@ const int TELEPORT_FLAG_PARTICLES = BIT(1); const int TELEPORT_FLAG_TDEATH = BIT(2); const int TELEPORT_FLAG_FORCE_TDEATH = BIT(3); -// triggers -const int SPAWNFLAG_NOMESSAGE = BIT(0); -const int SPAWNFLAG_NOTOUCH = BIT(0); // why are these the same? - // counter const int COUNTER_FIRE_AT_COUNT = BIT(2); +// gravity +const int GRAVITY_STICKY = BIT(0); // keep gravity multiplier even after exiting the trigger_gravity +const int GRAVITY_START_DISABLED = BIT(1); + //---------- // SENDFLAGS //---------- diff --git a/qcsrc/common/triggers/trigger/gravity.qc b/qcsrc/common/triggers/trigger/gravity.qc index 3ea1562f0..1ac0f8768 100644 --- a/qcsrc/common/triggers/trigger/gravity.qc +++ b/qcsrc/common/triggers/trigger/gravity.qc @@ -33,29 +33,31 @@ void trigger_gravity_check_think(entity this) } } +// legacy void trigger_gravity_use(entity this, entity actor, entity trigger) { - this.state = !this.state; + this.setactive(this, ACTIVE_TOGGLE); } void trigger_gravity_touch(entity this, entity toucher) { float g; - if(this.state != true) + if(this.active == ACTIVE_NOT) return; EXACTTRIGGER_TOUCH(this, toucher); g = this.gravity; - if (!(this.spawnflags & 1)) + if (!(this.spawnflags & GRAVITY_STICKY)) { if(toucher.trigger_gravity_check) { if(this == toucher.trigger_gravity_check.enemy) { // same? + // NOTE: see explanation in trigger_gravity_check_think toucher.trigger_gravity_check.count = 2; // gravity one more frame... return; } @@ -96,12 +98,14 @@ spawnfunc(trigger_gravity) if(this.noise != "") precache_sound(this.noise); - this.state = true; + this.active = ACTIVE_ACTIVE; + this.setactive = generic_setactive; IFTARGETED { + // legacy use this.use = trigger_gravity_use; - if(this.spawnflags & 2) - this.state = false; + if(this.spawnflags & GRAVITY_START_DISABLED) + this.active = ACTIVE_NOT; } } #endif diff --git a/qcsrc/common/triggers/trigger/relay_activators.qc b/qcsrc/common/triggers/trigger/relay_activators.qc index d713a0583..18c2a40d0 100644 --- a/qcsrc/common/triggers/trigger/relay_activators.qc +++ b/qcsrc/common/triggers/trigger/relay_activators.qc @@ -9,13 +9,7 @@ void relay_activators_use(entity this, entity actor, entity trigger) else { //bprint("Not using setactive\n"); - if(this.cnt == ACTIVE_TOGGLE) - if(trg.active == ACTIVE_ACTIVE) - trg.active = ACTIVE_NOT; - else - trg.active = ACTIVE_ACTIVE; - else - trg.active = this.cnt; + generic_setactive(trg, this.cnt); } } } diff --git a/qcsrc/common/triggers/triggers.qc b/qcsrc/common/triggers/triggers.qc index 034f66e1a..144f6bfb0 100644 --- a/qcsrc/common/triggers/triggers.qc +++ b/qcsrc/common/triggers/triggers.qc @@ -21,9 +21,8 @@ void FixSize(entity e) } #ifdef SVQC -void generic_netlinked_setactive(entity this, int act) +void generic_setactive(entity this, int act) { - int old_status = this.active; if(act == ACTIVE_TOGGLE) { if(this.active == ACTIVE_ACTIVE) @@ -39,6 +38,12 @@ void generic_netlinked_setactive(entity this, int act) { this.active = act; } +} + +void generic_netlinked_setactive(entity this, int act) +{ + int old_status = this.active; + generic_setactive(this, act); if (this.active != old_status) { diff --git a/qcsrc/common/triggers/triggers.qh b/qcsrc/common/triggers/triggers.qh index 681bb898b..1ecef7638 100644 --- a/qcsrc/common/triggers/triggers.qh +++ b/qcsrc/common/triggers/triggers.qh @@ -23,6 +23,7 @@ void target_voicescript_clear(entity pl); void SUB_UseTargets_PreventReuse(entity this, entity actor, entity trigger); +void generic_setactive(entity this, int act); // generic methods for netlinked entities void generic_netlinked_reset(entity this); void generic_netlinked_setactive(entity this, int act); -- 2.39.2