]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/train.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / train.qc
index c5a6e3d0393edebcbfd249296f6ecd8d78eb3dd4..1e26bc1a0ba226d93680231146a53ac150006db1 100644 (file)
@@ -11,53 +11,51 @@ void train_wait(entity this)
        this.enemy = NULL;
 
        // if turning is enabled, the train will turn toward the next point while waiting
-       if(this.platmovetype_turn && !this.train_wait_turning)
-       {
+       if (this.platmovetype_turn && !this.train_wait_turning) {
                entity targ, cp;
                vector ang;
                targ = this.future_target;
-               if((this.spawnflags & 1) && targ.curvetarget)
+               if ((this.spawnflags & 1) && targ.curvetarget) {
                        cp = find(NULL, targetname, targ.curvetarget);
-               else
+               } else {
                        cp = NULL;
+               }
 
-               if(cp) // bezier curves movement
-                       ang = cp.origin - (this.origin - this.view_ofs); // use the origin of the control point of the next path_corner
-               else // linear movement
+               if (cp) { // bezier curves movement
+                       ang = cp.origin - (this.origin - this.view_ofs);   // use the origin of the control point of the next path_corner
+               } else { // linear movement
                        ang = targ.origin - (this.origin - this.view_ofs); // use the origin of the next path_corner
+               }
                ang = vectoangles(ang);
-               ang_x = -ang_x; // flip up / down orientation
+               ang_x = -ang_x;                                        // flip up / down orientation
 
-               if(this.wait > 0) // slow turning
+               if (this.wait > 0) { // slow turning
                        SUB_CalcAngleMove(this, ang, TSPEED_TIME, this.ltime - time + this.wait, train_wait);
-               else // instant turning
+               } else { // instant turning
                        SUB_CalcAngleMove(this, ang, TSPEED_TIME, 0.0000001, train_wait);
+               }
                this.train_wait_turning = true;
                return;
        }
 
 #ifdef SVQC
-       if(this.noise != "")
+       if (this.noise != "") {
                stopsoundto(MSG_BROADCAST, this, CH_TRIGGER_SINGLE); // send this as unreliable only, as the train will resume operation shortly anyway
+       }
 #endif
 
 #ifdef SVQC
        entity tg = this.future_target;
-       if(tg.spawnflags & 4)
-       {
+       if (tg.spawnflags & 4) {
                this.use = train_use;
                setthink(this, func_null);
                this.nextthink = 0;
-       }
-       else
+       } else
 #endif
-            if(this.wait < 0 || this.train_wait_turning) // no waiting or we already waited while turning
-       {
+       if (this.wait < 0 || this.train_wait_turning) { // no waiting or we already waited while turning
                this.train_wait_turning = false;
                train_next(this);
-       }
-       else
-       {
+       } else {
                setthink(this, train_next);
                this.nextthink = this.ltime + this.wait;
        }
@@ -65,17 +63,13 @@ void train_wait(entity this)
 
 entity train_next_find(entity this)
 {
-       if(this.target_random)
-       {
+       if (this.target_random) {
                RandomSelection_Init();
-               for(entity t = NULL; (t = find(t, targetname, this.target));)
-               {
+               for (entity t = NULL; (t = find(t, targetname, this.target)); ) {
                        RandomSelection_AddEnt(t, 1, 0);
                }
                return RandomSelection_chosen_ent;
-       }
-       else
-       {
+       } else {
                return find(NULL, targetname, this.target);
        }
 }
@@ -91,50 +85,47 @@ void train_next(entity this)
        this.target_random = targ.target_random;
        this.future_target = train_next_find(targ);
 
-       if (this.spawnflags & 1)
-       {
-               if(targ.curvetarget)
-               {
+       if (this.spawnflags & 1) {
+               if (targ.curvetarget) {
                        cp = find(NULL, targetname, targ.curvetarget); // get its second target (the control point)
-                       cp_org = cp.origin - this.view_ofs; // no control point found, assume a straight line to the destination
+                       cp_org = cp.origin - this.view_ofs;            // no control point found, assume a straight line to the destination
                }
        }
-       if (this.target == "")
+       if (this.target == "") {
                objerror(this, "train_next: no next target");
+       }
        this.wait = targ.wait;
-       if (!this.wait)
+       if (!this.wait) {
                this.wait = 0.1;
+       }
 
-       if(targ.platmovetype)
-       {
+       if (targ.platmovetype) {
                // this path_corner contains a movetype overrider, apply it
                this.platmovetype_start = targ.platmovetype_start;
                this.platmovetype_end = targ.platmovetype_end;
-       }
-       else
-       {
+       } else {
                // this path_corner doesn't contain a movetype overrider, use the train's defaults
                this.platmovetype_start = this.platmovetype_start_default;
                this.platmovetype_end = this.platmovetype_end_default;
        }
 
-       if (targ.speed)
-       {
-               if (cp)
+       if (targ.speed) {
+               if (cp) {
                        SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
-               else
+               } else {
                        SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, targ.speed, train_wait);
-       }
-       else
-       {
-               if (cp)
+               }
+       } else {
+               if (cp) {
                        SUB_CalcMove_Bezier(this, cp_org, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
-               else
+               } else {
                        SUB_CalcMove(this, targ.origin - this.view_ofs, TSPEED_LINEAR, this.speed, train_wait);
+               }
        }
 
-       if(this.noise != "")
+       if (this.noise != "") {
                _sound(this, CH_TRIGGER_SINGLE, this.noise, VOL_BASE, ATTEN_IDLE);
+       }
 }
 
 REGISTER_NET_LINKED(ENT_CLIENT_TRAIN)
@@ -145,8 +136,7 @@ float train_send(entity this, entity to, float sf)
        WriteHeader(MSG_ENTITY, ENT_CLIENT_TRAIN);
        WriteByte(MSG_ENTITY, sf);
 
-       if(sf & SF_TRIGGER_INIT)
-       {
+       if (sf & SF_TRIGGER_INIT) {
                WriteString(MSG_ENTITY, this.platmovetype);
                WriteByte(MSG_ENTITY, this.platmovetype_turn);
                WriteByte(MSG_ENTITY, this.spawnflags);
@@ -186,8 +176,7 @@ float train_send(entity this, entity to, float sf)
                WriteByte(MSG_ENTITY, this.dmgtime);
        }
 
-       if(sf & SF_TRIGGER_RESET)
-       {
+       if (sf & SF_TRIGGER_RESET) {
                // used on client
        }
 
@@ -196,7 +185,7 @@ float train_send(entity this, entity to, float sf)
 
 void train_link(entity this)
 {
-       //Net_LinkEntity(this, 0, false, train_send);
+       // Net_LinkEntity(this, 0, false, train_send);
 }
 
 void train_use(entity this, entity actor, entity trigger)
@@ -204,8 +193,9 @@ void train_use(entity this, entity actor, entity trigger)
        this.nextthink = this.ltime + 1;
        setthink(this, train_next);
        this.use = func_null; // not again
-       if(trigger.target2 && trigger.target2 != "")
+       if (trigger.target2 && trigger.target2 != "") {
                this.future_target = find(NULL, targetname, trigger.target2);
+       }
 }
 
 void func_train_find(entity this)
@@ -215,12 +205,12 @@ void func_train_find(entity this)
        this.target_random = targ.target_random;
        // save the future target for later
        this.future_target = train_next_find(targ);
-       if (this.target == "")
+       if (this.target == "") {
                objerror(this, "func_train_find: no next target");
+       }
        setorigin(this, targ.origin - this.view_ofs);
 
-       if(!(this.spawnflags & 4))
-       {
+       if (!(this.spawnflags & 4)) {
                this.nextthink = this.ltime + 1;
                setthink(this, train_next);
        }
@@ -238,43 +228,51 @@ target : targetname of first spawnfunc_path_corner (starts here)
 #ifdef SVQC
 spawnfunc(func_train)
 {
-       if (this.noise != "")
+       if (this.noise != "") {
                precache_sound(this.noise);
+       }
 
-       if (this.target == "")
+       if (this.target == "") {
                objerror(this, "func_train without a target");
-       if (!this.speed)
+       }
+       if (!this.speed) {
                this.speed = 100;
+       }
 
-       if (!InitMovingBrushTrigger(this))
+       if (!InitMovingBrushTrigger(this)) {
                return;
+       }
        this.effects |= EF_LOWPRECISION;
 
-       if(this.spawnflags & 4)
+       if (this.spawnflags & 4) {
                this.use = train_use;
+       }
 
-       if (this.spawnflags & 2)
-       {
+       if (this.spawnflags & 2) {
                this.platmovetype_turn = true;
                this.view_ofs = '0 0 0'; // don't offset a rotating train, origin works differently now
-       }
-       else
+       } else {
                this.view_ofs = this.mins;
+       }
 
        // wait for targets to spawn
        InitializeEntity(this, func_train_find, INITPRIO_FINDTARGET);
 
        setblocked(this, generic_plat_blocked);
-       if(this.dmg && (this.message == ""))
+       if (this.dmg && (this.message == "")) {
                this.message = " was squished";
-    if(this.dmg && (this.message2 == ""))
+       }
+       if (this.dmg && (this.message2 == "")) {
                this.message2 = "was squished by";
-       if(this.dmg && (!this.dmgtime))
+       }
+       if (this.dmg && (!this.dmgtime)) {
                this.dmgtime = 0.25;
+       }
        this.dmgtime2 = time;
 
-       if(!set_platmovetype(this, this.platmovetype))
+       if (!set_platmovetype(this, this.platmovetype)) {
                return;
+       }
        this.platmovetype_start_default = this.platmovetype_start;
        this.platmovetype_end_default = this.platmovetype_end;
 
@@ -283,7 +281,7 @@ spawnfunc(func_train)
 #elif defined(CSQC)
 void train_draw(entity this)
 {
-       //Movetype_Physics_NoMatchServer();
+       // Movetype_Physics_NoMatchServer();
        Movetype_Physics_MatchServer(this, autocvar_cl_projectiles_sloppy);
 }
 
@@ -291,8 +289,7 @@ NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
 {
        float sf = ReadByte();
 
-       if(sf & SF_TRIGGER_INIT)
-       {
+       if (sf & SF_TRIGGER_INIT) {
                this.platmovetype = strzone(ReadString());
                this.platmovetype_turn = ReadByte();
                this.spawnflags = ReadByte();
@@ -337,17 +334,16 @@ NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
                set_movetype(this, MOVETYPE_PUSH);
                this.drawmask = MASK_NORMAL;
                this.draw = train_draw;
-               if (isnew) IL_PUSH(g_drawables, this);
+               if (isnew) { IL_PUSH(g_drawables, this); }
                this.entremove = trigger_remove_generic;
 
-               if(set_platmovetype(this, this.platmovetype))
-               {
+               if (set_platmovetype(this, this.platmovetype)) {
                        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();
+               // func_train_find();
 
                // but we will need these
                train_next(this);
@@ -356,8 +352,7 @@ NET_HANDLE(ENT_CLIENT_TRAIN, bool isnew)
                this.move_time = time;
        }
 
-       if(sf & SF_TRIGGER_RESET)
-       {
+       if (sf & SF_TRIGGER_RESET) {
                // TODO: make a reset function for trains
        }