]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/train.qc
Remove selfparam from triggers
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / train.qc
index 65414548b2e27f3926e41d5d4c3ad6416db7c568..18b8d083416541da0cf310aedd7b8aca1085e329 100644 (file)
@@ -1,8 +1,11 @@
 .float train_wait_turning;
-void() train_next;
-void train_wait()
-{SELFPARAM();
-       WITH(entity, self, self.enemy, SUB_UseTargets());
+void train_next(entity this);
+#ifdef SVQC
+void train_use(entity this, entity actor, entity trigger);
+#endif
+void train_wait(entity this)
+{
+       SUB_UseTargets(this.enemy, NULL, NULL);
        self.enemy = world;
 
        // if turning is enabled, the train will turn toward the next point while waiting
@@ -24,9 +27,9 @@ void train_wait()
                ang_x = -ang_x; // flip up / down orientation
 
                if(self.wait > 0) // slow turning
-                       SUB_CalcAngleMove(ang, TSPEED_TIME, self.SUB_LTIME - time + self.wait, train_wait);
+                       SUB_CalcAngleMove(self, ang, TSPEED_TIME, self.SUB_LTIME - time + self.wait, train_wait);
                else // instant turning
-                       SUB_CalcAngleMove(ang, TSPEED_TIME, 0.0000001, train_wait);
+                       SUB_CalcAngleMove(self, ang, TSPEED_TIME, 0.0000001, train_wait);
                self.train_wait_turning = true;
                return;
        }
@@ -36,20 +39,30 @@ 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;
+               SUB_THINK(self, 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();
+               train_next(self);
        }
        else
        {
-               self.SUB_THINK = train_next;
+               SUB_THINK(self, train_next);
                self.SUB_NEXTTHINK = self.SUB_LTIME + self.wait;
        }
 }
 
