]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'master' into terencehill/bot_waypoints
authorterencehill <piuntn@gmail.com>
Fri, 1 Dec 2017 14:39:56 +0000 (15:39 +0100)
committerterencehill <piuntn@gmail.com>
Fri, 1 Dec 2017 14:39:56 +0000 (15:39 +0100)
1  2 
qcsrc/common/triggers/teleporters.qc
qcsrc/common/triggers/trigger/jumppads.qc
qcsrc/server/bot/default/havocbot/roles.qc

index 2ba6e7e3c704f8b283a28dd0e0bfaccee7abc767,e1cd95058dbb7b597f174614c8b203be1674e05d..373b755371f14fc7f3bfa66fc6a56ec006e9791f
@@@ -228,20 -228,15 +228,21 @@@ entity Simple_TeleportPlayer(entity tel
  
  void teleport_findtarget(entity this)
  {
+       bool istrigger = (this.solid == SOLID_TRIGGER);
        int n = 0;
-       entity e;
-       for(e = NULL; (e = find(e, targetname, this.target)); )
+       for(entity e = NULL; (e = find(e, targetname, this.target)); )
        {
                ++n;
  #ifdef SVQC
                if(e.move_movetype == MOVETYPE_NONE)
 -                      waypoint_spawnforteleporter(this, e.origin, 0);
 +              {
 +                      entity tracetest_ent = spawn();
 +                      setsize(tracetest_ent, PL_MIN_CONST, PL_MAX_CONST);
 +                      tracetest_ent.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
 +                      waypoint_spawnforteleporter(this, e.origin, 0, tracetest_ent);
 +                      delete(tracetest_ent);
 +              }
                if(e.classname != "info_teleport_destination")
                        LOG_INFO("^3MAPPER ERROR: teleporter does target an invalid teleport destination entity. Angles will not work.");
  #endif
        else if(n == 1)
        {
                // exactly one dest - bots love that
-               this.enemy = find(e, targetname, this.target);
+               this.enemy = find(NULL, targetname, this.target);
        }
        else
        {
        }
  
        // now enable touch
-       settouch(this, Teleport_Touch);
+       if(istrigger)
+               settouch(this, Teleport_Touch);
  #ifdef SVQC
-       trigger_teleport_link(this);
+       if(istrigger)
+               trigger_teleport_link(this);
  #endif
  }
  
index 533f65989e3f283a425a04ab8f713fe49a0cd618,822411c6a23a93d2b58093f3e28c1616564be7b1..999a615cb7c9ac9b835cc275482720e06cbd76ac
@@@ -27,7 -27,10 +27,7 @@@ REGISTER_NET_LINKED(ENT_CLIENT_TARGET_P
          ht  - jump height, measured from the higher one of org and tgt's midpoint
  
        Returns: velocity for the jump
 -      the global trigger_push_calculatevelocity_flighttime is set to the total
 -      jump time
   */
 -
  vector trigger_push_calculatevelocity(vector org, entity tgt, float ht)
  {
        float grav, sdist, zdist, vs, vz, jumpheight;
@@@ -35,9 -38,9 +35,9 @@@
  
        torg = tgt.origin + (tgt.mins + tgt.maxs) * 0.5;
  
-       grav = PHYS_GRAVITY(other);
-       if(PHYS_ENTGRAVITY(other))
-               grav *= PHYS_ENTGRAVITY(other);
+       grav = PHYS_GRAVITY(tgt);
+       if(PHYS_ENTGRAVITY(tgt))
+               grav *= PHYS_ENTGRAVITY(tgt);
  
        zdist = torg.z - org.z;
        sdist = vlen(torg - org - zdist * '0 0 1');
@@@ -85,7 -88,6 +85,7 @@@
        if(zdist == 0)
                solution_x = solution.y; // solution_x is 0 in this case, so don't use it, but rather use solution_y (which will be sqrt(0.5 * jumpheight / grav), actually)
  
 +      float flighttime;
        if(zdist < 0)
        {
                // down-jump
                        // almost straight line type
                        // jump apex is before the jump
                        // we must take the larger one
 -                      trigger_push_calculatevelocity_flighttime = solution.y;
 +                      flighttime = solution.y;
                }
                else
                {
                        // regular jump
                        // jump apex is during the jump
                        // we must take the larger one too
 -                      trigger_push_calculatevelocity_flighttime = solution.y;
 +                      flighttime = solution.y;
                }
        }
        else
                        // almost straight line type
                        // jump apex is after the jump
                        // we must take the smaller one
 -                      trigger_push_calculatevelocity_flighttime = solution.x;
 +                      flighttime = solution.x;
                }
                else
                {
                        // regular jump
                        // jump apex is during the jump
                        // we must take the larger one
 -                      trigger_push_calculatevelocity_flighttime = solution.y;
 +                      flighttime = solution.y;
                }
        }
 -      vs = sdist / trigger_push_calculatevelocity_flighttime;
 +      vs = sdist / flighttime;
  
        // finally calculate the velocity
        return sdir * vs + '0 0 1' * vz;
@@@ -270,37 -272,6 +270,37 @@@ void trigger_push_touch(entity this, en
  #ifdef SVQC
  void trigger_push_link(entity this);
  void trigger_push_updatelink(entity this);
 +bool trigger_push_testorigin(entity tracetest_ent, entity targ, entity jp, vector org)
 +{
 +      setorigin(tracetest_ent, org);
 +      tracetoss(tracetest_ent, tracetest_ent);
 +      if(trace_startsolid)
 +              return false;
 +
 +      if(!jp.height)
 +      {
 +              // since tracetoss starting from jumppad's origin often fails when target
 +              // is very close to real destination, start it directly from target's
 +              // origin instead
 +              tracetest_ent.velocity.z = 0;
 +              setorigin(tracetest_ent, targ.origin + stepheightvec);
 +              tracetoss(tracetest_ent, tracetest_ent);
 +              if(trace_startsolid)
 +              {
 +                      setorigin(tracetest_ent, targ.origin + stepheightvec / 2);
 +                      tracetoss(tracetest_ent, tracetest_ent);
 +                      if(trace_startsolid)
 +                      {
 +                              setorigin(tracetest_ent, targ.origin);
 +                              tracetoss(tracetest_ent, tracetest_ent);
 +                              if(trace_startsolid)
 +                                      return false;
 +                      }
 +              }
 +      }
 +      tracebox(trace_endpos, tracetest_ent.mins, tracetest_ent.maxs, trace_endpos - eZ * 1500, true, tracetest_ent);
 +      return true;
 +}
  #endif
  void trigger_push_findtarget(entity this)
  {
        if (this.target)
        {
                int n = 0;
 +#ifdef SVQC
 +              vector vel = '0 0 0';
 +#endif
                for(entity t = NULL; (t = find(t, targetname, this.target)); )
                {
                        ++n;
  #ifdef SVQC
 +                      if(t.move_movetype != MOVETYPE_NONE)
 +                              continue;
 +
                        entity e = spawn();
 -                      setorigin(e, org);
                        setsize(e, PL_MIN_CONST, PL_MAX_CONST);
 +                      e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
                        e.velocity = trigger_push_calculatevelocity(org, t, this.height);
 -                      tracetoss(e, e);
 -                      if(e.move_movetype == MOVETYPE_NONE)
 -                              waypoint_spawnforteleporter(this, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
 +                      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))
 +                      {
 +                              best_target = trace_endpos;
 +                              best_org = org;
 +                              best_vel = e.velocity;
 +                              valid_best_target = true;
 +                      }
 +
 +                      vector new_org;
 +                      vector dist = t.origin - org;
 +                      if (dist.x || dist.y) // if not perfectly vertical
 +                      {
 +                              // test trajectory with different starting points, sometimes the trajectory
 +                              // starting from the jumppad origin can't reach the real destination
 +                              // and destination waypoint ends up near the jumppad itself
 +                              vector flatdir = normalize(dist - eZ * dist.z);
 +                              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);
 +                              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);
 +                              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 (valid_best_target)
 +                      {
 +                              if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, best_target + PL_MIN_CONST, best_target + PL_MAX_CONST)))
 +                              {
 +                                      float velxy = vlen(vec2(best_vel));
 +                                      float cost = vlen(vec2(t.origin - best_org)) / velxy;
 +                                      if(velxy < autocvar_sv_maxspeed)
 +                                              velxy = autocvar_sv_maxspeed;
 +                                      cost += vlen(vec2(best_target - t.origin)) / velxy;
 +                                      waypoint_spawnforteleporter(this, best_target, cost, e);
 +                              }
 +                      }
                        delete(e);
  #endif
                }
        else
        {
                entity e = spawn();
 -              setorigin(e, org);
                setsize(e, PL_MIN_CONST, PL_MAX_CONST);
 +              e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
 +              setorigin(e, org);
                e.velocity = this.movedir;
                tracetoss(e, e);
 -              waypoint_spawnforteleporter(this, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity));
 +              if (!(boxesoverlap(this.absmin, this.absmax + eZ * 50, trace_endpos + PL_MIN_CONST, trace_endpos + PL_MAX_CONST)))
 +                      waypoint_spawnforteleporter(this, trace_endpos, vlen(trace_endpos - org) / vlen(e.velocity), e);
                delete(e);
        }
  
