]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/bot/default/havocbot/havocbot.qc
Merge remote-tracking branch 'origin/terencehill/bot_waypoints'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / default / havocbot / havocbot.qc
index 969f291690eebe1e55244bf356b4447c7547a222..b82398675c175290a77594bba4b420fc11362647 100644 (file)
@@ -31,6 +31,11 @@ void havocbot_ai(entity this)
        if(this.draggedby)
                return;
 
+       this.bot_aimdir_executed = false;
+       // lock aim if teleported or passing through a warpzone
+       if (this.lastteleporttime && !this.jumppadcount)
+               this.bot_aimdir_executed = true;
+
        if(bot_execute_commands(this))
                return;
 
@@ -106,8 +111,6 @@ void havocbot_ai(entity this)
        havocbot_aim(this);
        lag_update(this);
 
-       this.bot_aimdir_executed = false;
-
        if (this.bot_aimtarg)
        {
                this.aistatus |= AI_STATUS_ATTACKING;
@@ -137,7 +140,7 @@ void havocbot_ai(entity this)
                else
                {
                        if(IS_PLAYER(this.bot_aimtarg))
-                               bot_aimdir(this, this.bot_aimtarg.origin + this.bot_aimtarg.view_ofs - this.origin - this.view_ofs , -1);
+                               bot_aimdir(this, this.bot_aimtarg.origin + this.bot_aimtarg.view_ofs - this.origin - this.view_ofs, 0);
                }
        }
        else if (this.goalcurrent)
@@ -153,7 +156,7 @@ void havocbot_ai(entity this)
                vector dir = get_closer_dest(this.goalcurrent, this.origin);
                dir -= this.origin + this.view_ofs;
                dir.z = 0;
-               bot_aimdir(this, dir, -1);
+               bot_aimdir(this, dir, 0);
        }
 
        // if the bot is not attacking, consider reloading weapons
@@ -577,7 +580,7 @@ void havocbot_movetogoal(entity this)
                                        this.aistatus &= ~AI_STATUS_OUT_JUMPPAD;
                                }
                        }
-                       else
+                       else //if (this.goalcurrent)
                        {
                                if (this.goalcurrent.bot_pickup)
                                {
@@ -601,9 +604,9 @@ void havocbot_movetogoal(entity this)
                                        return;
                        }
                }
-               else
+               else //if (!(this.aistatus & AI_STATUS_OUT_JUMPPAD))
                {
-                       if(time - this.lastteleporttime > 0.2 && this.velocity.z > 0)
+                       if(this.origin.z - this.lastteleport_origin.z > (this.maxs.z - this.mins.z) * 0.5)
                        {
                                vector velxy = this.velocity; velxy_z = 0;
                                if(vdist(velxy, <, autocvar_sv_maxspeed * 0.2))
@@ -794,8 +797,26 @@ void havocbot_movetogoal(entity this)
                        // don't remove if not visible
                        if (checkpvs(this.origin + this.view_ofs, this.goalcurrent))
                        {
-                               navigation_goalrating_timeout_force(this);
-                               return;
+                               if (IS_DEAD(this.goalcurrent))
+                               {
+                                       IL_EACH(g_items, it.enemy == this.goalcurrent && Item_IsLoot(it),
+                                       {
+                                               if (vdist(it.origin - this.goalcurrent.death_origin, <, 50))
+                                               {
+                                                       navigation_clearroute(this);
+                                                       navigation_pushroute(this, it);
+                                                       // loot can't be immediately rated since it isn't on ground yet
+                                                       // it will be rated after a second when on ground, meanwhile head to it
+                                                       navigation_goalrating_timeout_expire(this, 1);
+                                                       return;
+                                               }
+                                       });
+                               }
+                               if (!Item_IsLoot(this.goalcurrent))
+                               {
+                                       navigation_goalrating_timeout_force(this);
+                                       return;
+                               }
                        }
                }
                else if (!(STAT(FROZEN, this.goalentity)) && this.bot_tracewalk_time < time)
@@ -881,7 +902,8 @@ void havocbot_movetogoal(entity this)
 
        diff = destorg - this.origin;
 
-       if (this.goalcurrent == this.goalentity && time < this.goalentity_lock_timeout && vdist(diff, <, 10))
+       if (time < this.bot_stop_moving_timeout
+               || (this.goalcurrent == this.goalentity && time < this.goalentity_lock_timeout && vdist(diff, <, 10)))
        {
                // stop if the locked goal has been reached
                destorg = this.origin;
@@ -928,12 +950,18 @@ void havocbot_movetogoal(entity this)
                        }
                        else
                        {
-                               dir = flatdir;
                                if(this.velocity.z >= 0 && !(this.watertype == CONTENT_WATER && destorg.z < this.origin.z) &&
                                        (this.aistatus & AI_STATUS_OUT_WATER))
+                               {
                                        PHYS_INPUT_BUTTON_JUMP(this) = true;
+                                       dir = flatdir;
+                               }
                                else
+                               {
                                        PHYS_INPUT_BUTTON_JUMP(this) = false;
+                                       if (destorg.z > this.origin.z)
+                                               dir = flatdir;
+                               }
                        }
                }
                else
