From 7ea9095eda4f4d279e9703c9c5c770e905baa543 Mon Sep 17 00:00:00 2001 From: Freddy Date: Fri, 16 Mar 2018 00:30:31 +0100 Subject: [PATCH] Remove a few more magic numbers and minor code cleanup --- qcsrc/common/triggers/spawnflags.qh | 7 +++++++ qcsrc/common/triggers/trigger/multivibrator.qc | 6 +++--- qcsrc/common/triggers/trigger/relay.qc | 5 ++++- qcsrc/common/triggers/trigger/relay_if.qc | 2 +- qcsrc/common/triggers/trigger/relay_teamcheck.qc | 4 ++-- qcsrc/common/triggers/trigger/teleport.qc | 13 ++++++++++--- qcsrc/common/triggers/trigger/viewloc.qc | 5 ++++- 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/qcsrc/common/triggers/spawnflags.qh b/qcsrc/common/triggers/spawnflags.qh index 44d129d4e..02f80d6f0 100644 --- a/qcsrc/common/triggers/spawnflags.qh +++ b/qcsrc/common/triggers/spawnflags.qh @@ -131,6 +131,13 @@ const int MAGICEAR_TUBA_EXACTPITCH = BIT(9); // monoflop const int MONOFLOP_FIXED = BIT(0); +// relay_if +const int RELAYIF_NEGATE = BIT(0); + +// relay_teamcheck +const int RELAYTEAMCHECK_NOTEAM = BIT(0); +const int RELAYTEAMCHECK_INVERT = BIT(1); + //---------- // SENDFLAGS //---------- diff --git a/qcsrc/common/triggers/trigger/multivibrator.qc b/qcsrc/common/triggers/trigger/multivibrator.qc index d946efe5f..932fda13c 100644 --- a/qcsrc/common/triggers/trigger/multivibrator.qc +++ b/qcsrc/common/triggers/trigger/multivibrator.qc @@ -43,13 +43,13 @@ void multivibrator_toggle(entity this, entity actor, entity trigger) void multivibrator_reset(entity this) { - if(!(this.spawnflags & 1)) + if(!(this.spawnflags & START_ENABLED)) this.nextthink = 0; // wait for a trigger event else this.nextthink = max(1, time); } -/*QUAKED trigger_multivibrator (.5 .5 .5) (-8 -8 -8) (8 8 8) START_ON +/*QUAKED trigger_multivibrator (.5 .5 .5) (-8 -8 -8) (8 8 8) START_ENABLED "Multivibrator" trigger gate... repeatedly sends trigger events. When triggered, turns on or off. -------- KEYS -------- target: trigger all entities with this targetname when it goes off @@ -58,7 +58,7 @@ phase: offset of the timing wait: "on" cycle time (default: 1) respawntime: "off" cycle time (default: same as wait) -------- SPAWNFLAGS -------- -START_ON: assume it is already turned on (when targeted) +START_ENABLED: assume it is already turned on (when targeted) */ spawnfunc(trigger_multivibrator) { diff --git a/qcsrc/common/triggers/trigger/relay.qc b/qcsrc/common/triggers/trigger/relay.qc index e5d001803..f99d364ae 100644 --- a/qcsrc/common/triggers/trigger/relay.qc +++ b/qcsrc/common/triggers/trigger/relay.qc @@ -19,5 +19,8 @@ spawnfunc(trigger_relay) this.reset = spawnfunc_trigger_relay; // this spawnfunc resets fully } -spawnfunc(target_relay) { spawnfunc_trigger_relay(this); } +spawnfunc(target_relay) +{ + spawnfunc_trigger_relay(this); +} #endif diff --git a/qcsrc/common/triggers/trigger/relay_if.qc b/qcsrc/common/triggers/trigger/relay_if.qc index 728252c70..9adcd666e 100644 --- a/qcsrc/common/triggers/trigger/relay_if.qc +++ b/qcsrc/common/triggers/trigger/relay_if.qc @@ -6,7 +6,7 @@ void trigger_relay_if_use(entity this, entity actor, entity trigger) // TODO make this generic AND faster than nextent()ing through all, if somehow possible n = (cvar_string(this.netname) == cvar_string(this.message)); - if(this.spawnflags & 1) + if(this.spawnflags & RELAYIF_NEGATE) n = !n; if(n) diff --git a/qcsrc/common/triggers/trigger/relay_teamcheck.qc b/qcsrc/common/triggers/trigger/relay_teamcheck.qc index fee28df51..bf03b1542 100644 --- a/qcsrc/common/triggers/trigger/relay_teamcheck.qc +++ b/qcsrc/common/triggers/trigger/relay_teamcheck.qc @@ -4,7 +4,7 @@ void trigger_relay_teamcheck_use(entity this, entity actor, entity trigger) { if(actor.team) { - if(this.spawnflags & 2) + if(this.spawnflags & RELAYTEAMCHECK_INVERT) { if(DIFF_TEAM(actor, this)) SUB_UseTargets(this, actor, trigger); @@ -17,7 +17,7 @@ void trigger_relay_teamcheck_use(entity this, entity actor, entity trigger) } else { - if(this.spawnflags & 1) + if(this.spawnflags & RELAYTEAMCHECK_NOTEAM) SUB_UseTargets(this, actor, trigger); } } diff --git a/qcsrc/common/triggers/trigger/teleport.qc b/qcsrc/common/triggers/trigger/teleport.qc index 0330ce8d8..825dd01dd 100644 --- a/qcsrc/common/triggers/trigger/teleport.qc +++ b/qcsrc/common/triggers/trigger/teleport.qc @@ -36,7 +36,7 @@ bool Teleport_Active(entity this, entity player) return false; if(this.team) - if(((this.spawnflags & 4) == 0) == (DIFF_TEAM(this, player))) + if(((this.spawnflags & INVERT_TEAMS) == 0) == (DIFF_TEAM(this, player))) return false; return true; @@ -83,7 +83,10 @@ void target_teleport_use(entity this, entity actor, entity trigger) string s = this.target; this.target = string_null; SUB_UseTargets(this, player, player); // TODO: should we be using toucher for trigger too? - if (!this.target) this.target = s; + if (!this.target) + { + this.target = s; + } SUB_UseTargets(e, player, player); } @@ -157,7 +160,11 @@ NET_HANDLE(ENT_CLIENT_TRIGGER_TELEPORT, bool isnew) this.classname = "trigger_teleport"; if(isnew) IL_PUSH(g_teleporters, this); - int mytm = ReadByte(); if(mytm) { this.team = mytm - 1; } + int mytm = ReadByte(); + if(mytm) + { + this.team = mytm - 1; + } this.spawnflags = ReadInt24_t(); this.active = ReadByte(); this.speed = ReadCoord(); diff --git a/qcsrc/common/triggers/trigger/viewloc.qc b/qcsrc/common/triggers/trigger/viewloc.qc index 8b985795d..ba5dcbe44 100644 --- a/qcsrc/common/triggers/trigger/viewloc.qc +++ b/qcsrc/common/triggers/trigger/viewloc.qc @@ -154,7 +154,10 @@ spawnfunc(target_viewlocation_end) } // compatibility -spawnfunc(target_viewlocation) { spawnfunc_target_viewlocation_start(this); } +spawnfunc(target_viewlocation) +{ + spawnfunc_target_viewlocation_start(this); +} #elif defined(CSQC) -- 2.39.2