]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/g_subs.qc
Merge branch 'master' of ssh://git.xonotic.org/xonotic-data.pk3dir into savagex/plat...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_subs.qc
index 47f3a5a699b8daa78b7d9a896304a5ae681a6a0c..79369b74b9553dbcca2c0859560d46341c7b6111 100644 (file)
@@ -177,10 +177,51 @@ void SUB_CalcMoveDone (void)
                self.think1 ();
 }
 
                self.think1 ();
 }
 
+void SUB_CalcMove_controller_think (void)
+{
+       entity oldself;
+       float traveltime;
+       float phasepos;
+       float nexttick;
+       vector delta;
+       vector veloc;
+       vector nextpos;
+       if(time < self.animstate_endtime) {
+               delta = self.destvec;
+               nexttick = time + sys_frametime;
+
+               if(nexttick < self.animstate_endtime) {
+                       traveltime = self.animstate_endtime - self.animstate_starttime;
+                       phasepos = (nexttick - self.animstate_starttime) / traveltime; // range: [0, 1]
+                       phasepos = 3.14159265 + (phasepos * 3.14159265); // range: [pi, 2pi]
+                       phasepos = cos(phasepos); // cos [pi, 2pi] is in [-1, 1]
+                       phasepos = phasepos + 1; // correct range to [0, 2]
+                       phasepos = phasepos / 2; // correct range to [0, 1]
+                       nextpos = self.origin + (delta * phasepos);
+
+                       veloc = nextpos - self.owner.origin;
+                       veloc = veloc * (1 / sys_frametime); // so it arrives for the next frame
+
+               } else {
+                       veloc = self.finaldest - self.owner.origin;
+                       veloc = veloc * (1 / sys_frametime); // so it arrives for the next frame
+               }
+               self.owner.velocity = veloc;
+               self.nextthink = nexttick;
+       } else {
+               oldself = self;
+               self.owner.think = self.think1;
+               self = self.owner;
+               remove(oldself);
+               self.think();
+       }
+}
+
 void SUB_CalcMove (vector tdest, float tspeed, void() func)
 {
        vector  delta;
        float   traveltime;
 void SUB_CalcMove (vector tdest, float tspeed, void() func)
 {
        vector  delta;
        float   traveltime;
+       entity controller;
 
        if (!tspeed)
                objerror ("No speed is defined!");
 
        if (!tspeed)
                objerror ("No speed is defined!");
@@ -206,9 +247,34 @@ void SUB_CalcMove (vector tdest, float tspeed, void() func)
                return;
        }
 
                return;
        }
 
-       self.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
+       // very short animations don't really show off the effect
+       // of controlled animation, so let's just use linear movement
+       if (traveltime < 0.15)
+       {
+               self.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
+               self.nextthink = self.ltime + traveltime;
+               return;
+       }
 
 
+       controller = spawn();
+       controller.classname = "SUB_CalcMove_controller";
+       controller.owner = self;
+       controller.origin = self.origin; // starting point
+       controller.finaldest = (tdest + '0 0 1'); // where do we want to end? Offset to overshoot a bit.
+       controller.destvec = delta;
+       controller.animstate_starttime = time;
+       controller.animstate_endtime = time + traveltime;
+       controller.think = SUB_CalcMove_controller_think;
+       controller.think1 = self.think;
+
+       // the thinking is now done by the controller
+       self.think = SUB_Null;
        self.nextthink = self.ltime + traveltime;
        self.nextthink = self.ltime + traveltime;
+       
+       // invoke controller
+       self = controller;
+       self.think();
+       self = self.owner;
 }
 
 void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeed, void() func)
 }
 
 void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeed, void() func)
@@ -698,6 +764,33 @@ void LODmodel_attach()
                        SetCustomizer(self, LOD_customize, LOD_uncustomize);
 }
 
                        SetCustomizer(self, LOD_customize, LOD_uncustomize);
 }
 
+void ApplyMinMaxScaleAngles(entity e)
+{
+       if(e.angles_x != 0 || e.angles_z != 0 || self.avelocity_x != 0 || self.avelocity_z != 0) // "weird" rotation
+       {
+               e.maxs = '1 1 1' * vlen(
+                       '1 0 0' * max(-e.mins_x, e.maxs_x) +
+                       '0 1 0' * max(-e.mins_y, e.maxs_y) +
+                       '0 0 1' * max(-e.mins_z, e.maxs_z)
+               );
+               e.mins = -e.maxs;
+       }
+       else if(e.angles_y != 0 || self.avelocity_y != 0) // yaw only is a bit better
+       {
+               e.maxs_x = vlen(
+                       '1 0 0' * max(-e.mins_x, e.maxs_x) +
+                       '0 1 0' * max(-e.mins_y, e.maxs_y)
+               );
+               e.maxs_y = e.maxs_x;
+               e.mins_x = -e.maxs_x;
+               e.mins_y = -e.maxs_x;
+       }
+       if(e.scale)
+               setsize(e, e.mins * e.scale, e.maxs * e.scale);
+       else
+               setsize(e, e.mins, e.maxs);
+}
+
 void SetBrushEntityModel()
 {
        if(self.model != "")
 void SetBrushEntityModel()
 {
        if(self.model != "")
@@ -707,10 +800,7 @@ void SetBrushEntityModel()
                InitializeEntity(self, LODmodel_attach, INITPRIO_FINDTARGET);
        }
        setorigin(self, self.origin);
                InitializeEntity(self, LODmodel_attach, INITPRIO_FINDTARGET);
        }
        setorigin(self, self.origin);
-       if(self.scale)
-               setsize(self, self.mins * self.scale, self.maxs * self.scale);
-       else
-               setsize(self, self.mins, self.maxs);
+       ApplyMinMaxScaleAngles(self);
 }
 
 void SetBrushEntityModelNoLOD()
 }
 
 void SetBrushEntityModelNoLOD()
@@ -721,10 +811,7 @@ void SetBrushEntityModelNoLOD()
                setmodel(self, self.model); // no precision needed
        }
        setorigin(self, self.origin);
                setmodel(self, self.model); // no precision needed
        }
        setorigin(self, self.origin);
-       if(self.scale)
-               setsize(self, self.mins * self.scale, self.maxs * self.scale);
-       else
-               setsize(self, self.mins, self.maxs);
+       ApplyMinMaxScaleAngles(self);
 }
 
 /*
 }
 
 /*