From c505b3bd8e64b758c1ece62695d70da47df5f81e Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 31 Jul 2020 19:30:30 +1000 Subject: [PATCH] Refactor trigger_secret to be standalone (not using parts of trigger_multiple and trigger_once), fixes secrets being activated too many times and producing bogus secret counters, also cleanup relay trigger code a bit, allowing them to be (de)activated themselves --- qcsrc/common/mapobjects/trigger/multi.qc | 13 +---- .../mapobjects/trigger/relay_activators.qc | 17 +++++- qcsrc/common/mapobjects/trigger/relay_if.qc | 1 + .../mapobjects/trigger/relay_teamcheck.qc | 1 + qcsrc/common/mapobjects/trigger/secret.qc | 58 +++++++++---------- qcsrc/common/mapobjects/trigger/secret.qh | 20 ++----- qcsrc/common/stats.qh | 5 +- qcsrc/server/client.qc | 1 - 8 files changed, 55 insertions(+), 61 deletions(-) diff --git a/qcsrc/common/mapobjects/trigger/multi.qc b/qcsrc/common/mapobjects/trigger/multi.qc index df915a649..9ce5f52ce 100644 --- a/qcsrc/common/mapobjects/trigger/multi.qc +++ b/qcsrc/common/mapobjects/trigger/multi.qc @@ -29,16 +29,7 @@ void multi_trigger(entity this) return; // only players } - // TODO: restructure this so that trigger_secret is more independent - if (this.classname == "trigger_secret") - { - if (!IS_PLAYER(this.enemy)) - return; - found_secrets = found_secrets + 1; - WriteByte (MSG_ALL, SVC_FOUNDSECRET); - } - - if (this.noise) + if (this.noise && this.noise != "") { _sound (this.enemy, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM); } @@ -167,7 +158,7 @@ spawnfunc(trigger_multiple) else if (this.sounds == 3) this.noise = "misc/trigger1.wav"; - if(this.noise) + if(this.noise && this.noise != "") precache_sound(this.noise); if (!this.wait) diff --git a/qcsrc/common/mapobjects/trigger/relay_activators.qc b/qcsrc/common/mapobjects/trigger/relay_activators.qc index 18c2a40d0..2c891c2ac 100644 --- a/qcsrc/common/mapobjects/trigger/relay_activators.qc +++ b/qcsrc/common/mapobjects/trigger/relay_activators.qc @@ -1,7 +1,11 @@ #include "relay_activators.qh" + #ifdef SVQC void relay_activators_use(entity this, entity actor, entity trigger) { + if(this.active != ACTIVE_ACTIVE) + return; + for(entity trg = NULL; (trg = find(trg, targetname, this.target)); ) { if (trg.setactive) @@ -14,21 +18,28 @@ void relay_activators_use(entity this, entity actor, entity trigger) } } +void relay_activators_init(entity this) +{ + this.reset = relay_activators_init; // doubles as a reset function + this.active = ACTIVE_ACTIVE; + this.use = relay_activators_use; +} + spawnfunc(relay_activate) { this.cnt = ACTIVE_ACTIVE; - this.use = relay_activators_use; + relay_activators_init(this); } spawnfunc(relay_deactivate) { this.cnt = ACTIVE_NOT; - this.use = relay_activators_use; + relay_activators_init(this); } spawnfunc(relay_activatetoggle) { this.cnt = ACTIVE_TOGGLE; - this.use = relay_activators_use; + relay_activators_init(this); } #endif diff --git a/qcsrc/common/mapobjects/trigger/relay_if.qc b/qcsrc/common/mapobjects/trigger/relay_if.qc index 7586bd338..a8855f550 100644 --- a/qcsrc/common/mapobjects/trigger/relay_if.qc +++ b/qcsrc/common/mapobjects/trigger/relay_if.qc @@ -1,4 +1,5 @@ #include "relay_if.qh" + #ifdef SVQC void trigger_relay_if_use(entity this, entity actor, entity trigger) { diff --git a/qcsrc/common/mapobjects/trigger/relay_teamcheck.qc b/qcsrc/common/mapobjects/trigger/relay_teamcheck.qc index 5291f5290..217c0e4b0 100644 --- a/qcsrc/common/mapobjects/trigger/relay_teamcheck.qc +++ b/qcsrc/common/mapobjects/trigger/relay_teamcheck.qc @@ -1,4 +1,5 @@ #include "relay_teamcheck.qh" + #ifdef SVQC void trigger_relay_teamcheck_use(entity this, entity actor, entity trigger) { diff --git a/qcsrc/common/mapobjects/trigger/secret.qc b/qcsrc/common/mapobjects/trigger/secret.qc index e532f713c..e1b1e5531 100644 --- a/qcsrc/common/mapobjects/trigger/secret.qc +++ b/qcsrc/common/mapobjects/trigger/secret.qc @@ -8,13 +8,6 @@ #ifdef SVQC -void secrets_setstatus(entity this) -{ - // TODO: use global stats! - STAT(SECRETS_TOTAL, this) = secrets_total; - STAT(SECRETS_FOUND, this) = secrets_found; -} - /** * A secret has been found (maybe :P) */ @@ -24,21 +17,26 @@ void trigger_secret_touch(entity this, entity toucher) if (!IS_PLAYER(toucher)) return; + EXACTTRIGGER_TOUCH(this, toucher); + // update secrets found counter secrets_found += 1; - //print("Secret found: ", ftos(secret_counter.cnt), "/"); - //print(ftos(secret_counter.count), "\n"); - // centerprint message (multi_touch() doesn't always call centerprint()) - centerprint(toucher, this.message); - this.message = ""; + // message and noise handled by SUB_UseTargets + SUB_UseTargets(this, toucher, toucher); - // handle normal trigger features - multi_touch(this, toucher); // we can't just delete(this) here, because this is a touch function // called while C code is looping through area links... - //delete(this); + settouch(this, func_null); +} + +#if 0 +void trigger_secret_reset(entity this) +{ + secrets_found = 0; + settouch(this, trigger_secret_touch); } +#endif /*QUAKED trigger_secret (.5 .5 .5) ? Variable sized secret trigger. Can be targeted at one or more entities. @@ -61,30 +59,32 @@ spawnfunc(trigger_secret) secrets_total += 1; // add default message - if (this.message == "") + if (!this.message || this.message == "") this.message = "You found a secret!"; // set default sound - if (this.noise == "") - if (!this.sounds) + if ((!this.noise || this.noise == "") && !this.sounds) this.sounds = 1; // misc/secret.wav - // this entity can't be a target itself!!!! - this.targetname = ""; + switch(this.sounds) + { + case 1: this.noise = "misc/secret.wav"; break; + case 2: this.noise = strzone(SND(TALK)); break; + case 3: this.noise = "misc/trigger1.wav"; break; + } - // you can't just shoot a room to find it, can you? - SetResourceExplicit(this, RES_HEALTH, 0); + if(this.noise && this.noise != "") + precache_sound(this.noise); - // a secret can not be delayed + // a secret cannot be delayed this.delay = 0; - // convert this trigger to trigger_once - //this.classname = "trigger_once"; - spawnfunc_trigger_once(this); + EXACTTRIGGER_INIT; - // take over the touch() function, so we can mark secret as found settouch(this, trigger_secret_touch); - // ignore triggering; - this.use = func_null; +// NOTE: old maps don't expect secrets to reset, so enabling resetting can cause issues! +#if 0 + this.reset = trigger_secret_reset; +#endif } #endif diff --git a/qcsrc/common/mapobjects/trigger/secret.qh b/qcsrc/common/mapobjects/trigger/secret.qh index fcc55c395..f2ca25b2a 100644 --- a/qcsrc/common/mapobjects/trigger/secret.qh +++ b/qcsrc/common/mapobjects/trigger/secret.qh @@ -1,19 +1,9 @@ #pragma once -#ifdef SVQC - -/** - * Total number of secrets on the map. - */ -float secrets_total; - -/** - * Total numbe of secrets found on the map. - */ -float secrets_found; +#ifdef SVQC +// Total number of secrets on the map. +int secrets_total; -/** - * update secrets status. - */ -void secrets_setstatus(entity this); +// Total numbe of secrets found on the map. +int secrets_found; #endif diff --git a/qcsrc/common/stats.qh b/qcsrc/common/stats.qh index 9ecac9f7c..5bbc4dd26 100644 --- a/qcsrc/common/stats.qh +++ b/qcsrc/common/stats.qh @@ -3,6 +3,7 @@ #ifdef SVQC #include #include +#include #endif // Full list of all stat constants, included in a single location for easy reference @@ -100,8 +101,8 @@ REGISTER_STAT(VEHICLESTAT_AMMO2, int) REGISTER_STAT(VEHICLESTAT_RELOAD2, int) REGISTER_STAT(VEHICLESTAT_W2MODE, int) REGISTER_STAT(NADE_TIMER, float) -REGISTER_STAT(SECRETS_TOTAL, float) -REGISTER_STAT(SECRETS_FOUND, float) +REGISTER_STAT(SECRETS_TOTAL, int, secrets_total) +REGISTER_STAT(SECRETS_FOUND, int, secrets_found) REGISTER_STAT(RESPAWN_TIME, float) REGISTER_STAT(ROUNDSTARTTIME, float, round_starttime) REGISTER_STAT(MONSTERS_TOTAL, int) diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index 1211e8988..4990ed7ee 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -2267,7 +2267,6 @@ bool PlayerThink(entity this) this.dmg_team = max(0, this.dmg_team - autocvar_g_teamdamage_resetspeed * frametime); } - secrets_setstatus(this); monsters_setstatus(this); return true; -- 2.39.2