]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Bot AI: when assigning a bot frame to find a new goal prioritize bots that have just...
authorterencehill <piuntn@gmail.com>
Thu, 2 Nov 2017 22:17:38 +0000 (23:17 +0100)
committerterencehill <piuntn@gmail.com>
Fri, 3 Nov 2017 11:23:59 +0000 (12:23 +0100)
qcsrc/server/bot/api.qh
qcsrc/server/bot/default/bot.qc
qcsrc/server/bot/default/havocbot/havocbot.qc
qcsrc/server/bot/default/navigation.qc

index 1bab0b02b7b4afcf6eb8ee57ee5741c4de0a2e78..cde97db885a3e962c7dc49d1363f29f796331095 100644 (file)
@@ -87,6 +87,7 @@ void navigation_goalrating_end(entity this);
 void navigation_goalrating_start(entity this);
 void navigation_goalrating_timeout_set(entity this);
 void navigation_goalrating_timeout_force(entity this);
+void navigation_goalrating_timeout_expire(entity this, float seconds);
 bool navigation_goalrating_timeout(entity this);
 bool navigation_goalrating_timeout_can_be_anticipated(entity this);
 void navigation_markroutes(entity this, entity fixed_source_waypoint);
index 61a69747c79517341a1c96232ef1df854cbc1168..23a58dca8feecbcc53a80ed4247ec615483d5ba3 100644 (file)
@@ -770,6 +770,8 @@ void bot_serverframe()
                //  frame, which causes choppy framerates)
                if (bot_strategytoken_taken)
                {
+                       // give goal token to the first bot without goals; if all bots don't have
+                       // any goal (or are dead/frozen) simply give it to the next one
                        bot_strategytoken_taken = false;
                        entity bot_strategytoken_save = bot_strategytoken;
                        while (true)
@@ -779,7 +781,8 @@ void bot_serverframe()
                                if (!bot_strategytoken)
                                        bot_strategytoken = bot_list;
 
-                               if (!(IS_DEAD(bot_strategytoken) || STAT(FROZEN, bot_strategytoken)))
+                               if (!(IS_DEAD(bot_strategytoken) || STAT(FROZEN, bot_strategytoken))
+                                       && !bot_strategytoken.goalcurrent)
                                        break;
 
                                if (!bot_strategytoken_save) // break loop if all the bots are dead or frozen
index 98f8b790bd898ccf1f69fbeeed29fcdb6a604b50..7ca929859b67be15b4aa9718aa50bc93887f73cc 100644 (file)
@@ -752,9 +752,7 @@ void havocbot_movetogoal(entity this)
                                if(checkpvs(this.origin, this.goalentity))
                                {
                                        this.goalentity.bot_pickup_respawning = false;
-                                       navigation_clearroute(this);
-                                       navigation_goalrating_timeout_force(this);
-                                       return;
+                                       navigation_goalrating_timeout_expire(this, random());
                                }
                                locked_goal = true; // wait for item to respawn
                        }
@@ -765,9 +763,7 @@ void havocbot_movetogoal(entity this)
                {
                        if(checkpvs(this.origin, this.goalentity))
                        {
-                               navigation_clearroute(this);
-                               navigation_goalrating_timeout_force(this);
-                               return;
+                               navigation_goalrating_timeout_expire(this, random());
                        }
                }
        }
@@ -797,7 +793,7 @@ void havocbot_movetogoal(entity this)
        if(autocvar_bot_debug_goalstack)
                debuggoalstack(this);
 
-       bool bunnyhop_forbidden = false;;
+       bool bunnyhop_forbidden = false;
        SET_DESTCOORDS(this.goalcurrent, this.origin, destorg);
 
        // in case bot ends up inside the teleport waypoint without touching
index cd21f7aa8767028a43e5e60f7c70954fef48b664..d2b073b5c9037f2cca16593fc467a6ca2e45fa4d 100644 (file)
@@ -25,9 +25,20 @@ void navigation_goalrating_timeout_set(entity this)
                this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
 }
 
+// use this when current goal must be discarded immediately
 void navigation_goalrating_timeout_force(entity this)
 {
-       this.bot_strategytime = 0;
+       navigation_goalrating_timeout_expire(this, 0);
+}
+
+// use this when current goal can be kept for a short while to increase the chance
+// of bot touching a waypoint, which helps to find a new goal more efficiently
+void navigation_goalrating_timeout_expire(entity this, float seconds)
+{
+       if (seconds <= 0)
+               this.bot_strategytime = 0;
+       else if (this.bot_strategytime > time + seconds)
+               this.bot_strategytime = time + seconds;
 }
 
 bool navigation_goalrating_timeout(entity this)