]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/t_plats.qc
Fix some important mistakes in the last commit
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / t_plats.qc
index cd0ce71b6ac4e33d3050f604c9698939dcaca840..f27bb2b9ff617d14a7c9973b66591c5d47cd81a2 100644 (file)
@@ -182,7 +182,43 @@ void plat_reset()
        }
 }
 
-void spawnfunc_path_corner() { }
+.float platmovetype_start_default, platmovetype_end_default;
+float set_platmovetype(entity e, string s)
+{
+       // sets platmovetype_start and platmovetype_end based on a string consisting of two values
+
+       float n;
+       n = tokenize_console(s);
+       if(n > 0)
+               e.platmovetype_start = stof(argv(0));
+       else
+               e.platmovetype_start = 0;
+
+       if(n > 1)
+               e.platmovetype_end = stof(argv(1));
+       else
+               e.platmovetype_end = e.platmovetype_start;
+
+       if(n > 2)
+               if(argv(2) == "force")
+                       return TRUE; // no checking, return immediately
+
+       if(!cubic_speedfunc_is_sane(e.platmovetype_start, e.platmovetype_end))
+       {
+               objerror("Invalid platform move type; platform would go in reverse, which is not allowed.");
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+void spawnfunc_path_corner()
+{
+       // setup values for overriding train movement
+       // if a second value does not exist, both start and end speeds are the single value specified
+       if(!set_platmovetype(self, self.platmovetype))
+               return;
+}
 void spawnfunc_func_plat()
 {
        if (self.sounds == 0)
@@ -255,22 +291,55 @@ void spawnfunc_func_plat()
 void() train_next;
 void train_wait()
 {
-       // if using bezier curves and turning is enabled, the train will turn toward the next point while waiting
-       if(!self.train_wait_turning)
-       if (self.spawnflags & 1 && self.bezier_turn && self.wait >= 0)
+       entity oldself;
+       oldself = self;
+       self = self.enemy;
+       SUB_UseTargets();
+       self = oldself;
+       self.enemy = world;
+
+       // if turning is enabled, the train will turn toward the next point while waiting
+       if(self.bezier_turn && !self.train_wait_turning)
        {
                entity targ;
+               vector org;
                targ = find(world, targetname, self.target);
-               SUB_CalcAngleMove(targ.origin, TSPEED_TIME, self.ltime + self.wait, train_wait);
-               self.train_wait_turning = TRUE;
-               return;
+               if(self.spawnflags & 1) // bezier curves movement
+               {
+                       org = normalize(targ.origin);
+                       if(self.wait >= 0)
+                       {
+                               SUB_CalcAngleMove(org, TSPEED_TIME, self.ltime - time + self.wait, train_wait);
+                               self.train_wait_turning = TRUE;
+                               return;
+                       }
+                       else
+                       {
+                               self.angles = vectoangles(targ.origin - self.origin);
+                       }
+               }
+               else
+               {
+                       org = normalize(targ.origin);
+                       if(self.wait >= 0)
+                       {
+                               SUB_CalcAngleMove(org, TSPEED_TIME, self.ltime - time + self.wait, train_wait);
+                               self.train_wait_turning = TRUE;
+                               return;
+                       }
+                       else
+                       {
+                               self.angles = vectoangles(targ.origin - self.origin);
+                       }
+               }
        }
 
        if(self.noise != "")
                stopsoundto(MSG_BROADCAST, self, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
 
-       if(self.wait < 0)
+       if(self.wait < 0 || self.train_wait_turning) // no waiting or we already waited while turning
        {
+               self.train_wait_turning = FALSE;
                train_next();
        }
        else
@@ -278,14 +347,6 @@ void train_wait()
                self.think = train_next;
                self.nextthink = self.ltime + self.wait;
        }
-
-       entity oldself;
-       oldself = self;
-       self = self.enemy;
-       SUB_UseTargets();
-       self = oldself;
-       self.enemy = world;
-       self.train_wait_turning = FALSE;
 }
 
 void train_next()
@@ -297,12 +358,13 @@ void train_next()
        self.target = targ.target;
        if (self.spawnflags & 1)
        {
-               cp = find(world, target, targ.targetname); // get the previous corner first
-               cp = find(world, targetname, cp.curve); // now get its second target (the control point)
-               if(cp.targetname == "")
-                       cp_org = targ.origin - self.mins; // no control point found, assume a straight line to the destination
+               if(targ.curve)
+               {
+                       cp = find(world, targetname, targ.curve); // get its second target (the control point)
+                       cp_org = cp.origin - self.mins; // no control point found, assume a straight line to the destination
+               }
                else
-                       cp_org = cp.origin - self.mins;
+                       cp = world; // no cp
        }
        if (!self.target)
                objerror("train_next: no next target");
@@ -310,16 +372,29 @@ void train_next()
        if (!self.wait)
                self.wait = 0.1;
 
+       if(targ.platmovetype)
+       {
+               // this path_corner contains a movetype overrider, apply it
+               self.platmovetype_start = targ.platmovetype_start;
+               self.platmovetype_end = targ.platmovetype_end;
+       }
+       else
+       {
+               // this path_corner doesn't contain a movetype overrider, use the train's defaults
+               self.platmovetype_start = self.platmovetype_start_default;
+               self.platmovetype_end = self.platmovetype_end_default;
+       }
+
        if (targ.speed)
        {
-               if (self.spawnflags & 1)
+               if (cp)
                        SUB_CalcMove_Bezier(cp_org, targ.origin - self.mins, TSPEED_LINEAR, targ.speed, train_wait);
                else
                        SUB_CalcMove(targ.origin - self.mins, TSPEED_LINEAR, targ.speed, train_wait);
        }
        else
        {
-               if (self.spawnflags & 1)
+               if (cp)
                        SUB_CalcMove_Bezier(cp_org, targ.origin - self.mins, TSPEED_LINEAR, self.speed, train_wait);
                else
                        SUB_CalcMove(targ.origin - self.mins, TSPEED_LINEAR, self.speed, train_wait);
@@ -374,6 +449,11 @@ void spawnfunc_func_train()
                self.dmgtime = 0.25;
        self.dmgtime2 = time;
 
+       if(!set_platmovetype(self, self.platmovetype))
+               return;
+       self.platmovetype_start_default = self.platmovetype_start;
+       self.platmovetype_end_default = self.platmovetype_end;
+
        // TODO make a reset function for this one
 }