]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/vectormamamam.qc
Merge branch 'master' into terencehill/min_spec_time
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / vectormamamam.qc
index b3e931b3a364f66f7e5389a396dc9fdde2aa3111..61da52acbc483daef7c55c1e9d136000d7ace990 100644 (file)
@@ -1,3 +1,4 @@
+#include "vectormamamam.qh"
 #ifdef SVQC
 // reusing some fields havocbots declared
 .entity wp00, wp01, wp02, wp03;
@@ -5,20 +6,20 @@
 .float targetfactor, target2factor, target3factor, target4factor;
 .vector targetnormal, target2normal, target3normal, target4normal;
 
-vector func_vectormamamam_origin(entity o, float t)
+vector func_vectormamamam_origin(entity o, float timestep)
 {
        vector v, p;
-       float f;
+       float flags;
        entity e;
 
-       f = o.spawnflags;
+       flags = o.spawnflags;
        v = '0 0 0';
 
        e = o.wp00;
        if(e)
        {
-               p = e.origin + t * e.velocity;
-               if(f & 1)
+               p = e.origin + timestep * e.velocity;
+               if(flags & PROJECT_ON_TARGETNORMAL)
                        v = v + (p * o.targetnormal) * o.targetnormal * o.targetfactor;
                else
                        v = v + (p - (p * o.targetnormal) * o.targetnormal) * o.targetfactor;
@@ -27,8 +28,8 @@ vector func_vectormamamam_origin(entity o, float t)
        e = o.wp01;
        if(e)
        {
-               p = e.origin + t * e.velocity;
-               if(f & 2)
+               p = e.origin + timestep * e.velocity;
+               if(flags & PROJECT_ON_TARGET2NORMAL)
                        v = v + (p * o.target2normal) * o.target2normal * o.target2factor;
                else
                        v = v + (p - (p * o.target2normal) * o.target2normal) * o.target2factor;
@@ -37,8 +38,8 @@ vector func_vectormamamam_origin(entity o, float t)
        e = o.wp02;
        if(e)
        {
-               p = e.origin + t * e.velocity;
-               if(f & 4)
+               p = e.origin + timestep * e.velocity;
+               if(flags & PROJECT_ON_TARGET3NORMAL)
                        v = v + (p * o.target3normal) * o.target3normal * o.target3factor;
                else
                        v = v + (p - (p * o.target3normal) * o.target3normal) * o.target3factor;
@@ -47,8 +48,8 @@ vector func_vectormamamam_origin(entity o, float t)
        e = o.wp03;
        if(e)
        {
-               p = e.origin + t * e.velocity;
-               if(f & 8)
+               p = e.origin + timestep * e.velocity;
+               if(flags & PROJECT_ON_TARGET4NORMAL)
                        v = v + (p * o.target4normal) * o.target4normal * o.target4factor;
                else
                        v = v + (p - (p * o.target4normal) * o.target4normal) * o.target4factor;
@@ -59,34 +60,34 @@ vector func_vectormamamam_origin(entity o, float t)
 
 void func_vectormamamam_controller_think(entity this)
 {
-       self.nextthink = time + 0.1;
+       this.nextthink = time + vectormamamam_timestep;
 
-       if(self.owner.active != ACTIVE_ACTIVE)
+       if(this.owner.active != ACTIVE_ACTIVE)
        {
-               self.owner.velocity = '0 0 0';
+               this.owner.velocity = '0 0 0';
                return;
        }
 
-       if(self.owner.classname == "func_vectormamamam") // don't brake stuff if the func_vectormamamam was killtarget'ed
-               self.owner.velocity = (self.owner.destvec + func_vectormamamam_origin(self.owner, 0.1) - self.owner.origin) * 10;
+       if(this.owner.classname == "func_vectormamamam") // don't brake stuff if the func_vectormamamam was killtarget'ed
+               this.owner.velocity = (this.owner.destvec + func_vectormamamam_origin(this.owner, vectormamamam_timestep) - this.owner.origin) * 10;
 }
 
 void func_vectormamamam_findtarget(entity this)
 {
        if(this.target != "")
-               this.wp00 = find(world, targetname, this.target);
+               this.wp00 = find(NULL, targetname, this.target);
 
        if(this.target2 != "")
-               this.wp01 = find(world, targetname, this.target2);
+               this.wp01 = find(NULL, targetname, this.target2);
 
        if(this.target3 != "")
-               this.wp02 = find(world, targetname, this.target3);
+               this.wp02 = find(NULL, targetname, this.target3);
 
        if(this.target4 != "")
-               this.wp03 = find(world, targetname, this.target4);
+               this.wp03 = find(NULL, targetname, this.target4);
 
        if(!this.wp00 && !this.wp01 && !this.wp02 && !this.wp03)
-               objerror("No reference entity found, so there is nothing to move. Aborting.");
+               objerror(this, "No reference entity found, so there is nothing to move. Aborting.");
 
        this.destvec = this.origin - func_vectormamamam_origin(this, 0);
 
@@ -97,12 +98,45 @@ void func_vectormamamam_findtarget(entity this)
        setthink(controller, func_vectormamamam_controller_think);
 }
 
+void func_vectormamamam_setactive(entity this, int astate)
+{
+       if (astate == ACTIVE_TOGGLE)
+       {
+               if(this.active == ACTIVE_ACTIVE)
+                       this.active = ACTIVE_NOT;
+               else
+                       this.active = ACTIVE_ACTIVE;
+       }
+       else
+               this.active = astate;
+
+       if(this.active  == ACTIVE_NOT)
+       {
+               stopsound(this, CH_TRIGGER_SINGLE);
+       }
+       else
+       {
+               if(this.noise && this.noise != "")
+               {
+                       _sound(this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
+               }
+       }
+}
+
+void func_vectormamamam_init_for_player(entity this, entity player)
+{
+       if (this.noise && this.noise != "" && this.active == ACTIVE_ACTIVE && IS_REAL_CLIENT(player))
+       {
+               msg_entity = player;
+               soundto(MSG_ONE, this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
+       }
+}
+
 spawnfunc(func_vectormamamam)
 {
        if (this.noise != "")
        {
                precache_sound(this.noise);
-               soundto(MSG_INIT, this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
        }
 
        if(!this.targetfactor)
@@ -117,19 +151,19 @@ spawnfunc(func_vectormamamam)
        if(!this.target4factor)
                this.target4factor = 1;
 
-       if(vlen(this.targetnormal))
+       if(this.targetnormal)
                this.targetnormal = normalize(this.targetnormal);
 
-       if(vlen(this.target2normal))
+       if(this.target2normal)
                this.target2normal = normalize(this.target2normal);
 
-       if(vlen(this.target3normal))
+       if(this.target3normal)
                this.target3normal = normalize(this.target3normal);
 
-       if(vlen(this.target4normal))
+       if(this.target4normal)
                this.target4normal = normalize(this.target4normal);
 
-       this.blocked = generic_plat_blocked;
+       setblocked(this, generic_plat_blocked);
        if(this.dmg && (this.message == ""))
                this.message = " was squished";
     if(this.dmg && (this.message == ""))
@@ -138,20 +172,22 @@ spawnfunc(func_vectormamamam)
                this.dmgtime = 0.25;
        this.dmgtime2 = time;
 
-       if(this.netname == "")
-               this.netname = "1 0 0 0 1";
-
        if (!InitMovingBrushTrigger(this))
                return;
 
        // wait for targets to spawn
-       this.SUB_NEXTTHINK = this.SUB_LTIME + 999999999;
-       SUB_THINK(this, SUB_NullThink); // for PushMove
+       this.nextthink = this.ltime + 999999999;
+       setthink(this, SUB_NullThink); // for PushMove
 
        // Savage: Reduce bandwith, critical on e.g. nexdm02
        this.effects |= EF_LOWPRECISION;
 
-       this.active = ACTIVE_ACTIVE;
+       this.setactive = func_vectormamamam_setactive;
+       this.setactive(this, ACTIVE_ACTIVE);
+
+       // maybe send sound to new players
+       IL_PUSH(g_initforplayer, this);
+       this.init_for_player = func_vectormamamam_init_for_player;
 
        InitializeEntity(this, func_vectormamamam_findtarget, INITPRIO_FINDTARGET);
 }