-void train_next()
-{SELFPARAM();
+void train_next(entity this)
+{
        entity targ, cp = world;
        vector cp_org = '0 0 0';
 
@@ -85,26 +98,28 @@ void train_next()
        if (targ.speed)
        {
                if (cp)
-                       SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
+                       SUB_CalcMove_Bezier(self, cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
                else
-                       SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
+                       SUB_CalcMove(self, targ.origin - self.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
        }
        else
        {
                if (cp)
-                       SUB_CalcMove_Bezier(cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
+                       SUB_CalcMove_Bezier(self, cp_org, targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
                else
-                       SUB_CalcMove(targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
+                       SUB_CalcMove(self, targ.origin - self.view_ofs, TSPEED_LINEAR, self.speed, train_wait);
        }
 
        if(self.noise != "")
                _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);
+float train_send(entity this, entity to, float sf)
+{
+       WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
        WriteByte(MSG_ENTITY, sf);
 
        if(sf & SF_TRIGGER_INIT)
@@ -115,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);
 
@@ -161,15 +176,15 @@ void train_link()
        //Net_LinkEntity(self, 0, false, train_send);
 }
 
-void train_use()
+void train_use(entity this, entity actor, entity trigger)
 {
-       self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
-       self.SUB_THINK = train_next;
-       self.use = func_null; // not again
+       this.SUB_NEXTTHINK = this.SUB_LTIME + 1;
+       SUB_THINK(this, train_next);
+       this.use = func_null; // not again
 }
 
-void func_train_find()
-{SELFPARAM();
+void func_train_find(entity this)
+{
        entity targ;
        targ = find(world, targetname, self.target);
        self.target = targ.target;
@@ -180,7 +195,7 @@ void func_train_find()
        if(!(self.spawnflags & 4))
        {
                self.SUB_NEXTTHINK = self.SUB_LTIME + 1;
-               self.SUB_THINK = train_next;
+               SUB_THINK(self, train_next);
        }
 
        train_link();
@@ -196,45 +211,45 @@ target : targetname of first spawnfunc_path_corner (starts here)
 #ifdef SVQC
 spawnfunc(func_train)
 {
-       if (self.noise != "")
-               precache_sound(self.noise);
+       if (this.noise != "")
+               precache_sound(this.noise);
 
-       if (self.target == "")
+       if (this.target == "")
                objerror("func_train without a target");
-       if (!self.speed)
-               self.speed = 100;
+       if (!this.speed)
+               this.speed = 100;
 
-       if (!InitMovingBrushTrigger())
+       if (!InitMovingBrushTrigger(this))
                return;
-       self.effects |= EF_LOWPRECISION;
+       this.effects |= EF_LOWPRECISION;
 
-       if(self.spawnflags & 4)
-               self.use = train_use;
+       if(this.spawnflags & 4)
+               this.use = train_use;
 
-       if (self.spawnflags & 2)
+       if (this.spawnflags & 2)
        {
-               self.platmovetype_turn = true;
-               self.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
+               this.platmovetype_turn = true;
+               this.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
        }
        else
-               self.view_ofs = self.mins;
+               this.view_ofs = this.mins;
 
        // wait for targets to spawn
-       InitializeEntity(self, func_train_find, INITPRIO_FINDTARGET);
-
-       self.blocked = generic_plat_blocked;
-       if(self.dmg && (self.message == ""))
-               self.message = " was squished";
-    if(self.dmg && (self.message2 == ""))
-               self.message2 = "was squished by";
-       if(self.dmg && (!self.dmgtime))
-               self.dmgtime = 0.25;
-       self.dmgtime2 = time;
-
-       if(!set_platmovetype(self, self.platmovetype))
+       InitializeEntity(this, func_train_find, INITPRIO_FINDTARGET);
+
+       this.blocked = generic_plat_blocked;
+       if(this.dmg && (this.message == ""))
+               this.message = " was squished";
+    if(this.dmg && (this.message2 == ""))
+               this.message2 = "was squished by";
+       if(this.dmg && (!this.dmgtime))
+               this.dmgtime = 0.25;
+       this.dmgtime2 = time;
+
+       if(!set_platmovetype(this, this.platmovetype))
                return;
-       self.platmovetype_start_default = self.platmovetype_start;
-       self.platmovetype_end_default = self.platmovetype_end;
+       this.platmovetype_start_default = this.platmovetype_start;
+       this.platmovetype_end_default = this.platmovetype_end;
 
        // TODO make a reset function for this one
 }
@@ -242,85 +257,87 @@ spawnfunc(func_train)
 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)
        {
-               self.platmovetype = strzone(ReadString());
-               self.platmovetype_turn = ReadByte();
-               self.spawnflags = ReadByte();
+               this.platmovetype = strzone(ReadString());
+               this.platmovetype_turn = ReadByte();
+               this.spawnflags = ReadByte();
 
-               self.model = strzone(ReadString());
-               _setmodel(self, self.model);
+               this.model = strzone(ReadString());
+               _setmodel(this, this.model);
 
-               trigger_common_read(true);
+               trigger_common_read(this, true);
 
-               self.curvetarget = strzone(ReadString());
+               this.curvetarget = strzone(ReadString());
 
-               self.pos1_x = ReadCoord();
-               self.pos1_y = ReadCoord();
-               self.pos1_z = ReadCoord();
-               self.pos2_x = ReadCoord();
-               self.pos2_y = ReadCoord();
-               self.pos2_z = ReadCoord();
+               this.pos1_x = ReadCoord();
+               this.pos1_y = ReadCoord();
+               this.pos1_z = ReadCoord();
+               this.pos2_x = ReadCoord();
+               this.pos2_y = ReadCoord();
+               this.pos2_z = ReadCoord();
 
-               self.size_x = ReadCoord();
-               self.size_y = ReadCoord();
-               self.size_z = ReadCoord();
+               this.size_x = ReadCoord();
+               this.size_y = ReadCoord();
+               this.size_z = ReadCoord();
 
-               self.view_ofs_x = ReadCoord();
-               self.view_ofs_y = ReadCoord();
-               self.view_ofs_z = ReadCoord();
+               this.view_ofs_x = ReadCoord();
+               this.view_ofs_y = ReadCoord();
+               this.view_ofs_z = ReadCoord();
 
-               self.mangle_x = ReadAngle();
-               self.mangle_y = ReadAngle();
-               self.mangle_z = ReadAngle();
+               this.mangle_x = ReadAngle();
+               this.mangle_y = ReadAngle();
+               this.mangle_z = ReadAngle();
 
-               self.speed = ReadShort();
-               self.height = ReadShort();
-               self.lip = ReadByte();
-               self.state = ReadByte();
-               self.wait = ReadByte();
+               this.speed = ReadShort();
+               this.height = ReadShort();
+               this.lip = ReadByte();
+               this.state = ReadByte();
+               this.wait = ReadByte();
 
-               self.dmg = ReadShort();
-               self.dmgtime = ReadByte();
+               this.dmg = ReadShort();
+               this.dmgtime = ReadByte();
 
-               self.classname = "func_train";
-               self.solid = SOLID_BSP;
-               self.movetype = MOVETYPE_PUSH;
-               self.drawmask = MASK_NORMAL;
-               self.draw = train_draw;
-               self.entremove = trigger_remove_generic;
+               this.classname = "func_train";
+               this.solid = SOLID_BSP;
+               this.movetype = MOVETYPE_PUSH;
+               this.drawmask = MASK_NORMAL;
+               this.draw = train_draw;
+               this.entremove = trigger_remove_generic;
 
-               if(set_platmovetype(self, self.platmovetype))
+               if(set_platmovetype(this, this.platmovetype))
                {
-                       self.platmovetype_start_default = self.platmovetype_start;
-                       self.platmovetype_end_default = self.platmovetype_end;
+                       this.platmovetype_start_default = this.platmovetype_start;
+                       this.platmovetype_end_default = this.platmovetype_end;
                }
 
                // everything is set up by the time the train is linked, we shouldn't need this
                //func_train_find();
 
                // but we will need these
-               //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;
-               self.move_angles = self.angles;
-               self.move_time = time;
+               //this.move_nextthink = this.move_ltime + 0.1;
+               //this.move_think = train_next;
+               WITHSELF(this, train_next(this));
+
+               this.move_movetype = MOVETYPE_PUSH;
+               this.move_origin = this.origin;
+               this.move_angles = this.angles;
+               this.move_time = time;
        }
 
        if(sf & SF_TRIGGER_RESET)
        {
                // TODO: make a reset function for trains
        }
+
+       return true;
 }
 
 #endif