Refactor trigger_secret to be standalone (not using parts of trigger_multiple and...
authorMario <mario.mario@y7mail.com>
Fri, 31 Jul 2020 09:30:30 +0000 (19:30 +1000)
committerMario <mario.mario@y7mail.com>
Fri, 31 Jul 2020 09:30:30 +0000 (19:30 +1000)
qcsrc/common/mapobjects/trigger/multi.qc
qcsrc/common/mapobjects/trigger/relay_activators.qc
qcsrc/common/mapobjects/trigger/relay_if.qc
qcsrc/common/mapobjects/trigger/relay_teamcheck.qc
qcsrc/common/mapobjects/trigger/secret.qc
qcsrc/common/mapobjects/trigger/secret.qh
qcsrc/common/stats.qh
qcsrc/server/client.qc

index df915a6..9ce5f52 100644 (file)
@@ -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)
index 18c2a40..2c891c2 100644 (file)
@@ -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
index 7586bd3..a8855f5 100644 (file)
@@ -1,4 +1,5 @@
 #include "relay_if.qh"
+
 #ifdef SVQC
 void trigger_relay_if_use(entity this, entity actor, entity trigger)
 {
index 5291f52..217c0e4 100644 (file)
@@ -1,4 +1,5 @@
 #include "relay_teamcheck.qh"
+
 #ifdef SVQC
 void trigger_relay_teamcheck_use(entity this, entity actor, entity trigger)
 {
index e532f71..e1b1e55 100644 (file)
@@ -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
index fcc55c3..f2ca25b 100644 (file)
@@ -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
index 9ecac9f..5bbc4dd 100644 (file)
@@ -3,6 +3,7 @@
 #ifdef SVQC
 #include <server/autocvars.qh>
 #include <server/client.qh>
+#include <common/mapobjects/trigger/secret.qh>
 #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)
index 1211e89..4990ed7 100644 (file)
@@ -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;