]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Introduce 2 helpful macros
authorterencehill <piuntn@gmail.com>
Sat, 10 Jun 2017 00:00:35 +0000 (02:00 +0200)
committerterencehill <piuntn@gmail.com>
Sat, 10 Jun 2017 00:00:35 +0000 (02:00 +0200)
qcsrc/server/bot/default/navigation.qc
qcsrc/server/bot/default/navigation.qh
qcsrc/server/bot/default/waypoints.qc

index 61c7db0a752fac213ff7636c8bf248b6e1b4930a..3495991ebe796b0535507e59a0c24bf00b68eff9 100644 (file)
@@ -544,7 +544,8 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom
                te_plasmaburn(org);
 
        entity best = NULL;
-       vector v;
+       vector v, v2;
+       float v2_height;
 
        if(!autocvar_g_waypointeditor && !ent.navigation_dynamicgoal)
        {
@@ -554,26 +555,7 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom
                        if(walkfromwp && (it.wpflags & WAYPOINTFLAG_NORELINK))
                                continue;
 
-                       vector v2;
-                       float v2_height;
-                       if(it.wpisbox)
-                       {
-                               vector wm1 = it.origin + it.mins;
-                               vector wm2 = it.origin + it.maxs;
-                               v.x = bound(wm1_x, org.x, wm2_x);
-                               v.y = bound(wm1_y, org.y, wm2_y);
-                               v.z = bound(wm1_z, org.z, wm2_z);
-                               v2.x = v.x;
-                               v2.y = v.y;
-                               v2.z = wm1.z;
-                               v2_height = wm2.z - wm1.z;
-                       }
-                       else
-                       {
-                               v = it.origin;
-                               v2 = v;
-                               v2_height = 0;
-                       }
+                       SET_TRACEWALK_DESTCOORDS_2(it, org, v, v2, v2_height);
                        if(navigation_waypoint_will_link(v, org, ent, v2, v2_height, walkfromwp, 1050))
                                navigation_item_addlink(it, ent);
                });
