]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add a function to skip certain target fields when using an entity's targets so they...
authorMario <mario.mario@y7mail.com>
Tue, 14 Jan 2020 21:53:24 +0000 (07:53 +1000)
committerMario <mario.mario@y7mail.com>
Tue, 14 Jan 2020 21:53:24 +0000 (07:53 +1000)
qcsrc/common/mapobjects/triggers.qc
qcsrc/common/mapobjects/triggers.qh
qcsrc/lib/warpzone/server.qc
xonotic-server.cfg

index 9a7181d3a2250a530466a1d3dcbf59a9e9d1f0d8..27ffead9c7582bed0e81d63e1c99c926dc0d7980 100644 (file)
@@ -235,7 +235,7 @@ match (string)this.target and call their .use function
 ==============================
 */
 
-void SUB_UseTargets_Ex(entity this, entity actor, entity trigger, bool preventReuse)
+void SUB_UseTargets_Ex(entity this, entity actor, entity trigger, bool preventReuse, int skiptargets)
 {
 //
 // check for a delay
@@ -249,10 +249,10 @@ void SUB_UseTargets_Ex(entity this, entity actor, entity trigger, bool preventRe
                t.enemy = actor;
                t.message = this.message;
                t.killtarget = this.killtarget;
-               t.target = this.target;
-               t.target2 = this.target2;
-               t.target3 = this.target3;
-               t.target4 = this.target4;
+               if(!(skiptargets & BIT(1))) t.target = this.target;
+               if(!(skiptargets & BIT(2))) t.target2 = this.target2;
+               if(!(skiptargets & BIT(3))) t.target3 = this.target3;
+               if(!(skiptargets & BIT(4))) t.target4 = this.target4;
                t.antiwall_flag = this.antiwall_flag;
                return;
        }
@@ -292,6 +292,8 @@ void SUB_UseTargets_Ex(entity this, entity actor, entity trigger, bool preventRe
 
        for(int i = 0; i < 4; ++i)
        {
+               if(skiptargets & BIT(i + 1))
+                       continue;
                switch(i)
                {
                        default:
@@ -329,5 +331,6 @@ void SUB_UseTargets_Ex(entity this, entity actor, entity trigger, bool preventRe
        }
 }
 
-void SUB_UseTargets(entity this, entity actor, entity trigger) { SUB_UseTargets_Ex(this, actor, trigger, false); }
-void SUB_UseTargets_PreventReuse(entity this, entity actor, entity trigger) { SUB_UseTargets_Ex(this, actor, trigger, true); }
+void SUB_UseTargets(entity this, entity actor, entity trigger) { SUB_UseTargets_Ex(this, actor, trigger, false, 0); }
+void SUB_UseTargets_PreventReuse(entity this, entity actor, entity trigger) { SUB_UseTargets_Ex(this, actor, trigger, true, 0); }
+void SUB_UseTargets_SkipTargets(entity this, entity actor, entity trigger, int skiptargets) { SUB_UseTargets_Ex(this, actor, trigger, false, skiptargets); }
index b9baf63f1c70ed30fcaaaf89559d298b45c93084..797c9767f6a084271f6b4ae64327d9ce8650caf6 100644 (file)
@@ -26,6 +26,10 @@ void SUB_UseTargets(entity this, entity actor, entity trigger);
 
 void SUB_UseTargets_PreventReuse(entity this, entity actor, entity trigger);
 
+// allow excluding certain .target* fields without needing to nullify them
+// use BIT(1) through BIT(4)
+void SUB_UseTargets_SkipTargets(entity this, entity actor, entity trigger, int skiptargets);
+
 void generic_setactive(entity this, int act);
 // generic methods for netlinked entities
 void generic_netlinked_reset(entity this);
index 0244b40a9d724c33713d95e4b694cce4b6f84849..66ee6b133c22b2ef98cc1e1e4aae614ed21ae79d 100644 (file)
        #include <server/utils.qh>
 #endif
 
+#ifdef SVQC
+bool autocvar_sv_warpzone_allow_selftarget;
+#endif
+
 #ifdef WARPZONELIB_KEEPDEBUG
 #define WARPZONELIB_REMOVEHACK
 #endif
@@ -213,19 +217,8 @@ void WarpZone_Touch(entity this, entity toucher)
        if(WarpZone_Teleport(this, toucher, f, 0))
        {
 #ifdef SVQC
-               string save1, save2;
-
-               save1 = this.target; this.target = string_null;
-               save2 = this.target3; this.target3 = string_null;
-               SUB_UseTargets(this, toucher, toucher); // use toucher too?
-               if (!this.target) this.target = save1;
-               if (!this.target3) this.target3 = save2;
-
-               save1 = this.target; this.target = string_null;
-               save2 = this.target2; this.target2 = string_null;
-               SUB_UseTargets(this.enemy, toucher, toucher); // use toucher too?
-               if (!this.target) this.target = save1;
-               if (!this.target2) this.target2 = save2;
+               SUB_UseTargets_SkipTargets(this, toucher, toucher, BIT(1) | BIT(3)); // use toucher too?
+               SUB_UseTargets_SkipTargets(this.enemy, toucher, toucher, BIT(1) | BIT(2)); // use toucher too?
 #endif
        }
        else
@@ -369,19 +362,8 @@ float WarpZone_CheckProjectileImpact(entity player)
        player.velocity = player.warpzone_oldvelocity;
        if(WarpZone_Teleport(wz, player, 0, 1))
        {
-               string save1, save2;
-
-               save1 = wz.target; wz.target = string_null;
-               save2 = wz.target3; wz.target3 = string_null;
-               SUB_UseTargets(wz, player, player);
-               if (!wz.target) wz.target = save1;
-               if (!wz.target3) wz.target3 = save2;
-
-               save1 = wz.enemy.target; wz.enemy.target = string_null;
-               save2 = wz.enemy.target2; wz.enemy.target2 = string_null;
-               SUB_UseTargets(wz.enemy, player, player);
-               if (!wz.enemy.target) wz.enemy.target = save1;
-               if (!wz.enemy.target2) wz.enemy.target2 = save2;
+               SUB_UseTargets_SkipTargets(wz, player, player, BIT(1) | BIT(3));
+               SUB_UseTargets_SkipTargets(wz.enemy, player, player, BIT(1) | BIT(2));
        }
        else
        {
@@ -648,7 +630,8 @@ void WarpZone_InitStep_FindTarget(entity this)
        // this way only one of the two ents needs to target
        if(this.target != "")
        {
-               this.enemy = this; // so the if(!e.enemy) check also skips this, saves one IF
+               if(!autocvar_sv_warpzone_allow_selftarget)
+                       this.enemy = this; // so the if(!e.enemy) check also skips this, saves one IF
 
                e2 = NULL;
                for(e = NULL, i = 0; (e = find(e, targetname, this.target)); )
index 6e040d5b0f747abd3055f21cacfb5d1178f301e9..3db80bb337c796c3c42bd3544bacb6d1ee2cd3e2 100644 (file)
@@ -570,3 +570,5 @@ set sv_damagetext 2 "<= 0: disabled, >= 1: visible to spectators, >= 2: visible
 
 set sv_showfps 5 "Show player's FPS counters in the scoreboard. This setting acts as a delay in seconds between updates"
 set autocvar_sv_doors_always_open 0 "If set to 1 don't close doors which after they were open"
+
+set sv_warpzone_allow_selftarget 0 "do not touch"