]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/train.qc
Merge branch 'terencehill/quickmenu_file_example' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / train.qc
index 2b4f67cd023a13bde9ef18027183e13d1bde920f..0f827a60e37e4bdef4c8c031a84c5b927f9c11f7 100644 (file)
@@ -1,12 +1,8 @@
 .float train_wait_turning;
 void() train_next;
 void train_wait()
-{
-       entity oldself;
-       oldself = self;
-       self = self.enemy;
-       SUB_UseTargets();
-       self = oldself;
+{SELFPARAM();
+       WITH(entity, self, self.enemy, SUB_UseTargets());
        self.enemy = world;
 
        // if turning is enabled, the train will turn toward the next point while waiting
@@ -53,7 +49,7 @@ void train_wait()
 }
 
 void train_next()
-{
+{SELFPARAM();
        entity targ, cp = world;
        vector cp_org = '0 0 0';
 
@@ -102,13 +98,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)
@@ -162,19 +160,30 @@ float train_send(entity to, float sf)
 
 void train_link()
 {
-       Net_LinkEntity(self, 0, false, train_send);
+       //Net_LinkEntity(self, 0, false, train_send);
 }
 
-void func_train_find()
+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;
        targ = find(world, targetname, self.target);
        self.target = targ.target;
        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 +196,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);
@@ -200,7 +209,10 @@ void spawnfunc_func_train()
        if (!InitMovingBrushTrigger())
                return;
        self.effects |= EF_LOWPRECISION;
-       
+
+       if(self.spawnflags & 4)
+               self.use = train_use;
+
        if (self.spawnflags & 2)
        {
                self.platmovetype_turn = true;
@@ -210,7 +222,7 @@ void spawnfunc_func_train()
                self.view_ofs = self.mins;
 
        // wait for targets to spawn
-       InitializeEntity(self, func_train_find, INITPRIO_SETLOCATION);
+       InitializeEntity(self, func_train_find, INITPRIO_FINDTARGET);
 
        self.blocked = generic_plat_blocked;
        if(self.dmg && (self.message == ""))
@@ -229,13 +241,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);
 }
 
-void ent_train()
+NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
 {
        float sf = ReadByte();
 
@@ -246,7 +258,7 @@ void ent_train()
                self.spawnflags = ReadByte();
 
                self.model = strzone(ReadString());
-               setmodel(self, self.model);
+               _setmodel(self, self.model);
 
                trigger_common_read(true);
 
@@ -297,8 +309,9 @@ void ent_train()
                //func_train_find();
 
                // but we will need these
-               self.move_nextthink = self.move_ltime + 0.1;
-               self.move_think = train_next;
+               //self.move_nextthink = self.move_ltime + 0.1;
+               //self.move_think = train_next;
+               train_next();
 
                self.move_movetype = MOVETYPE_PUSH;
                self.move_origin = self.origin;
@@ -310,6 +323,8 @@ void ent_train()
        {
                // TODO: make a reset function for trains
        }
+
+       return true;
 }
 
 #endif