]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/triggers.qc
Step 6: complete
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / triggers.qc
index 1ca03fd4fefc819113b7b6aaae62ba1c9009d8aa..0e13a6bdeb77ce0bfeb9698b67f548ce6d2ba261 100644 (file)
@@ -1,11 +1,10 @@
-void SUB_DontUseTargets() { }
+void SUB_DontUseTargets(entity this, entity actor, entity trigger) { }
 
-void() SUB_UseTargets;
+void SUB_UseTargets(entity this, entity actor, entity trigger);
 
-void DelayThink()
-{SELFPARAM();
-       activator = this.enemy;
-       SUB_UseTargets ();
+void DelayThink(entity this)
+{
+       SUB_UseTargets (this, this.enemy, NULL);
        remove(this);
 }
 
@@ -25,7 +24,7 @@ void FixSize(entity e)
 void trigger_init(entity this)
 {
        string m = this.model;
-       WITHSELF(this, WarpZoneLib_ExactTrigger_Init());
+       EXACTTRIGGER_INIT;
        if(m != "")
        {
                precache_model(m);
@@ -42,8 +41,7 @@ void trigger_init(entity this)
 
 void trigger_link(entity this, bool(entity this, entity to, int sendflags) sendfunc)
 {
-       this.SendEntity = SendEntity_self;
-       this.SendEntity3 = sendfunc;
+       setSendEntity(this, sendfunc);
        this.SendFlags = 0xFFFFFF;
 }
 
@@ -93,8 +91,8 @@ void trigger_common_write(entity this, bool withtarget)
 
 #elif defined(CSQC)
 
-void trigger_common_read(bool withtarget)
-{SELFPARAM();
+void trigger_common_read(entity this, bool withtarget)
+{
        int f = ReadByte();
        this.warpzone_isboxy = (f & 1);
 
@@ -171,35 +169,31 @@ SUB_UseTargets
 
 the global "activator" should be set to the entity that initiated the firing.
 
-If self.delay is set, a DelayedUse entity will be created that will actually
+If this.delay is set, a DelayedUse entity will be created that will actually
 do the SUB_UseTargets after that many seconds have passed.
 
-Centerprints any self.message to the activator.
+Centerprints any this.message to the activator.
 
-Removes all entities with a targetname that match self.killtarget,
+Removes all entities with a targetname that match this.killtarget,
 and removes them, so some events can remove other triggers.
 
 Search for (string)targetname in all entities that
-match (string)self.target and call their .use function
+match (string)this.target and call their .use function
 
 ==============================
 */
-void SUB_UseTargets()
-{SELFPARAM();
-       entity t, otemp, act;
-       string s;
-       float i;
-
+void SUB_UseTargets(entity this, entity actor, entity trigger)
+{
 //
 // check for a delay
 //
        if (this.delay)
        {
        // create a temp object to fire at a later time
-               t = new(DelayedUse);
+               entity t = new(DelayedUse);
                t.nextthink = time + this.delay;
-               t.think = DelayThink;
-               t.enemy = activator;
+               setthink(t, DelayThink);
+               t.enemy = actor;
                t.message = this.message;
                t.killtarget = this.killtarget;
                t.target = this.target;
@@ -209,18 +203,19 @@ void SUB_UseTargets()
                return;
        }
 
+       string s;
 
 //
 // print the message
 //
 #ifdef SVQC
        if(this)
-       if(IS_PLAYER(activator) && this.message != "")
-       if(IS_REAL_CLIENT(activator))
+       if(IS_PLAYER(actor) && this.message != "")
+       if(IS_REAL_CLIENT(actor))
        {
-               centerprint(activator, this.message);
+               centerprint(actor, this.message);
                if (this.noise == "")
-                       play2(activator, SND(TALK));
+                       play2(actor, SND(TALK));
        }
 
 //
@@ -229,7 +224,7 @@ void SUB_UseTargets()
        s = this.killtarget;
        if (s != "")
        {
-               for(t = world; (t = find(t, targetname, s)); )
+               for(entity t = world; (t = find(t, targetname, s)); )
                        remove(t);
        }
 #endif
@@ -237,13 +232,11 @@ void SUB_UseTargets()
 //
 // fire targets
 //
-       act = activator;
-       otemp = other;
 
        if(this.target_random)
                RandomSelection_Init();
 
-       for(i = 0; i < 4; ++i)
+       for(int i = 0; i < 4; ++i)
        {
                switch(i)
                {
@@ -257,67 +250,32 @@ void SUB_UseTargets()
                {
                        // Flag to set func_clientwall state
                        // 1 == deactivate, 2 == activate, 0 == do nothing
-                       float aw_flag = this.antiwall_flag;
-                       for(t = world; (t = find(t, targetname, s)); )
-                       if(t.use)
+                       int aw_flag = this.antiwall_flag;
+                       for(entity t = world; (t = find(t, targetname, s)); )
                        {
-                               if(this.target_random)
+                               if(t.use)
                                {
-                                       RandomSelection_Add(t, 0, string_null, 1, 0);
-                               }
-                               else
-                               {
-                                       if (t.classname == "func_clientwall" || t.classname == "func_clientillusionary")
-                                               t.antiwall_flag = aw_flag;
-                                       setself(t);
-                                       other = this;
-                                       activator = act;
-                                       self.use();
+                                       if(this.target_random)
+                                       {
+                                               RandomSelection_Add(t, 0, string_null, 1, 0);
+                                       }
+                                       else
+                                       {
+                                               if (t.classname == "func_clientwall" || t.classname == "func_clientillusionary")
+                                                       t.antiwall_flag = aw_flag;
+
+                                               t.use(t, actor, this);
+                                       }
                                }
                        }
                }
        }
 
        if(this.target_random && RandomSelection_chosen_ent)
-       {
-               setself(RandomSelection_chosen_ent);
-               other = this;
-               activator = act;
-               self.use();
-       }
-
-       activator = act;
-       setself(this);
-       other = otemp;
+               RandomSelection_chosen_ent.use(RandomSelection_chosen_ent, actor, this);
 }
 
-#ifdef CSQC
-void trigger_touch_generic(entity this, void() touchfunc)
+void SUB_UseTargets_self(entity this)
 {
-       entity e;
-       for(e = findradius((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1); e; e = e.chain)
-       if(e.classname == "csqcprojectile")
-       {
-               vector emin = e.absmin, emax = e.absmax;
-               if(this.solid == SOLID_BSP)
-               {
-                       emin -= '1 1 1';
-                       emax += '1 1 1';
-               }
-               if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick
-               if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, e)) // accurate
-               {
-                       other = e;
-                       WITHSELF(this, touchfunc());
-               }
-       }
+       SUB_UseTargets(this, NULL, NULL);
 }
-void trigger_draw_generic(entity this)
-{
-       float dt = time - this.move_time;
-       this.move_time = time;
-       if(dt <= 0) { return; }
-
-       if(this.trigger_touch) { trigger_touch_generic(this, this.trigger_touch); }
-}
-#endif