]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Bot AI: consider an item pickable via a jumppad only if it can be touched by all...
authorterencehill <piuntn@gmail.com>
Wed, 16 May 2018 20:40:21 +0000 (22:40 +0200)
committerterencehill <piuntn@gmail.com>
Wed, 16 May 2018 20:40:21 +0000 (22:40 +0200)
qcsrc/common/triggers/trigger/jumppads.qc
qcsrc/common/triggers/trigger/jumppads.qh

index 3c5019a5c38b71a1ddddf0433e4c30c3327e9239..22d7ceba665d07ee6f7b4f28c3ea19d11a17a6d2 100644 (file)
@@ -308,6 +308,24 @@ bool trigger_push_testorigin(entity tracetest_ent, entity targ, entity jp, vecto
        tracebox(trace_endpos, tracetest_ent.mins, tracetest_ent.maxs, trace_endpos - eZ * 1500, true, tracetest_ent);
        return true;
 }
+
+bool trigger_push_testorigin_for_item(entity tracetest_ent, entity item, vector org)
+{
+       setorigin(tracetest_ent, org);
+       tracetoss(tracetest_ent, tracetest_ent);
+
+       if(trace_startsolid)
+               return false;
+       if (trace_ent == item)
+               return true;
+
+       tracebox(trace_endpos, tracetest_ent.mins, tracetest_ent.maxs, trace_endpos - eZ * 1500, true, tracetest_ent);
+
+       if (trace_ent == item)
+               return true;
+
+       return false;
+}
 #endif
 
 /// if (item != NULL) returns true if the item can be reached by using this jumppad, false otherwise
@@ -336,26 +354,28 @@ bool trigger_push_test(entity this, entity item)
                        e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
                        e.velocity = trigger_push_calculatevelocity(org, t, this.height, e);
 
-                       if(item)
-                       {
-                               setorigin(e, org);
-                               tracetoss(e, e);
-                               bool r = (trace_ent == item);
-                               delete(e);
-                               return r;
-                       }
-
                        vel = e.velocity;
                        vector best_target = '0 0 0';
                        vector best_org = '0 0 0';
                        vector best_vel = '0 0 0';
                        bool valid_best_target = false;
-                       if (trigger_push_testorigin(e, t, this, org))
+                       if (item)
                        {
-                               best_target = trace_endpos;
-                               best_org = org;
-                               best_vel = e.velocity;
-                               valid_best_target = true;
+                               if (!trigger_push_testorigin_for_item(e, item, org))
+                               {
+                                       delete(e);
+                                       return false;
+                               }
+                       }
+                       else
+                       {
+                               if (trigger_push_testorigin(e, t, this, org))
+                               {
+                                       best_target = trace_endpos;
+                                       best_org = org;
+                                       best_vel = e.velocity;
+                                       valid_best_target = true;
+                               }
                        }
 
                        vector new_org;
@@ -369,30 +389,58 @@ bool trigger_push_test(entity this, entity item)
                                vector ofs = flatdir * 0.5 * min(fabs(this.absmax.x - this.absmin.x), fabs(this.absmax.y - this.absmin.y));
                                new_org = org + ofs;
                                e.velocity = trigger_push_calculatevelocity(new_org, t, this.height, e);
-                               vel = e.velocity;
-                               if (vdist(vec2(e.velocity), <, autocvar_sv_maxspeed))
-                                       e.velocity = autocvar_sv_maxspeed * flatdir;
-                               if (trigger_push_testorigin(e, t, this, new_org) && (!valid_best_target || trace_endpos.z > best_target.z + 50))
+                               if (item)
                                {
-                                       best_target = trace_endpos;
-                                       best_org = new_org;
-                                       best_vel = vel;
-                                       valid_best_target = true;
+                                       if (!trigger_push_testorigin_for_item(e, item, new_org))
+                                       {
+                                               delete(e);
+                                               return false;
+                                       }
+                               }
+                               else
+                               {
+                                       vel = e.velocity;
+                                       if (vdist(vec2(e.velocity), <, autocvar_sv_maxspeed))
+                                               e.velocity = autocvar_sv_maxspeed * flatdir;
+                                       if (trigger_push_testorigin(e, t, this, new_org) && (!valid_best_target || trace_endpos.z > best_target.z + 50))
+                                       {
+                                               best_target = trace_endpos;
+                                               best_org = new_org;
+                                               best_vel = vel;
+                                               valid_best_target = true;
+                                       }
                                }
                                new_org = org - ofs;
                                e.velocity = trigger_push_calculatevelocity(new_org, t, this.height, e);
-                               vel = e.velocity;
-                               if (vdist(vec2(e.velocity), <, autocvar_sv_maxspeed))
-                                       e.velocity = autocvar_sv_maxspeed * flatdir;
-                               if (trigger_push_testorigin(e, t, this, new_org) && (!valid_best_target || trace_endpos.z > best_target.z + 50))
+                               if (item)
                                {
-                                       best_target = trace_endpos;
-                                       best_org = new_org;
-                                       best_vel = vel;
-                                       valid_best_target = true;
+                                       if (!trigger_push_testorigin_for_item(e, item, new_org))
+                                       {
+                                               delete(e);
+                                               return false;
+                                       }
+                               }
+                               else
+                               {
+                                       vel = e.velocity;
+                                       if (vdist(vec2(e.velocity), <, autocvar_sv_maxspeed))
+                                               e.velocity = autocvar_sv_maxspeed * flatdir;
+                                       if (trigger_push_testorigin(e, t, this, new_org) && (!valid_best_target || trace_endpos.z > best_target.z + 50))
+                                       {
+                                               best_target = trace_endpos;
+                                               best_org = new_org;
+                                               best_vel = vel;
+                                               valid_best_target = true;
+                                       }
                                }
                        }
 
+                       if (item)
+                       {
+                               delete(e);
+                               return true;
+                       }
+
                        if (valid_best_target)
                        {
                                if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, best_target + PL_MIN_CONST, best_target + PL_MAX_CONST)))
@@ -440,7 +488,7 @@ bool trigger_push_test(entity this, entity item)
                setorigin(e, org);
                e.velocity = this.movedir;
                tracetoss(e, e);
-               if(item)
+               if (item)
                {
                        bool r = (trace_ent == item);
                        delete(e);
index 07ab441fe5efcf7d61d2fe1c227c97440174b237..cd6adec310ccf2c00b974f92329f519f0561b45e 100644 (file)
@@ -19,6 +19,7 @@ const int NUM_JUMPPADSUSED = 3;
 void SUB_UseTargets(entity this, entity actor, entity trigger);
 void trigger_push_use(entity this, entity actor, entity trigger);
 bool trigger_push_testorigin(entity tracetest_ent, entity targ, entity jp, vector org);
+bool trigger_push_testorigin_for_item(entity tracetest_ent, entity item, vector org);
 #endif
 
 /*