]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/train.qc
Add a way to pause a train until triggered again
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / train.qc
index 187fd3f1b97be9174c2bbdf962be42f507c0c104..909b8f5e8b37938f8c68cbae639d5beeaf80417e 100644 (file)
@@ -36,7 +36,17 @@ void train_wait()
                stopsoundto(MSG_BROADCAST, self, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
 #endif
 
-       if(self.wait < 0 || self.train_wait_turning) // no waiting or we already waited while turning
+#ifdef SVQC
+       entity tg = find(world, targetname, self.target);
+       if(tg.spawnflags & 4)
+       {
+               self.use = train_use;
+               self.SUB_THINK = func_null;
+               self.SUB_NEXTTHINK = 0;
+       }
+       else
+#endif
+            if(self.wait < 0 || self.train_wait_turning) // no waiting or we already waited while turning
        {
                self.train_wait_turning = false;
                train_next();
@@ -101,10 +111,12 @@ void train_next()
                _sound(self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTEN_IDLE);
 }
 
+REGISTER_NET_LINKED(ENT_CLIENT_TRAIN)
+
 #ifdef SVQC
 float train_send(entity to, float sf)
 {SELFPARAM();
-       WriteByte(MSG_ENTITY, ENT_CLIENT_TRAIN);
+       WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
        WriteByte(MSG_ENTITY, sf);
 
        if(sf & SF_TRIGGER_INIT)
@@ -115,7 +127,7 @@ float train_send(entity to, float sf)
 
                WriteString(MSG_ENTITY, self.model);
 
-               trigger_common_write(true);
+               trigger_common_write(self, true);
 
                WriteString(MSG_ENTITY, self.curvetarget);
 
@@ -161,6 +173,13 @@ void train_link()
        //Net_LinkEntity(self, 0, false, train_send);
 }
 
+void train_use()
+{
+       self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
+       self.SUB_THINK = train_next;
+       self.use = func_null; // not again
+}
+
 void func_train_find()
 {SELFPARAM();
        entity targ;
@@ -169,8 +188,12 @@ void func_train_find()
        if (self.target == "")
                objerror("func_train_find: no next target");
        SUB_SETORIGIN(self, targ.origin - self.view_ofs);
-       self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
-       self.SUB_THINK = train_next;
+
+       if(!(self.spawnflags & 4))
+       {
+               self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
+               self.SUB_THINK = train_next;
+       }
 
        train_link();
 }
@@ -183,8 +206,8 @@ speed : speed the train moves (can be overridden by each spawnfunc_path_corner)
 target : targetname of first spawnfunc_path_corner (starts here)
 */
 #ifdef SVQC
-void spawnfunc_func_train()
-{SELFPARAM();
+spawnfunc(func_train)
+{
        if (self.noise != "")
                precache_sound(self.noise);
 
@@ -197,6 +220,9 @@ void spawnfunc_func_train()
                return;
        self.effects |= EF_LOWPRECISION;
 
+       if(self.spawnflags & 4)
+               self.use = train_use;
+
        if (self.spawnflags & 2)
        {
                self.platmovetype_turn = true;
@@ -225,14 +251,14 @@ void spawnfunc_func_train()
        // TODO make a reset function for this one
 }
 #elif defined(CSQC)
-void train_draw()
+void train_draw(entity this)
 {
        //Movetype_Physics_NoMatchServer();
-       Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
+       Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
 }
 
-void ent_train()
-{SELFPARAM();
+NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
+{
        float sf = ReadByte();
 
        if(sf & SF_TRIGGER_INIT)
@@ -307,6 +333,8 @@ void ent_train()
        {
                // TODO: make a reset function for trains
        }
+
+       return true;
 }
 
 #endif