]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/train.qc
Propagate this
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / train.qc
index 0de3489381fa2dba5b27b8b6f58fed55f44a1f55..2b27c7355ce5b814bc1ceac5dff541aacee79a4e 100644 (file)
@@ -1,12 +1,11 @@
 .float train_wait_turning;
 void() train_next;
+#ifdef SVQC
+void train_use();
+#endif
 void train_wait()
-{
-       entity oldself;
-       oldself = self;
-       self = self.enemy;
-       SUB_UseTargets();
-       self = oldself;
+{SELFPARAM();
+       WITHSELF(self.enemy, SUB_UseTargets());
        self.enemy = world;
 
        // if turning is enabled, the train will turn toward the next point while waiting
@@ -40,7 +39,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();
@@ -53,7 +62,7 @@ void train_wait()
 }
 
 void train_next()
-{
+{SELFPARAM();
        entity targ, cp = world;
        vector cp_org = '0 0 0';
 
@@ -102,13 +111,15 @@ void train_next()
        }
 
        if(self.noise != "")
-               sound(self, CH_TRIGGER_SINGLE, self.noise, VOL_BASE, ATTEN_IDLE);
+               _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)
-{
-       WriteByte(MSG_ENTITY, ENT_CLIENT_TRAIN);
+{SELFPARAM();
+       WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
        WriteByte(MSG_ENTITY, sf);
 
        if(sf & SF_TRIGGER_INIT)
@@ -119,7 +130,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);
 
@@ -165,7 +176,15 @@ void train_link()
        //Net_LinkEntity(self, 0, false, train_send);
 }
 
-void func_train_find()
+void train_use()
+{
+    SELFPARAM();
+       self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
+       self.SUB_THINK = train_next;
+       self.use = func_null; // not again
+}
+
+void func_train_find(entity this)
 {
        entity targ;
        targ = find(world, targetname, self.target);
@@ -173,8 +192,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();
 }
@@ -187,7 +210,7 @@ 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()
+spawnfunc(func_train)
 {
        if (self.noise != "")
                precache_sound(self.noise);
@@ -201,6 +224,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;
@@ -229,13 +255,13 @@ 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()
+NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
 {
        float sf = ReadByte();
 
@@ -246,7 +272,7 @@ void ent_train()
                self.spawnflags = ReadByte();
 
                self.model = strzone(ReadString());
-               setmodel(self, self.model);
+               _setmodel(self, self.model);
 
                trigger_common_read(true);
 
@@ -311,6 +337,8 @@ void ent_train()
        {
                // TODO: make a reset function for trains
        }
+
+       return true;
 }
 
 #endif