index d33aadfac8ad3567b1a1543acfd6f6e4e0e11892,aa1884a33592e4634954165bb2cd2d53f81ea666..6d0b3c6a1cae803294d4adb588868ab6da8dba94
@@@ -2,6 -2,7 +2,7 @@@
  
  #include <server/defs.qh>
  #include <server/miscfunctions.qh>
+ #include <server/items.qh>
  #include "havocbot.qh"
  
  #include "../cvars.qh"
@@@ -81,15 -82,14 +82,15 @@@ void havocbot_goalrating_items(entity t
                        continue;
  
                // Check if the item can be picked up safely
-               if(it.classname == "droppedweapon")
+               if(Item_IsLoot(it))
                {
                        if(!IS_ONGROUND(it))
                                continue;
                        traceline(o, o + '0 0 -1500', true, NULL);
  
 -                      if(Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(trace_endpos + '0 0 1')) & DPCONTENTS_LIQUIDSMASK)
 +                      if(IN_LAVA(trace_endpos + '0 0 1'))
                                continue;
 +
                        // this tracebox_hits_trigger_hurt call isn't needed:
                        // dropped weapons are removed as soon as they fall on a trigger_hurt
                        // and can't be rated while they are in the air
@@@ -98,7 -98,9 +99,7 @@@
                }
                else
                {
 -                      // Ignore items under water
 -                      // TODO: can't .waterlevel be used here?
 -                      if(Mod_Q1BSP_SuperContentsFromNativeContents(pointcontents(it.origin + ((it.mins + it.maxs) * 0.5))) & DPCONTENTS_LIQUIDSMASK)
 +                      if(IN_LAVA(it.origin + (it.mins + it.maxs) * 0.5))
                                continue;
                }