]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/g_subs.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_subs.qc
index 713577fad17beb0c5d46932b7d845cea4b18cd7e..0b3202019ec9c5f6127c0f6bcd5650ad85ad7e93 100644 (file)
@@ -21,10 +21,8 @@ main
 unused but required by the engine
 ==================
 */
-void main ()
-{
-
-}
+void main()
+{}
 
 // Misc
 
@@ -36,21 +34,22 @@ A version of traceline that must be used by SOLID_SLIDEBOX things that want to h
 Additionally it moves players back into the past before the trace and restores them afterward.
 ==================
 */
-void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz)
+void tracebox_antilag_force_wz(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag, float wz)
 {
        // check whether antilagged traces are enabled
-       if (lag < 0.001)
+       if (lag < 0.001) {
                lag = 0;
-       if (!IS_REAL_CLIENT(forent))
+       }
+       if (!IS_REAL_CLIENT(forent)) {
                lag = 0; // only antilag for clients
-
+       }
        // change shooter to SOLID_BBOX so the shot can hit corpses
        int oldsolid = source.dphitcontentsmask;
-       if(source)
+       if (source) {
                source.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
+       }
 
-       if (lag)
-       {
+       if (lag) {
                // take players back into the past
                FOREACH_CLIENT(IS_PLAYER(it) && it != forent, antilag_takeback(it, CS(it), time - lag));
                IL_EACH(g_monsters, it != forent,
@@ -60,14 +59,14 @@ void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma,
        }
 
        // do the trace
-       if(wz)
-               WarpZone_TraceBox (v1, mi, ma, v2, nomonst, forent);
-       else
-               tracebox (v1, mi, ma, v2, nomonst, forent);
+       if (wz) {
+               WarpZone_TraceBox(v1, mi, ma, v2, nomonst, forent);
+       } else {
+               tracebox(v1, mi, ma, v2, nomonst, forent);
+       }
 
        // restore players to current positions
-       if (lag)
-       {
+       if (lag) {
                FOREACH_CLIENT(IS_PLAYER(it) && it != forent, antilag_restore(it, CS(it)));
                IL_EACH(g_monsters, it != forent,
                {
@@ -76,53 +75,58 @@ void tracebox_antilag_force_wz (entity source, vector v1, vector mi, vector ma,
        }
 
        // restore shooter solid type
-       if(source)
+       if (source) {
                source.dphitcontentsmask = oldsolid;
+       }
 }
-void traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
+void traceline_antilag_force(entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
 {
        tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonst, forent, lag, false);
 }
-void traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
+void traceline_antilag(entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
 {
        bool noantilag = ((IS_CLIENT(source)) ? CS(source).cvar_cl_noantilag : false);
-       if (autocvar_g_antilag != 2 || noantilag)
+       if (autocvar_g_antilag != 2 || noantilag) {
                lag = 0;
+       }
        traceline_antilag_force(source, v1, v2, nomonst, forent, lag);
 }
-void tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
+void tracebox_antilag(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
 {
        bool noantilag = ((IS_CLIENT(source)) ? CS(source).cvar_cl_noantilag : false);
-       if (autocvar_g_antilag != 2 || noantilag)
+       if (autocvar_g_antilag != 2 || noantilag) {
                lag = 0;
+       }
        tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonst, forent, lag, false);
 }
-void WarpZone_traceline_antilag_force (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
+void WarpZone_traceline_antilag_force(entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
 {
        tracebox_antilag_force_wz(source, v1, '0 0 0', '0 0 0', v2, nomonst, forent, lag, true);
 }
-void WarpZone_traceline_antilag (entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
+void WarpZone_traceline_antilag(entity source, vector v1, vector v2, float nomonst, entity forent, float lag)
 {
        bool noantilag = ((IS_CLIENT(source)) ? CS(source).cvar_cl_noantilag : false);
-       if (autocvar_g_antilag != 2 || noantilag)
+       if (autocvar_g_antilag != 2 || noantilag) {
                lag = 0;
+       }
        WarpZone_traceline_antilag_force(source, v1, v2, nomonst, forent, lag);
 }
-void WarpZone_tracebox_antilag (entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
+void WarpZone_tracebox_antilag(entity source, vector v1, vector mi, vector ma, vector v2, float nomonst, entity forent, float lag)
 {
        bool noantilag = ((IS_CLIENT(source)) ? CS(source).cvar_cl_noantilag : false);
-       if (autocvar_g_antilag != 2 || noantilag)
+       if (autocvar_g_antilag != 2 || noantilag) {
                lag = 0;
+       }
        tracebox_antilag_force_wz(source, v1, mi, ma, v2, nomonst, forent, lag, true);
 }
 
-float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity) // returns the number of traces done, for benchmarking
+float tracebox_inverted(vector v1, vector mi, vector ma, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity) // returns the number of traces done, for benchmarking
 {
        vector pos, dir, t;
        float nudge;
        entity stopentity;
 
-       //nudge = 2 * cvar("collision_impactnudge"); // why not?
+       // nudge = 2 * cvar("collision_impactnudge"); // why not?
        nudge = 0.5;
 
        dir = normalize(v2 - v1);
@@ -132,10 +136,8 @@ float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomon
        float c;
        c = 0;
 
-       for (;;)
-       {
-               if(pos * dir >= v2 * dir)
-               {
+       for ( ; ; ) {
+               if (pos * dir >= v2 * dir) {
                        // went too far
                        trace_fraction = 1;
                        trace_endpos = v2;
@@ -145,8 +147,7 @@ float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomon
                tracebox(pos, mi, ma, v2, nomonsters, forent);
                ++c;
 
-               if(c == 50)
-               {
+               if (c == 50) {
                        LOG_TRACE("HOLY SHIT! When tracing from ", vtos(v1), " to ", vtos(v2));
                        LOG_TRACE("  Nudging gets us nowhere at ", vtos(pos));
                        LOG_TRACE("  trace_endpos is ", vtos(trace_endpos));
@@ -155,37 +156,30 @@ float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomon
 
                stopentity = trace_ent;
 
-               if(trace_startsolid)
-               {
+               if (trace_startsolid) {
                        // we started inside solid.
                        // then trace from endpos to pos
                        t = trace_endpos;
                        tracebox(t, mi, ma, pos, nomonsters, forent);
                        ++c;
-                       if(trace_startsolid)
-                       {
+                       if (trace_startsolid) {
                                // t is still inside solid? bad
                                // force advance, then, and retry
                                pos = t + dir * nudge;
 
                                // but if we hit an entity, stop RIGHT before it
-                               if(stopatentity && stopentity && stopentity != ignorestopatentity)
-                               {
+                               if (stopatentity && stopentity && stopentity != ignorestopatentity) {
                                        trace_ent = stopentity;
                                        trace_endpos = t;
                                        trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
                                        return c;
                                }
-                       }
-                       else
-                       {
+                       } else {
                                // we actually LEFT solid!
                                trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
                                return c;
                        }
-               }
-               else
-               {
+               } else {
                        // pos is outside solid?!? but why?!? never mind, just return it.
                        trace_endpos = pos;
                        trace_fraction = ((trace_endpos - v1) * dir) / ((v2 - v1) * dir);
@@ -194,7 +188,7 @@ float tracebox_inverted (vector v1, vector mi, vector ma, vector v2, float nomon
        }
 }
 
-void traceline_inverted (vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity)
+void traceline_inverted(vector v1, vector v2, float nomonsters, entity forent, float stopatentity, entity ignorestopatentity)
 {
        tracebox_inverted(v1, '0 0 0', '0 0 0', v2, nomonsters, forent, stopatentity, ignorestopatentity);
 }
@@ -208,23 +202,21 @@ Returns a point at least 12 units away from walls
 Ripped from DPMod
 ==================
 */
-vector findbetterlocation (vector org, float mindist)
+vector findbetterlocation(vector org, float mindist)
 {
        vector vec = mindist * '1 0 0';
        int c = 0;
-       while (c < 6)
-       {
-               traceline (org, org + vec, true, NULL);
+       while (c < 6) {
+               traceline(org, org + vec, true, NULL);
                vec = vec * -1;
-               if (trace_fraction < 1)
-               {
+               if (trace_fraction < 1) {
                        vector loc = trace_endpos;
-                       traceline (loc, loc + vec, true, NULL);
-                       if (trace_fraction >= 1)
+                       traceline(loc, loc + vec, true, NULL);
+                       if (trace_fraction >= 1) {
                                org = loc + vec;
+                       }
                }
-               if (c & 1)
-               {
+               if (c & 1) {
                        float h = vec.y;
                        vec.y = vec.x;
                        vec.x = vec.z;
@@ -238,26 +230,27 @@ vector findbetterlocation (vector org, float mindist)
 
 bool LOD_customize(entity this, entity client)
 {
-       if(autocvar_loddebug)
-       {
+       if (autocvar_loddebug) {
                int d = autocvar_loddebug;
-               if(d == 1)
+               if (d == 1) {
                        this.modelindex = this.lodmodelindex0;
-               else if(d == 2 || !this.lodmodelindex2)
+               } else if (d == 2 || !this.lodmodelindex2) {
                        this.modelindex = this.lodmodelindex1;
-               else // if(d == 3)
+               } else { // if(d == 3)
                        this.modelindex = this.lodmodelindex2;
+               }
                return true;
        }
 
        // TODO csqc network this so it only gets sent once
        vector near_point = NearestPointOnBox(this, client.origin);
-       if(vdist(near_point - client.origin, <, this.loddistance1))
+       if (vdist(near_point - client.origin, <, this.loddistance1)) {
                this.modelindex = this.lodmodelindex0;
-       else if(!this.lodmodelindex2 || vdist(near_point - client.origin, <, this.loddistance2))
+       } else if (!this.lodmodelindex2 || vdist(near_point - client.origin, <, this.loddistance2)) {
                this.modelindex = this.lodmodelindex1;
-       else
+       } else {
                this.modelindex = this.lodmodelindex2;
+       }
 
        return true;
 }
@@ -271,38 +264,34 @@ void LODmodel_attach(entity this)
 {
        entity e;
 
-       if(!this.loddistance1)
+       if (!this.loddistance1) {
                this.loddistance1 = 1000;
-       if(!this.loddistance2)
+       }
+       if (!this.loddistance2) {
                this.loddistance2 = 2000;
+       }
        this.lodmodelindex0 = this.modelindex;
 
-       if(this.lodtarget1 != "")
-       {
+       if (this.lodtarget1 != "") {
                e = find(NULL, targetname, this.lodtarget1);
-               if(e)
-               {
+               if (e) {
                        this.lodmodel1 = e.model;
                        delete(e);
                }
        }
-       if(this.lodtarget2 != "")
-       {
+       if (this.lodtarget2 != "") {
                e = find(NULL, targetname, this.lodtarget2);
-               if(e)
-               {
+               if (e) {
                        this.lodmodel2 = e.model;
                        delete(e);
                }
        }
 
-       if(autocvar_loddebug < 0)
-       {
+       if (autocvar_loddebug < 0) {
                this.lodmodel1 = this.lodmodel2 = ""; // don't even initialize
        }
 
-       if(this.lodmodel1 != "")
-       {
+       if (this.lodmodel1 != "") {
                vector mi, ma;
                mi = this.mins;
                ma = this.maxs;
@@ -311,8 +300,7 @@ void LODmodel_attach(entity this)
                _setmodel(this, this.lodmodel1);
                this.lodmodelindex1 = this.modelindex;
 
-               if(this.lodmodel2 != "")
-               {
+               if (this.lodmodel2 != "") {
                        precache_model(this.lodmodel2);
                        _setmodel(this, this.lodmodel2);
                        this.lodmodelindex2 = this.modelindex;
@@ -322,73 +310,69 @@ void LODmodel_attach(entity this)
                setsize(this, mi, ma);
        }
 
-       if(this.lodmodelindex1)
-               if (!getSendEntity(this))
+       if (this.lodmodelindex1) {
+               if (!getSendEntity(this)) {
                        SetCustomizer(this, LOD_customize, LOD_uncustomize);
+               }
+       }
 }
 
 void ApplyMinMaxScaleAngles(entity e)
 {
-       if(e.angles.x != 0 || e.angles.z != 0 || e.avelocity.x != 0 || e.avelocity.z != 0) // "weird" rotation
-       {
+       if (e.angles.x != 0 || e.angles.z != 0 || e.avelocity.x != 0 || e.avelocity.z != 0) { // "weird" rotation
                e.maxs = '1 1 1' * vlen(
-                       '1 0 0' * max(-e.mins.x, e.maxs.x) +
-                       '0 1 0' * max(-e.mins.y, e.maxs.y) +
-                       '0 0 1' * max(-e.mins.z, e.maxs.z)
-               );
+                       '1 0 0' * max(-e.mins.x, e.maxs.x)
+                       + '0 1 0' * max(-e.mins.y, e.maxs.y)
+                       '0 0 1' * max(-e.mins.z, e.maxs.z)
+                       );
                e.mins = -e.maxs;
-       }
-       else if(e.angles.y != 0 || e.avelocity.y != 0) // yaw only is a bit better
-       {
+       } else if (e.angles.y != 0 || e.avelocity.y != 0) { // yaw only is a bit better
                e.maxs_x = vlen(
-                       '1 0 0' * max(-e.mins.x, e.maxs.x) +
-                       '0 1 0' * max(-e.mins.y, e.maxs.y)
-               );
+                       '1 0 0' * max(-e.mins.x, e.maxs.x)
+                       '0 1 0' * max(-e.mins.y, e.maxs.y)
+                       );
                e.maxs_y = e.maxs.x;
                e.mins_x = -e.maxs.x;
                e.mins_y = -e.maxs.x;
        }
-       if(e.scale)
+       if (e.scale) {
                setsize(e, e.mins * e.scale, e.maxs * e.scale);
-       else
+       } else {
                setsize(e, e.mins, e.maxs);
+       }
 }
 
 void SetBrushEntityModel(entity this)
 {
-       if(this.model != "")
-       {
-               precache_model(this.model);
-               if(this.mins != '0 0 0' || this.maxs != '0 0 0')
-               {
+       if (this.model != "") {
+               precache_model(this.model);
+               if (this.mins != '0 0 0' || this.maxs != '0 0 0') {
                        vector mi = this.mins;
                        vector ma = this.maxs;
                        _setmodel(this, this.model); // no precision needed
                        setsize(this, mi, ma);
-               }
-               else
+               } else {
                        _setmodel(this, this.model); // no precision needed
+               }
                InitializeEntity(this, LODmodel_attach, INITPRIO_FINDTARGET);
-       }
+       }
        setorigin(this, this.origin);
        ApplyMinMaxScaleAngles(this);
 }
 
 void SetBrushEntityModelNoLOD(entity this)
 {
-       if(this.model != "")
-       {
-               precache_model(this.model);
-               if(this.mins != '0 0 0' || this.maxs != '0 0 0')
-               {
+       if (this.model != "") {
+               precache_model(this.model);
+               if (this.mins != '0 0 0' || this.maxs != '0 0 0') {
                        vector mi = this.mins;
                        vector ma = this.maxs;
                        _setmodel(this, this.model); // no precision needed
                        setsize(this, mi, ma);
-               }
-               else
+               } else {
                        _setmodel(this, this.model); // no precision needed
-       }
+               }
+       }
        setorigin(this, this.origin);
        ApplyMinMaxScaleAngles(this);
 }
@@ -401,10 +385,9 @@ InitTrigger
 
 void SetMovedir(entity this)
 {
-       if(this.movedir != '0 0 0')
+       if (this.movedir != '0 0 0') {
                this.movedir = normalize(this.movedir);
-       else
-       {
+       } else {
                makevectors(this.angles);
                this.movedir = v_forward;
        }
@@ -443,8 +426,7 @@ bool InitMovingBrushTrigger(entity this)
        this.solid = SOLID_BSP;
        SetBrushEntityModel(this);
        set_movetype(this, MOVETYPE_PUSH);
-       if(this.modelindex == 0)
-       {
+       if (this.modelindex == 0) {
                objerror(this, "InitMovingBrushTrigger: no brushes found!");
                return false;
        }