@@ -1065,6 +1093,12 @@ void havocbot_movetogoal(entity this)
                        // Check for water/slime/lava and dangerous edges
                        // (only when the bot is on the ground or jumping intentionally)
 
+                       if (skill + this.bot_moveskill <= 3 && time > this.bot_stop_moving_timeout
+                               && current_speed > maxspeed * 0.9 && fabs(deviation.y) > 70)
+                       {
+                               this.bot_stop_moving_timeout = time + 0.4 + random() * 0.2;
+                       }
+
                        offset = (vdist(this.velocity, >, 32) ? this.velocity * 0.2 : v_forward * 32);
                        vector dst_ahead = this.origin + this.view_ofs + offset;
                        vector dst_down = dst_ahead - '0 0 3000';
@@ -1168,13 +1202,11 @@ void havocbot_movetogoal(entity this)
                }
                if (ladder_zdir)
                {
-                       if (vdist(flatdir, <, 15))
-                               dir = ladder_zdir * '0 0 1';
+                       if (vdist(vec2(diff), <, 40))
+                               dir.z = ladder_zdir * 4;
                        else
-                       {
-                               dir.z = ladder_zdir * 1.3;
-                               dir = normalize(dir);
-                       }
+                               dir.z = ladder_zdir * 2;
+                       dir = normalize(dir);
                }
        }
 
@@ -1188,8 +1220,14 @@ void havocbot_movetogoal(entity this)
                dir = normalize(dir);
        }
 
+       // already executed when bot targets an enemy
        if (!this.bot_aimdir_executed)
-               bot_aimdir(this, dir, -1);
+       {
+               if (time < this.bot_stop_moving_timeout)
+                       bot_aimdir(this, normalize(this.goalcurrent.origin - this.origin), 0);
+               else
+                       bot_aimdir(this, dir, 0);
+       }
 
        if (!ladder_zdir)
        {
@@ -1561,14 +1599,14 @@ float havocbot_moveto(entity this, vector pos)
                        vector dir = get_closer_dest(this.goalcurrent, this.origin);
                        dir -= this.origin + this.view_ofs;
                        dir.z = 0;
-                       bot_aimdir(this, dir, -1);
+                       bot_aimdir(this, dir, 0);
                }
 
                if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_REACHED)
                {
                        // Step 5: Waypoint reached
                        LOG_TRACE(this.netname, "'s personal waypoint reached");
-                       delete(this.havocbot_personal_waypoint);
+                       waypoint_remove(this.havocbot_personal_waypoint);
                        this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_REACHED;
                        return CMD_STATUS_FINISHED;
                }