@@ -584,27 +566,7 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom
        {
                if(walkfromwp && (it.wpflags & WAYPOINTFLAG_NORELINK))
                        continue;
-
-               vector v2;
-               float v2_height;
-               if(it.wpisbox)
-               {
-                       vector wm1 = it.origin + it.mins;
-                       vector wm2 = it.origin + it.maxs;
-                       v.x = bound(wm1_x, org.x, wm2_x);
-                       v.y = bound(wm1_y, org.y, wm2_y);
-                       v.z = bound(wm1_z, org.z, wm2_z);
-                       v2.x = v.x;
-                       v2.y = v.y;
-                       v2.z = wm1.z;
-                       v2_height = wm2.z - wm1.z;
-               }
-               else
-               {
-                       v = it.origin;
-                       v2 = v;
-                       v2_height = 0;
-               }
+               SET_TRACEWALK_DESTCOORDS_2(it, org, v, v2, v2_height);
                if(navigation_waypoint_will_link(v, org, ent, v2, v2_height, walkfromwp, bestdist))
                {
                        bestdist = vlen(v - org);
@@ -628,27 +590,14 @@ entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
 // finds the waypoints near the bot initiating a navigation query
 float navigation_markroutes_nearestwaypoints(entity this, float maxdist)
 {
-       vector v, m1, m2;
+       vector v;
        //navigation_testtracewalk = true;
        int c = 0;
        float v_height;
        IL_EACH(g_waypoints, !it.wpconsidered,
        {
-               if (it.wpisbox)
-               {
-                       m1 = it.origin + it.mins;
-                       m2 = it.origin + it.maxs;
-                       v = this.origin;
-                       v.x = bound(m1_x, v.x, m2_x);
-                       v.y = bound(m1_y, v.y, m2_y);
-                       v.z = m1.z;
-                       v_height = m2.z - m1.z;
-               }
-               else
-               {
-                       v = it.origin;
-                       v_height = 0;
-               }
+               SET_TRACEWALK_DESTCOORDS(it, this.origin, v, v_height);
+
                vector diff = v - this.origin;
                diff.z = max(0, diff.z);
                if(vdist(diff, <, maxdist))
@@ -671,13 +620,12 @@ float navigation_markroutes_nearestwaypoints(entity this, float maxdist)
 // updates a path link if a spawnfunc_waypoint link is better than the current one
 void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost, vector p)
 {
-       vector m1;
-       vector m2;
+       vector m1, m2;
        vector v;
        if (wp.wpisbox)
        {
-               m1 = wp.absmin;
-               m2 = wp.absmax;
+               m1 = wp.origin + wp.mins;
+               m2 = wp.origin + wp.maxs;
                v.x = bound(m1_x, p.x, m2_x);
                v.y = bound(m1_y, p.y, m2_y);
                v.z = bound(m1_z, p.z, m2_z);
index 91f043f7a2deed935f78c9d4743bf0b2541f1bca..f1fcae0fc4c723b14cfef48a6a594859ab831bc9 100644 (file)
@@ -48,6 +48,41 @@ entity navigation_bestgoal;
 #define navigation_item_addlink(from_wp, to_item) \
        waypoint_addlink_customcost(to_item, from_wp, waypoint_getlinkcost(from_wp, to_item))
 
+// if ent is a box waypoint or an item v is set to coords of ent that are closer to org
+// (but v.z is set to the lowest coord of ent), v_height is set to ent's height
+#define SET_TRACEWALK_DESTCOORDS(ent, org, v, v_height) MACRO_BEGIN { \
+       if ((ent.classname != "waypoint") || ent.wpisbox) { \
+               vector wm1 = ent.origin + ent.mins; \
+               vector wm2 = ent.origin + ent.maxs; \
+               v.x = bound(wm1.x, org.x, wm2.x); \
+               v.y = bound(wm1.y, org.y, wm2.y); \
+               v.z = wm1.z; \
+               v_height = wm2.z - wm1.z; \
+       } else { \
+               v = ent.origin; \
+               v_height = 0; \
+       } \
+} MACRO_END
+
+// if ent is a box waypoint or an item v and v2 are set to coords of ent that are closer to org
+// (but v2.z is set to the lowest coord of ent), v2_height is set to ent's height
+#define SET_TRACEWALK_DESTCOORDS_2(ent, org, v, v2, v2_height) MACRO_BEGIN { \
+       if ((ent.classname != "waypoint") || ent.wpisbox) { \
+               vector wm1 = ent.origin + ent.mins; \
+               vector wm2 = ent.origin + ent.maxs; \
+               v.x = bound(wm1.x, org.x, wm2.x); \
+               v.y = bound(wm1.y, org.y, wm2.y); \
+               v.z = bound(wm1.z, org.z, wm2.z); \
+               v2.x = v.x; \
+               v2.y = v.y; \
+               v2.z = wm1.z; \
+               v2_height = wm2.z - wm1.z; \
+       } else { \
+               v = ent.origin; \
+               v2 = v; \
+               v2_height = 0; \
+       } \
+} MACRO_END
 
 .entity wp_goal_prev0;
 .entity wp_goal_prev1;
index 05133bb762d47399d636b308f5d2af0b73e7ec3d..436220d698aff0fc108c0fd1d1c166af484c0c17 100644 (file)
@@ -538,15 +538,14 @@ void waypoint_addlink(entity from, entity to)
 // (SLOW!)
 void waypoint_think(entity this)
 {
-       vector sv, sm1, sm2, ev, em1, em2, dv;
+       vector sv, sv2, ev, ev2, dv;
+       float sv2_height, ev2_height;
 
        bot_calculate_stepheightvec();
 
        bot_navigation_movemode = ((autocvar_bot_navigation_ignoreplayers) ? MOVE_NOMONSTERS : MOVE_NORMAL);
 
        //dprint("waypoint_think wpisbox = ", ftos(this.wpisbox), "\n");
-       sm1 = this.origin + this.mins;
-       sm2 = this.origin + this.maxs;
        IL_EACH(g_waypoints, this != it,
        {
                if (boxesoverlap(this.absmin, this.absmax, it.absmin, it.absmax))
@@ -563,47 +562,8 @@ void waypoint_think(entity this)
                                continue;
                        }
 
-                       vector sv2;
-                       float sv2_height;
-                       if (this.wpisbox)
-                       {
-                               sv = it.origin;
-                               sv.x = bound(sm1.x, sv.x, sm2.x);
-                               sv.y = bound(sm1.y, sv.y, sm2.y);
-                               sv.z = bound(sm1.z, sv.z, sm2.z);
-                               sv2.x = sv.x;
-                               sv2.y = sv.y;
-                               sv2.z = sm1.z;
-                               sv2_height = sm2.z - sm1.z;
-                       }
-                       else
-                       {
-                               sv = this.origin;
-                               sv2 = sv;
-                               sv2_height = 0;
-                       }
-
-                       vector ev2;
-                       float ev2_height;
-                       if (it.wpisbox)
-                       {
-                               ev = this.origin;
-                               em1 = it.origin + it.mins;
-                               em2 = it.origin + it.maxs;
-                               ev.x = bound(em1.x, ev.x, em2.x);
-                               ev.y = bound(em1.y, ev.y, em2.y);
-                               ev.z = bound(em1.z, ev.z, em2.z);
-                               ev2.x = ev.x;
-                               ev2.y = ev.y;
-                               ev2.z = em1.z;
-                               ev2_height = em2.z - em1.z;
-                       }
-                       else
-                       {
-                               ev = it.origin;
-                               ev2 = ev;
-                               ev2_height = 0;
-                       }
+                       SET_TRACEWALK_DESTCOORDS_2(this, it.origin, sv, sv2, sv2_height);
+                       SET_TRACEWALK_DESTCOORDS_2(it, this.origin, ev, ev2, ev2_height);
 
                        dv = ev - sv;
                        dv.z = 0;