]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Bot AI: implement goal locking for goals that require bot to stand on the goal's...
authorterencehill <piuntn@gmail.com>
Tue, 31 Oct 2017 18:09:24 +0000 (19:09 +0100)
committerterencehill <piuntn@gmail.com>
Wed, 1 Nov 2017 01:53:33 +0000 (02:53 +0100)
qcsrc/server/bot/default/havocbot/havocbot.qc
qcsrc/server/bot/default/navigation.qc
qcsrc/server/bot/default/navigation.qh
qcsrc/server/mutators/mutator/gamemode_ctf.qc

index d77c5a18eafd69d9489b464bbfe1111ff11ccc02..86826f6b6f36dfa5388be732eabe777041ce53d2 100644 (file)
@@ -753,6 +753,7 @@ void havocbot_movetogoal(entity this)
                                        navigation_goalrating_timeout_force(this);
                                        return;
                                }
+                               locked_goal = true; // wait for item to respawn
                        }
                        else if(this.goalentity == this.goalcurrent)
                                locked_goal = true; // wait for item to respawn
@@ -767,6 +768,9 @@ void havocbot_movetogoal(entity this)
                        }
                }
        }
+       if (this.goalcurrent == this.goalentity && this.goalentity_lock_timeout > time)
+               locked_goal = true;
+
        if(!locked_goal)
        {
                // optimize path finding by anticipating goalrating when bot is near a waypoint;
@@ -804,7 +808,15 @@ void havocbot_movetogoal(entity this)
        }
 
        diff = destorg - this.origin;
-       //dist = vlen(diff);
+
+       if (fabs(diff.x) < 10 && fabs(diff.y) < 10
+               && this.goalcurrent == this.goalentity && time < this.goalentity_lock_timeout)
+       {
+               destorg = this.origin;
+               diff.x = 0;
+               diff.y = 0;
+       }
+
        dir = normalize(diff);
        flatdir = diff;flatdir.z = 0;
        flatdir = normalize(flatdir);
@@ -866,7 +878,7 @@ void havocbot_movetogoal(entity this)
 
                        // if bot for some reason doesn't get close to the current goal find another one
                        if(!this.jumppadcount && !IS_PLAYER(this.goalcurrent))
-                       if(!(this.goalcurrent.bot_pickup_respawning && this.goalcurrent_distance_z < 50 && this.goalcurrent_distance_2d < 50))
+                       if(!(locked_goal && this.goalcurrent_distance_z < 50 && this.goalcurrent_distance_2d < 50))
                        if(havocbot_checkgoaldistance(this, gco))
                        {
                                if(this.goalcurrent_distance_time < 0) // can't get close for the second time
index 135b5fc68214c95e27e0fe21593fb9a12a915026..c512b8eb421c264cdd736d8f13065375ce71238c 100644 (file)
@@ -625,7 +625,7 @@ void navigation_clearroute(entity this)
        this.goalcurrent_distance_2d = FLOAT_MAX;
        this.goalcurrent_distance_z = FLOAT_MAX;
        this.goalcurrent_distance_time = 0;
-       //print("bot ", etos(this), " clear\n");
+       this.goalentity_lock_timeout = 0;
        this.goalentity = NULL;
        this.goalcurrent = NULL;
        this.goalstack01 = NULL;
@@ -721,7 +721,10 @@ void navigation_poproute(entity this)
        this.goalcurrent_distance_time = 0;
        //print("bot ", etos(this), " pop\n");
        if(this.goalcurrent == this.goalentity)
+       {
                this.goalentity = NULL;
+               this.goalentity_lock_timeout = 0;
+       }
        this.goalcurrent = this.goalstack01;
        this.goalstack01 = this.goalstack02;
        this.goalstack02 = this.goalstack03;
index 90777d30c157e495a969e2e1bbb247a3ef52d141..35036798498178f4e813f1584a1746a8d1195856 100644 (file)
@@ -29,6 +29,8 @@ entity navigation_bestgoal;
 .float goalcurrent_distance_2d;
 .float goalcurrent_distance_time;
 
+.float goalentity_lock_timeout;
+
 .entity nearestwaypoint;
 .float nearestwaypointtimeout;
 
index cd891b6bfb4a8dc49c99798bd9adca340e687f29..739f672ca19f5dc253fc69b02916c96fdd473533 100644 (file)
@@ -540,6 +540,9 @@ void ctf_Handle_Capture(entity flag, entity toucher, int capturetype)
        if(CTF_DIFFTEAM(player, flag)) { return; }
        if((flag.cnt || enemy_flag.cnt) && flag.cnt != enemy_flag.cnt) { return; } // this should catch some edge cases (capturing grouped flag at ungrouped flag disallowed etc)
 
+       if (toucher.goalentity == flag.bot_basewaypoint)
+               toucher.goalentity_lock_timeout = 0;
+
        if(ctf_oneflag)
        for(tmp_entity = ctf_worldflaglist; tmp_entity; tmp_entity = tmp_entity.ctf_worldflagnext)
        if(SAME_TEAM(tmp_entity, player))
@@ -1669,6 +1672,17 @@ void havocbot_role_ctf_carrier(entity this)
 
                navigation_goalrating_timeout_set(this);
 
+               entity head = ctf_worldflaglist;
+               while (head)
+               {
+                       if (this.goalentity == head.bot_basewaypoint)
+                       {
+                               this.goalentity_lock_timeout = time + 5;
+                               break;
+                       }
+                       head = head.ctf_worldflagnext;
+               }
+
                if (this.goalentity)
                        this.havocbot_cantfindflag = time + 10;
                else if (time > this.havocbot_cantfindflag)