]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'terencehill/bot_waypoints' into terencehill/bot_ai
authorterencehill <piuntn@gmail.com>
Mon, 15 Jan 2018 16:57:12 +0000 (17:57 +0100)
committerterencehill <piuntn@gmail.com>
Mon, 15 Jan 2018 16:57:12 +0000 (17:57 +0100)
# Conflicts:
# qcsrc/server/mutators/mutator/gamemode_race.qc

28 files changed:
defaultServer.cfg
qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc
qcsrc/common/t_items.qc
qcsrc/common/t_items.qh
qcsrc/common/triggers/trigger/jumppads.qc
qcsrc/common/triggers/trigger/jumppads.qh
qcsrc/server/autocvars.qh
qcsrc/server/bot/api.qh
qcsrc/server/bot/default/aim.qc
qcsrc/server/bot/default/aim.qh
qcsrc/server/bot/default/bot.qc
qcsrc/server/bot/default/havocbot/havocbot.qc
qcsrc/server/bot/default/havocbot/havocbot.qh
qcsrc/server/bot/default/havocbot/roles.qc
qcsrc/server/bot/default/navigation.qc
qcsrc/server/bot/default/navigation.qh
qcsrc/server/bot/default/waypoints.qc
qcsrc/server/mutators/mutator/gamemode_assault.qc
qcsrc/server/mutators/mutator/gamemode_assault.qh
qcsrc/server/mutators/mutator/gamemode_ctf.qc
qcsrc/server/mutators/mutator/gamemode_ctf.qh
qcsrc/server/mutators/mutator/gamemode_cts.qc
qcsrc/server/mutators/mutator/gamemode_domination.qc
qcsrc/server/mutators/mutator/gamemode_freezetag.qc
qcsrc/server/mutators/mutator/gamemode_keepaway.qc
qcsrc/server/mutators/mutator/gamemode_keyhunt.qc
qcsrc/server/mutators/mutator/gamemode_race.qc
qcsrc/server/utils.qh

index db91e385495a17e66d07aa3dfb8c955476085f2f..739746267769380cc8cd599a5f944bc91e477a9d 100644 (file)
@@ -116,7 +116,8 @@ set bot_debug_goalstack 0 "Visualize the current path that each bot is following
 set bot_wander_enable 1 "Have bots wander around if they are unable to reach any useful goal. Disable only for debugging purposes."
 // general bot AI cvars
 set bot_ai_thinkinterval 0.05
-set bot_ai_strategyinterval 5 "How often a new objective is chosen"
+set bot_ai_strategyinterval 7 "How often a new objective is chosen"
+set bot_ai_strategyinterval_movingtarget 5.5 "How often a new objective is chosen when current objective can move"
 set bot_ai_enemydetectioninterval 2 "How often bots pick a new target"
 set bot_ai_enemydetectionradius 10000 "How far bots can see enemies"
 set bot_ai_dodgeupdateinterval 0.2 "How often scan for items to dodge. Currently not in use."
index 0150de3925ee90072b040e2f5d132cd301a736ad..5a0e0975e528e7315c90e4ccf6e17199ac32e59e 100644 (file)
@@ -1488,7 +1488,7 @@ void havocbot_role_ons_offense(entity this)
        if(this.havocbot_attack_time>time)
                return;
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
                navigation_goalrating_start(this);
                havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
@@ -1497,7 +1497,7 @@ void havocbot_role_ons_offense(entity this)
                havocbot_goalrating_ons_offenseitems(this, 10000, this.origin, 10000);
                navigation_goalrating_end(this);
 
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+               navigation_goalrating_timeout_set(this);
        }
 }
 
index fa6d0f6f313510dd1bc6a8e1a6e921a425d7e1b0..feefd10985aa37763770520146704e307b78ae87 100644 (file)
@@ -1126,8 +1126,6 @@ float ammo_pickupevalfunc(entity player, entity item)
        return rating;
 }
 
-.int item_group;
-.int item_group_count;
 float healtharmor_pickupevalfunc(entity player, entity item)
 {
        float c = 0;
index 3740c9a576d5ee045a8d80660fbbbc6170399cc1..5d815cef928419eebc8b281fbba3e2423d275cbe 100644 (file)
@@ -26,6 +26,8 @@ const int ISF_SIZE                            = BIT(7);
 
 #ifdef SVQC
 void StartItem(entity this, entity a);
+.int item_group;
+.int item_group_count;
 #endif
 
 #ifdef CSQC
index 11ea2f360aba51619735f23d109e857d9a554510..9e40cfd40178224fc9c48efe76cece7de982253a 100644 (file)
@@ -216,7 +216,7 @@ bool jumppad_push(entity this, entity targ)
                                animdecide_setaction(targ, ANIMACTION_JUMP, true);
                }
                else
-                       targ.jumppadcount = true;
+                       targ.jumppadcount = 1;
 
                // reset tracking of who pushed you into a hazard (for kill credit)
                targ.pushltime = 0;
@@ -310,7 +310,10 @@ bool trigger_push_testorigin(entity tracetest_ent, entity targ, entity jp, vecto
        return true;
 }
 #endif
-void trigger_push_findtarget(entity this)
+
+/// if (item != NULL) returns true if the item can be reached by using this jumppad, false otherwise
+/// if (item == NULL) tests jumppad's trajectory and eventually spawns waypoints for it (return value doesn't matter)
+bool trigger_push_test(entity this, entity item)
 {
        // first calculate a typical start point for the jump
        vector org = (this.absmin + this.absmax) * 0.5;
@@ -333,6 +336,16 @@ void trigger_push_findtarget(entity this)
                        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, 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';
@@ -397,13 +410,16 @@ void trigger_push_findtarget(entity this)
 #endif
                }
 
+               if(item)
+                       return false;
+
                if(!n)
                {
                        // no dest!
 #ifdef SVQC
                        objerror (this, "Jumppad with nonexistant target");
 #endif
-                       return;
+                       return false;
                }
                else if(n == 1)
                {
@@ -425,6 +441,12 @@ void trigger_push_findtarget(entity this)
                setorigin(e, org);
                e.velocity = this.movedir;
                tracetoss(e, e);
+               if(item)
+               {
+                       bool r = (trace_ent == item);
+                       delete(e);
+                       return r;
+               }
                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);
@@ -432,6 +454,12 @@ void trigger_push_findtarget(entity this)
 
        defer(this, 0.1, trigger_push_updatelink);
 #endif
+       return true;
+}
+
+void trigger_push_findtarget(entity this)
+{
+       trigger_push_test(this, NULL);
 }
 
 #ifdef SVQC
@@ -496,6 +524,8 @@ spawnfunc(trigger_push)
 
        trigger_push_link(this); // link it now
 
+       IL_PUSH(g_jumppads, this);
+
        // this must be called to spawn the teleport waypoints for bots
        InitializeEntity(this, trigger_push_findtarget, INITPRIO_FINDTARGET);
 }
index c3b0b339def6c2f0f7b8e5c35f6773c91bcb4aea..50ed0a343c8c86b7cc53e12274ddac7261bead75 100644 (file)
@@ -1,5 +1,8 @@
 #pragma once
 
+IntrusiveList g_jumppads;
+STATIC_INIT(g_jumppads) { g_jumppads = IL_NEW(); }
+
 const float PUSH_ONCE          = 1;
 const float PUSH_SILENT                = 2;
 
@@ -14,6 +17,7 @@ const int NUM_JUMPPADSUSED = 3;
 #ifdef SVQC
 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);
 #endif
 
 /*
@@ -33,6 +37,7 @@ vector trigger_push_calculatevelocity(vector org, entity tgt, float ht, entity p
 void trigger_push_touch(entity this, entity toucher);
 
 .vector dest;
+bool trigger_push_test(entity this, entity item);
 void trigger_push_findtarget(entity this);
 
 /*
index b71d4459d1387469f9c1732fa906dda15617f965..4b3745dc00784589e9c288854c3b6f948bfbfbd8 100644 (file)
@@ -6,6 +6,7 @@ int autocvar__campaign_index;
 string autocvar__campaign_name;
 bool autocvar__sv_init;
 float autocvar_bot_ai_strategyinterval;
+float autocvar_bot_ai_strategyinterval_movingtarget;
 #define autocvar_bot_number cvar("bot_number")
 int autocvar_bot_vs_human;
 int autocvar_captureleadlimit_override;
index 86442178c1e0068b4b24886fa7a79f2caefeed58..51ac148fc13c42c1185866cd87d6430165f61b8e 100644 (file)
@@ -6,7 +6,7 @@
 
 const int WAYPOINTFLAG_GENERATED = BIT(23);
 const int WAYPOINTFLAG_ITEM = BIT(22);
-const int WAYPOINTFLAG_TELEPORT = BIT(21);
+const int WAYPOINTFLAG_TELEPORT = BIT(21); // teleports, warpzones and jumppads
 const int WAYPOINTFLAG_NORELINK = BIT(20);
 const int WAYPOINTFLAG_PERSONAL = BIT(19);
 const int WAYPOINTFLAG_PROTECTED = BIT(18);  // Useless WP detection never kills these.
@@ -23,6 +23,7 @@ float bot_weapons_far[Weapons_MAX];
 float bot_weapons_mid[Weapons_MAX];
 float skill;
 
+.float bot_tracewalk_time;
 .float bot_attack;
 .float bot_dodgerating;
 .float bot_dodge;
@@ -30,9 +31,10 @@ float skill;
 .float bot_moveskill; // moving technique
 .float bot_pickup;
 .float(entity player, entity item) bot_pickupevalfunc;
-.float bot_strategytime;
 .string cleanname;
 .float havocbot_role_timeout;
+.void(entity this) havocbot_role;
+.void(entity this) havocbot_previous_role;
 .float isbot; // true if this client is actually a bot
 .float lastteleporttime;
 .vector lastteleport_origin;
@@ -73,10 +75,16 @@ void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org
 void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius);
 void havocbot_goalrating_waypoints(entity this, float ratingscale, vector org, float sradius);
 
+bool havocbot_goalrating_item_pickable_check_players(entity this, vector org, entity item, vector item_org);
+
 vector havocbot_middlepoint;
 float havocbot_middlepoint_radius;
 vector havocbot_symmetryaxis_equation;
 
+.float goalentity_lock_timeout;
+.float ignoregoaltime;
+.entity ignoregoal;
+
 .entity bot_basewaypoint;
 .bool navigation_dynamicgoal;
 void navigation_dynamicgoal_init(entity this, bool initially_static);
@@ -85,10 +93,19 @@ void navigation_dynamicgoal_unset(entity this);
 entity navigation_findnearestwaypoint(entity ent, float walkfromwp);
 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);
 void navigation_markroutes_inverted(entity fixed_source_waypoint);
 void navigation_routerating(entity this, entity e, float f, float rangebias);
 
+vector get_closer_dest(entity ent, vector org);
+
+void set_tracewalk_dest(entity ent, vector org, bool fix_player_dest);
+vector set_tracewalk_dest_2(entity ent, vector org);
 bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float end_height, float movemode);
 
 void waypoint_remove_fromeditor(entity pl);
@@ -103,6 +120,3 @@ void waypoint_spawnforteleporter_wz(entity e, vector org, vector destination, fl
 void waypoint_spawn_fromeditor(entity pl);
 entity waypoint_spawn(vector m1, vector m2, float f);
 void waypoint_unreachable(entity pl);
-
-.entity goalcurrent;
-void navigation_clearroute(entity this);
index 8f2abb3f824b5745448a5fb4c16ab21545e5451b..7441ce7bcab56cfafd3cf9e1ac8b6b68eab9385d 100644 (file)
@@ -174,7 +174,7 @@ void bot_lagfunc(entity this, float t, float f1, float f2, entity e1, vector v1,
                this.bot_canfire = 1;
 }
 
-float bot_aimdir(entity this, vector v, float maxfiredeviation)
+void bot_aimdir(entity this, vector v, float maxfiredeviation)
 {
        float dist, delta_t, blend;
        vector desiredang, diffang;
@@ -184,6 +184,9 @@ float bot_aimdir(entity this, vector v, float maxfiredeviation)
        this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360;
        this.v_angle_z = 0;
 
+       // invalid aim dir (can happen when bot overlaps target)
+       if(!v) return;
+
        // get the desired angles to aim at
        //dprint(" at:", vtos(v));
        v = normalize(v);
@@ -314,7 +317,7 @@ float bot_aimdir(entity this, vector v, float maxfiredeviation)
        //dprint(ftos(maxfiredeviation),"\n");
        //dprint(" diff:", vtos(diffang), "\n");
 
-       return this.bot_canfire && (time < this.bot_firetimer);
+       //return this.bot_canfire && (time < this.bot_firetimer);
 }
 
 vector bot_shotlead(vector targorigin, vector targvelocity, float shotspeed, float shotdelay)
@@ -325,7 +328,7 @@ vector bot_shotlead(vector targorigin, vector targvelocity, float shotspeed, flo
 
 bool bot_aim(entity this, .entity weaponentity, float shotspeed, float shotspeedupward, float maxshottime, bool applygravity)
 {
-       float f, r, hf, distanceratio;
+       float r, hf, distanceratio;
        vector v;
        /*
        eprint(this);
@@ -367,11 +370,11 @@ bool bot_aim(entity this, .entity weaponentity, float shotspeed, float shotspeed
                        return false;
                }
 
-               f = bot_aimdir(this, findtrajectory_velocity - shotspeedupward * '0 0 1', r);
+               bot_aimdir(this, findtrajectory_velocity - shotspeedupward * '0 0 1', r);
        }
        else
        {
-               f = bot_aimdir(this, v - shotorg, r);
+               bot_aimdir(this, v - shotorg, r);
                //dprint("AIM: ");dprint(vtos(this.bot_aimtargorigin));dprint(" + ");dprint(vtos(this.bot_aimtargvelocity));dprint(" * ");dprint(ftos(this.bot_aimlatency + vlen(this.bot_aimtargorigin - shotorg) / shotspeed));dprint(" = ");dprint(vtos(v));dprint(" : aimdir = ");dprint(vtos(normalize(v - shotorg)));dprint(" : ");dprint(vtos(shotdir));dprint("\n");
                //traceline(shotorg, shotorg + shotdir * 10000, false, this);
                //if (trace_ent.takedamage)
index e7c60758aec2eca3c46fe3c588a8cce4e635551e..b8b35f1c203a08968e3b82e7029bbfd17109e6dd 100644 (file)
@@ -90,7 +90,7 @@ void lag_update(entity this);
 void bot_lagfunc(entity this, float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4);
 
 float bot_shouldattack(entity this, entity targ);
-float bot_aimdir(entity this, vector v, float maxfiredeviation);
+void bot_aimdir(entity this, vector v, float maxfiredeviation);
 bool bot_aim(entity this, .entity weaponentity, float shotspeed, float shotspeedupward, float maxshottime, bool applygravity);
 float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, float shotspeed, float shotspeedupward, float maxtime, float shotdelay, entity ignore);
 
index a056b25a768de115a62c371f47a351bd6dba2eb6..af238029abd85042eb7e72e8f2de43f0a0c6dd94 100644 (file)
@@ -133,7 +133,7 @@ void bot_think(entity this)
                if (this.deadflag == DEAD_DEAD)
                {
                        PHYS_INPUT_BUTTON_JUMP(this) = true; // press jump to respawn
-                       this.bot_strategytime = 0;
+                       navigation_goalrating_timeout_force(this);
                }
        }
        else if(this.aistatus & AI_STATUS_STUCK)
@@ -769,11 +769,26 @@ 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;
-                       if (bot_strategytoken)
-                               bot_strategytoken = bot_strategytoken.nextbot;
-                       if (!bot_strategytoken)
-                               bot_strategytoken = bot_list;
+                       entity bot_strategytoken_save = bot_strategytoken;
+                       while (true)
+                       {
+                               if (bot_strategytoken)
+                                       bot_strategytoken = bot_strategytoken.nextbot;
+                               if (!bot_strategytoken)
+                                       bot_strategytoken = bot_list;
+
+                               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
+                                       break;
+                               if (bot_strategytoken == bot_strategytoken_save)
+                                       bot_strategytoken_save = NULL; // looped through all the bots
+                       }
                }
 
                if (botframe_nextdangertime < time)
index 439ef5471525c4486e99221fc8d6fb9921e27410..2a0d0c8503f005c17d2156fd2871ebf216ac932d 100644 (file)
@@ -33,8 +33,7 @@ void havocbot_ai(entity this)
        if(bot_execute_commands(this))
                return;
 
-       if (bot_strategytoken == this)
-       if (!bot_strategytoken_taken)
+       if (bot_strategytoken == this && !bot_strategytoken_taken)
        {
                if(this.havocbot_blockhead)
                {
@@ -85,7 +84,11 @@ void havocbot_ai(entity this)
        }
 
        if(IS_DEAD(this) || STAT(FROZEN, this))
+       {
+               if (this.goalcurrent)
+                       navigation_clearroute(this);
                return;
+       }
 
        havocbot_chooseenemy(this);
 
@@ -138,10 +141,10 @@ void havocbot_ai(entity this)
                this.aistatus |= AI_STATUS_ROAMING;
                this.aistatus &= ~AI_STATUS_ATTACKING;
 
-               vector v = '0 0 0', now, next;
+               vector now, next;
                float aimdistance,skillblend,distanceblend,blend;
 
-               SET_DESTCOORDS(this.goalcurrent, this.origin, v);
+               vector v = get_closer_dest(this.goalcurrent, this.origin);
                if(this.goalcurrent.wpisbox)
                {
                        // avoid a glitch when bot is teleported but teleport waypoint isn't removed yet
@@ -286,7 +289,6 @@ void havocbot_bunnyhop(entity this, vector dir)
        float bunnyhopdistance;
        vector deviation;
        float maxspeed;
-       vector gco = '0 0 0', gno;
 
        // Don't jump when attacking
        if(this.aistatus & AI_STATUS_ATTACKING)
@@ -319,7 +321,7 @@ void havocbot_bunnyhop(entity this, vector dir)
                this.bot_timelastseengoal = 0;
        }
 
-       SET_DESTCOORDS(this.goalcurrent, this.origin, gco);
+       vector gco = get_closer_dest(this.goalcurrent, this.origin);
        bunnyhopdistance = vlen(this.origin - gco);
 
        // Run only to visible goals
@@ -356,7 +358,7 @@ void havocbot_bunnyhop(entity this, vector dir)
                                        if(fabs(gco.z - this.origin.z) < this.maxs.z - this.mins.z)
                                        if(this.goalstack01 && !wasfreed(this.goalstack01))
                                        {
-                                               gno = (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5;
+                                               vector gno = (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5;
                                                deviation = vectoangles(gno - this.origin) - vectoangles(gco - this.origin);
                                                while (deviation.y < -180) deviation.y = deviation.y + 360;
                                                while (deviation.y > 180) deviation.y = deviation.y - 360;
@@ -429,33 +431,64 @@ void havocbot_bunnyhop(entity this, vector dir)
 // return true when bot isn't getting closer to the current goal
 bool havocbot_checkgoaldistance(entity this, vector gco)
 {
-       float curr_dist = vlen(this.origin - gco);
-       if(curr_dist > this.goalcurrent_distance)
+       float curr_dist_z = max(20, fabs(this.origin.z - gco.z));
+       float curr_dist_2d = max(20, vlen(vec2(this.origin - gco)));
+       float distance_time = this.goalcurrent_distance_time;
+       if(distance_time < 0)
+               distance_time = -distance_time;
+       if(curr_dist_z >= this.goalcurrent_distance_z && curr_dist_2d >= this.goalcurrent_distance_2d)
        {
-               if(!this.goalcurrent_distance_time)
+               if(!distance_time)
                        this.goalcurrent_distance_time = time;
-               else if (time - this.goalcurrent_distance_time > 0.5)
+               else if (time - distance_time > 0.5)
                        return true;
        }
        else
        {
                // reduce it a little bit so it works even with very small approaches to the goal
-               this.goalcurrent_distance = max(20, curr_dist - 15);
+               this.goalcurrent_distance_z = max(20, curr_dist_z - 10);
+               this.goalcurrent_distance_2d = max(20, curr_dist_2d - 10);
                this.goalcurrent_distance_time = 0;
        }
        return false;
 }
 
+entity havocbot_select_an_item_of_group(entity this, int gr)
+{
+       entity selected = NULL;
+       float selected_dist2 = 0;
+       // select farthest item of this group from bot's position
+       IL_EACH(g_items, it.item_group == gr && it.solid,
+       {
+               float dist2 = vlen2(this.origin - it.origin);
+               if (dist2 < 600 ** 2 && dist2 > selected_dist2)
+               {
+                       selected = it;
+                       selected_dist2 = vlen2(this.origin - selected.origin);
+               }
+       });
+
+       if (!selected)
+               return NULL;
+
+       set_tracewalk_dest(selected, this.origin, false);
+       if (!tracewalk(this, this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this),
+               tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode))
+       {
+               return NULL;
+       }
+
+       return selected;
+}
+
 void havocbot_movetogoal(entity this)
 {
-       vector destorg = '0 0 0';
        vector diff;
        vector dir;
        vector flatdir;
        vector evadeobstacle;
        vector evadelava;
        float maxspeed;
-       vector gco;
        //float dist;
        vector dodge;
        //if (this.goalentity)
@@ -463,8 +496,8 @@ void havocbot_movetogoal(entity this)
        CS(this).movement = '0 0 0';
        maxspeed = autocvar_sv_maxspeed;
 
+       PHYS_INPUT_BUTTON_JETPACK(this) = false;
        // Jetpack navigation
-       if(this.goalcurrent)
        if(this.navigation_jetpack_goal)
        if(this.goalcurrent==this.navigation_jetpack_goal)
        if(this.ammo_fuel)
@@ -491,18 +524,14 @@ void havocbot_movetogoal(entity this)
                if(this.aistatus & AI_STATUS_JETPACK_LANDING)
                {
                        // Calculate brake distance in xy
-                       float db, v, d;
-                       vector dxy;
-
-                       dxy = this.origin - ( ( this.goalcurrent.absmin + this.goalcurrent.absmax ) * 0.5 ); dxy.z = 0;
-                       d = vlen(dxy);
-                       v = vlen(this.velocity -  this.velocity.z * '0 0 1');
-                       db = ((v ** 2) / (autocvar_g_jetpack_acceleration_side * 2)) + 100;
-               //      dprint("distance ", ftos(ceil(d)), " velocity ", ftos(ceil(v)), " brake at ", ftos(ceil(db)), "\n");
+                       float d = vlen(vec2(this.origin - (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5));
+                       float v = vlen(vec2(this.velocity));
+                       float db = ((v ** 2) / (autocvar_g_jetpack_acceleration_side * 2)) + 100;
+                       //LOG_INFOF("distance %d, velocity %d, brake at %d ", ceil(d), ceil(v), ceil(db));
                        if(d < db || d < 500)
                        {
                                // Brake
-                               if(fabs(this.velocity.x)>maxspeed*0.3)
+                               if(v > maxspeed * 0.3)
                                {
                                        CS(this).movement_x = dir * v_forward * -maxspeed;
                                        return;
@@ -523,7 +552,7 @@ void havocbot_movetogoal(entity this)
                }
 
                // Flying
-               PHYS_INPUT_BUTTON_HOOK(this) = true;
+               PHYS_INPUT_BUTTON_JETPACK(this) = true;
                if(this.navigation_jetpack_point.z - STAT(PL_MAX, this).z + STAT(PL_MIN, this).z < this.origin.z)
                {
                        CS(this).movement_x = dir * v_forward * maxspeed;
@@ -576,13 +605,23 @@ void havocbot_movetogoal(entity this)
                        }
                        else
                        {
-                               gco = (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5;
+                               if (this.goalcurrent.bot_pickup)
+                               {
+                                       entity jumppad_wp = this.goalcurrent_prev;
+                                       navigation_poptouchedgoals(this);
+                                       if(!this.goalcurrent && jumppad_wp.wp00)
+                                       {
+                                               // head to the jumppad destination once bot reaches the goal item
+                                               navigation_pushroute(this, jumppad_wp.wp00);
+                                       }
+                               }
+                               vector gco = (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5;
                                if (this.origin.z > gco.z && vdist(vec2(this.velocity), <, autocvar_sv_maxspeed))
                                        this.aistatus &= ~AI_STATUS_OUT_JUMPPAD;
                                else if(havocbot_checkgoaldistance(this, gco))
                                {
                                        navigation_clearroute(this);
-                                       this.bot_strategytime = 0;
+                                       navigation_goalrating_timeout_force(this);
                                }
                                else
                                        return;
@@ -610,9 +649,12 @@ void havocbot_movetogoal(entity this)
                this.aistatus &= ~AI_STATUS_OUT_JUMPPAD;
 
        // If there is a trigger_hurt right below try to use the jetpack or make a rocketjump
-       if(skill>6)
-       if (!(IS_ONGROUND(this)))
+       if (skill > 6 && !(IS_ONGROUND(this)))
        {
+               #define ROCKETJUMP_DAMAGE() WEP_CVAR(devastator, damage) * 0.8 \
+                       * ((this.strength_finished > time) ? autocvar_g_balance_powerup_strength_selfdamage : 1) \
+                       * ((this.invincible_finished > time) ? autocvar_g_balance_powerup_invincible_takedamage : 1)
+
                tracebox(this.origin, this.mins, this.maxs, this.origin + '0 0 -65536', MOVE_NOMONSTERS, this);
                if(tracebox_hits_trigger_hurt(this.origin, this.mins, this.maxs, trace_endpos ))
                if(this.items & IT_JETPACK)
@@ -621,12 +663,10 @@ void havocbot_movetogoal(entity this)
                        if(tracebox_hits_trigger_hurt(this.origin, this.mins, this.maxs, trace_endpos + '0 0 1' ))
                        {
                                if(this.velocity.z<0)
-                               {
-                                       PHYS_INPUT_BUTTON_HOOK(this) = true;
-                               }
+                                       PHYS_INPUT_BUTTON_JETPACK(this) = true;
                        }
                        else
-                               PHYS_INPUT_BUTTON_HOOK(this) = true;
+                               PHYS_INPUT_BUTTON_JETPACK(this) = true;
 
                        // If there is no goal try to move forward
 
@@ -655,7 +695,7 @@ void havocbot_movetogoal(entity this)
 
                        return;
                }
-               else if(this.health > WEP_CVAR(devastator, damage) * 0.5 * ((this.strength_finished < time) ? autocvar_g_balance_powerup_strength_selfdamage : 1))
+               else if(this.health + this.armorvalue > ROCKETJUMP_DAMAGE())
                {
                        if(this.velocity.z < 0)
                        {
@@ -698,8 +738,7 @@ void havocbot_movetogoal(entity this)
        }
 
        // If we are under water with no goals, swim up
-       if(this.waterlevel)
-       if(this.goalcurrent==NULL)
+       if(this.waterlevel && !this.goalcurrent)
        {
                dir = '0 0 0';
                if(this.waterlevel>WATERLEVEL_SWIMMING)
@@ -720,12 +759,17 @@ void havocbot_movetogoal(entity this)
 
 
        bool locked_goal = false;
-       if(this.goalentity && wasfreed(this.goalentity))
+       if((this.goalentity && wasfreed(this.goalentity))
+               || (this.goalcurrent == this.goalentity && this.goalentity.tag_entity))
        {
                navigation_clearroute(this);
-               this.bot_strategytime = 0;
+               navigation_goalrating_timeout_force(this);
                return;
        }
+       else if(this.goalentity.tag_entity)
+       {
+               navigation_goalrating_timeout_expire(this, 2);
+       }
        else if(this.goalentity.bot_pickup)
        {
                if(this.goalentity.bot_pickup_respawning)
@@ -734,28 +778,91 @@ void havocbot_movetogoal(entity this)
                                this.goalentity.bot_pickup_respawning = false;
                        else if(time < this.goalentity.scheduledrespawntime - 10) // item already taken (by someone else)
                        {
-                               this.goalentity.bot_pickup_respawning = false;
-                               navigation_clearroute(this);
-                               this.bot_strategytime = 0;
-                               return;
+                               if(checkpvs(this.origin, this.goalentity))
+                               {
+                                       this.goalentity.bot_pickup_respawning = false;
+                                       navigation_goalrating_timeout_expire(this, random());
+                               }
+                               locked_goal = true; // wait for item to respawn
                        }
                        else if(this.goalentity == this.goalcurrent)
                                locked_goal = true; // wait for item to respawn
                }
-               else if(!this.goalentity.solid)
+               else if(!this.goalentity.solid && !boxesoverlap(this.goalentity.absmin, this.goalentity.absmax, this.absmin, this.absmax))
                {
-                       navigation_clearroute(this);
-                       this.bot_strategytime = 0;
-                       return;
+                       if(checkpvs(this.origin, this.goalentity))
+                       {
+                               navigation_goalrating_timeout_expire(this, random());
+                       }
+               }
+       }
+       if (this.goalcurrent == this.goalentity && this.goalentity_lock_timeout > time)
+               locked_goal = true;
+
+       navigation_shortenpath(this);
+
+       if (IS_MOVABLE(this.goalcurrent))
+       {
+               if (IS_DEAD(this.goalcurrent))
+               {
+                       if (checkpvs(this.origin + this.view_ofs, this.goalcurrent))
+                       {
+                               navigation_goalrating_timeout_force(this);
+                               return;
+                       }
+               }
+               else if (this.bot_tracewalk_time < time)
+               {
+                       set_tracewalk_dest(this.goalcurrent, this.origin, true);
+                       if (!(trace_ent == this || tracewalk(this, this.origin, this.mins, this.maxs,
+                               tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode)))
+                       {
+                               navigation_goalrating_timeout_force(this);
+                               return;
+                       }
+                       this.bot_tracewalk_time = max(time, this.bot_tracewalk_time) + 0.25;
                }
        }
        if(!locked_goal)
-               navigation_poptouchedgoals(this);
+       {
+               // optimize path finding by anticipating goalrating when bot is near a waypoint;
+               // in this case path finding can start directly from a waypoint instead of
+               // looking for all the reachable waypoints up to a certain distance
+               if (navigation_poptouchedgoals(this))
+               {
+                       if (this.goalcurrent)
+                       {
+                               if (IS_MOVABLE(this.goalcurrent) && IS_DEAD(this.goalcurrent))
+                               {
+                                       // remove even if not visible
+                                       navigation_goalrating_timeout_force(this);
+                                       return;
+                               }
+                               else if (navigation_goalrating_timeout_can_be_anticipated(this))
+                                       navigation_goalrating_timeout_force(this);
+                       }
+                       else
+                       {
+                               entity old_goal = this.goalcurrent_prev;
+                               if (old_goal.item_group && this.item_group != old_goal.item_group)
+                               {
+                                       // Avoid multiple costly calls of path finding code that selects one of the closest
+                                       // item of the group by telling the bot to head directly to the farthest item.
+                                       // Next time we let the bot select a goal as usual which can be another item
+                                       // of this group (the closest one) and so on
+                                       this.item_group = old_goal.item_group;
+                                       entity new_goal = havocbot_select_an_item_of_group(this, old_goal.item_group);
+                                       if (new_goal)
+                                               navigation_pushroute(this, new_goal);
+                               }
+                       }
+               }
+       }
 
        // if ran out of goals try to use an alternative goal or get a new strategy asap
        if(this.goalcurrent == NULL)
        {
-               this.bot_strategytime = 0;
+               navigation_goalrating_timeout_force(this);
                return;
        }
 
@@ -763,8 +870,8 @@ void havocbot_movetogoal(entity this)
        if(autocvar_bot_debug_goalstack)
                debuggoalstack(this);
 
-       bool bunnyhop_forbidden = false;;
-       SET_DESTCOORDS(this.goalcurrent, this.origin, destorg);
+       bool bunnyhop_forbidden = false;
+       vector destorg = get_closer_dest(this.goalcurrent, this.origin);
 
        // in case bot ends up inside the teleport waypoint without touching
        // the teleport itself, head to the teleport origin
@@ -777,11 +884,18 @@ 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);
-       gco = (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5;
 
        //if (this.bot_dodgevector_time < time)
        {
@@ -798,13 +912,13 @@ void havocbot_movetogoal(entity this)
                        {
                                if(!this.goalcurrent)
                                        this.aistatus |= AI_STATUS_OUT_WATER;
-                               else if(gco.z > this.origin.z)
+                               else if(destorg.z > this.origin.z)
                                        PHYS_INPUT_BUTTON_JUMP(this) = true;
                        }
                        else
                        {
                                dir = flatdir;
-                               if(this.velocity.z >= 0 && !(this.watertype == CONTENT_WATER && gco.z < this.origin.z) &&
+                               if(this.velocity.z >= 0 && !(this.watertype == CONTENT_WATER && destorg.z < this.origin.z) &&
                                        ( !(this.waterlevel == WATERLEVEL_WETFEET && this.watertype == CONTENT_WATER) || this.aistatus & AI_STATUS_OUT_WATER))
                                        PHYS_INPUT_BUTTON_JUMP(this) = true;
                                else
@@ -820,35 +934,86 @@ void havocbot_movetogoal(entity this)
 
                        // jump if going toward an obstacle that doesn't look like stairs we
                        // can walk up directly
-                       offset = (vdist(this.velocity, >, 32) ? this.velocity * 0.2 : v_forward * 32);
-                       tracebox(this.origin, this.mins, this.maxs, this.origin + offset, false, this);
+                       vector deviation = '0 0 0';
+                       if (this.velocity)
+                       {
+                               deviation = vectoangles(diff) - vectoangles(this.velocity);
+                               while (deviation.y < -180) deviation.y += 360;
+                               while (deviation.y > 180) deviation.y -= 360;
+                       }
+                       vector flat_diff = vec2(diff);
+                       offset = max(32, vlen(vec2(this.velocity)) * cos(deviation.y * DEG2RAD) * 0.2) * flatdir;
+                       vector actual_destorg = this.origin + offset;
+                       if (!this.goalstack01 || this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
+                       {
+                               if (vlen2(flat_diff) < vlen2(offset))
+                               {
+                                       actual_destorg.x = destorg.x;
+                                       actual_destorg.y = destorg.y;
+                               }
+                       }
+                       else if (vdist(flat_diff, <, 32) && diff.z < -16) // destination is under the bot
+                       {
+                               actual_destorg.x = destorg.x;
+                               actual_destorg.y = destorg.y;
+                       }
+                       else if (vlen2(flat_diff) < vlen2(offset))
+                       {
+                               vector next_goal_org = (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5;
+                               vector next_dir = normalize(vec2(next_goal_org - destorg));
+                               float next_dist = vlen(vec2(this.origin + offset - destorg));
+                               actual_destorg = vec2(destorg) + next_dist * next_dir;
+                               actual_destorg.z = this.origin.z;
+                       }
+
+                       tracebox(this.origin, this.mins, this.maxs, actual_destorg, false, this);
                        if (trace_fraction < 1)
                        if (trace_plane_normal.z < 0.7)
                        {
                                s = trace_fraction;
-                               tracebox(this.origin + stepheightvec, this.mins, this.maxs, this.origin + offset + stepheightvec, false, this);
+                               tracebox(this.origin + stepheightvec, this.mins, this.maxs, actual_destorg + stepheightvec, false, this);
                                if (trace_fraction < s + 0.01)
                                if (trace_plane_normal.z < 0.7)
                                {
                                        s = trace_fraction;
-                                       tracebox(this.origin + jumpstepheightvec, this.mins, this.maxs, this.origin + offset + jumpstepheightvec, false, this);
+                                       tracebox(this.origin + jumpstepheightvec, this.mins, this.maxs, actual_destorg + jumpstepheightvec, false, this);
                                        if (trace_fraction > s)
                                                PHYS_INPUT_BUTTON_JUMP(this) = true;
                                }
                        }
 
                        // if bot for some reason doesn't get close to the current goal find another one
-                       if(!this.jumppadcount && !IS_PLAYER(this.goalcurrent) && !(this.goalcurrent.bot_pickup_respawning && this.goalcurrent_distance < 50))
-                       if(havocbot_checkgoaldistance(this, gco))
+                       if(!this.jumppadcount && !IS_PLAYER(this.goalcurrent))
+                       if(!(locked_goal && this.goalcurrent_distance_z < 50 && this.goalcurrent_distance_2d < 50))
+                       if(havocbot_checkgoaldistance(this, destorg))
                        {
-                               navigation_clearroute(this);
-                               this.bot_strategytime = 0;
-                               return;
+                               if(this.goalcurrent_distance_time < 0) // can't get close for the second time
+                               {
+                                       navigation_clearroute(this);
+                                       navigation_goalrating_timeout_force(this);
+                                       return;
+                               }
+
+                               set_tracewalk_dest(this.goalcurrent, this.origin, false);
+                               if (!tracewalk(this, this.origin, this.mins, this.maxs,
+                                       tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode))
+                               {
+                                       navigation_clearroute(this);
+                                       navigation_goalrating_timeout_force(this);
+                                       return;
+                               }
+
+                               // give bot only another chance to prevent bot getting stuck
+                               // in case it thinks it can walk but actually can't
+                               this.goalcurrent_distance_z = FLOAT_MAX;
+                               this.goalcurrent_distance_2d = FLOAT_MAX;
+                               this.goalcurrent_distance_time = -time; // mark second try
                        }
 
                        // Check for water/slime/lava and dangerous edges
                        // (only when the bot is on the ground or jumping intentionally)
 
+                       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';
                        traceline(this.origin + this.view_ofs, dst_ahead, true, NULL);
@@ -877,7 +1042,7 @@ void havocbot_movetogoal(entity this)
                                                tracebox(dst_ahead, this.mins, this.maxs, dst_down, true, this);
                                                if (tracebox_hits_trigger_hurt(dst_ahead, this.mins, this.maxs, trace_endpos))
                                                {
-                                                       if (gco.z > this.origin.z + jumpstepheightvec.z)
+                                                       if (destorg.z > this.origin.z + jumpstepheightvec.z)
                                                        {
                                                                // the goal is probably on an upper platform, assume bot can't get there
                                                                unreachable = true;
@@ -903,7 +1068,9 @@ void havocbot_movetogoal(entity this)
                        if(unreachable)
                        {
                                navigation_clearroute(this);
-                               this.bot_strategytime = 0;
+                               navigation_goalrating_timeout_force(this);
+                               this.ignoregoal = this.goalcurrent;
+                               this.ignoregoaltime = time + autocvar_bot_ai_ignoregoal_timeout;
                        }
                }
 
@@ -1287,8 +1454,7 @@ float havocbot_moveto(entity this, vector pos)
                        debuggoalstack(this);
 
                // Heading
-               vector dir = '0 0 0';
-               SET_DESTCOORDS(this.goalcurrent, this.origin, dir);
+               vector dir = get_closer_dest(this.goalcurrent, this.origin);
                dir = dir - (this.origin + this.view_ofs);
                dir.z = 0;
                bot_aimdir(this, dir, -1);
index 88ba407a2d68aca2dd10f96bbe028c79de4987a9..2f987f674ec8719503137e05452abe5e7701fd1e 100644 (file)
@@ -23,6 +23,7 @@
 .float havocbot_stickenemy;
 .float havocbot_role_timeout;
 
+.float bot_tracewalk_time;
 .entity ignoregoal;
 .entity bot_lastseengoal;
 .entity havocbot_personal_waypoint;
index 6d0b3c6a1cae803294d4adb588868ab6da8dba94..e469436014e1e030cc7dd1fc3bad16e61ad9fb11 100644 (file)
@@ -10,6 +10,8 @@
 #include "../bot.qh"
 #include "../navigation.qh"
 
+.float bot_ratingscale;
+.float bot_ratingscale_time;
 .float max_armorvalue;
 .float havocbot_role_timeout;
 
@@ -45,15 +47,81 @@ void havocbot_goalrating_waypoints(entity this, float ratingscale, vector org, f
        }
 };
 
+bool havocbot_goalrating_item_can_be_left_to_teammate(entity this, entity player, entity item)
+{
+       if (item.health && player.health <= this.health) {return true;}
+       if (item.armorvalue && player.armorvalue <= this.armorvalue) {return true;}
+       if (item.weapons && !(player.weapons & item.weapons)) {return true;}
+       if (item.ammo_shells && player.ammo_shells <= this.ammo_shells) {return true;}
+       if (item.ammo_nails && player.ammo_nails <= this.ammo_nails) {return true;}
+       if (item.ammo_rockets && player.ammo_rockets <= this.ammo_rockets) {return true;}
+       if (item.ammo_cells && player.ammo_cells <= this.ammo_cells) {return true;}
+       if (item.ammo_plasma && player.ammo_plasma <= this.ammo_plasma) {return true;}
+       if (item.itemdef.instanceOfPowerup) {return true;}
+
+       return false;
+};
+
+bool havocbot_goalrating_item_pickable_check_players(entity this, vector org, entity item, vector item_org)
+{
+       if(!teamplay)
+               return true;
+
+       // actually these variables hold the squared distances in order to optimize code
+       float friend_distance = FLOAT_MAX;
+       float enemy_distance = FLOAT_MAX;
+       float dist;
+
+       FOREACH_CLIENT(IS_PLAYER(it) && it != this && !IS_DEAD(it),
+       {
+               if (it.team == this.team)
+               {
+                       if (!IS_REAL_CLIENT(it))
+                               continue;
+
+                       dist = vlen2(it.origin - item_org);
+                       if(dist > friend_distance)
+                               continue;
+
+                       if(havocbot_goalrating_item_can_be_left_to_teammate(this, it, item))
+                       {
+                               friend_distance = dist;
+                               continue;
+                       }
+               }
+               else
+               {
+                       // If enemy only track distances
+                       // TODO: track only if visible ?
+                       dist = vlen2(it.origin - item_org);
+                       if(dist < enemy_distance)
+                               enemy_distance = dist;
+               }
+       });
+
+       // Rate the item only if no one needs it, or if an enemy is closer to it
+       dist = vlen2(item_org - org);
+       if ((enemy_distance < friend_distance && dist < enemy_distance) ||
+               (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ** 2) ||
+               (dist < friend_distance && dist < 200 ** 2))
+               return true;
+       return false;
+};
+
 void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius)
 {
-       float rating, discard, friend_distance, enemy_distance;
+       float rating;
        vector o;
        ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
 
        IL_EACH(g_items, it.bot_pickup,
        {
-               rating = 0;
+               // ignore if bot already rated this item with a higher ratingscale
+               // NOTE: this code assumes each bot rates items in a different frame
+               if(it.bot_ratingscale_time == time && ratingscale < it.bot_ratingscale)
+                       continue;
+               it.bot_ratingscale_time = time;
+               it.bot_ratingscale = ratingscale;
 
                if(!it.solid)
                {
@@ -103,55 +171,10 @@ void havocbot_goalrating_items(entity this, float ratingscale, vector org, float
                                continue;
                }
 
-               if(teamplay)
-               {
-                       friend_distance = 10000; enemy_distance = 10000;
-                       discard = false;
-
-                       entity picker = it;
-                       FOREACH_CLIENT(IS_PLAYER(it) && it != this && !IS_DEAD(it),
-                       {
-                               if ( it.team == this.team )
-                               {
-                                       if ( !IS_REAL_CLIENT(it) || discard )
-                                               continue;
-
-                                       if( vdist(it.origin - o, >, friend_distance) )
-                                               continue;
-
-                                       friend_distance = vlen(it.origin - o); // distance between player and item
-                                       discard = true;
-
-                                       if (picker.health && it.health > this.health) continue;
-                                       if (picker.armorvalue && it.armorvalue > this.armorvalue) continue;
-
-                                       if (picker.weapons && (picker.weapons & ~it.weapons)) continue;
-
-                                       if (picker.ammo_shells && it.ammo_shells > this.ammo_shells) continue;
-                                       if (picker.ammo_nails && it.ammo_nails > this.ammo_nails) continue;
-                                       if (picker.ammo_rockets && it.ammo_rockets > this.ammo_rockets) continue;
-                                       if (picker.ammo_cells && it.ammo_cells > this.ammo_cells) continue;
-                                       if (picker.ammo_plasma && it.ammo_plasma > this.ammo_plasma) continue;
-
-                                       discard = false;
-                               }
-                               else
-                               {
-                                       // If enemy only track distances
-                                       // TODO: track only if visible ?
-                                       if( vdist(it.origin - o, <, enemy_distance) )
-                                               enemy_distance = vlen(it.origin - o); // distance between player and item
-                               }
-                       });
-
-                       // Rate the item only if no one needs it, or if an enemy is closer to it
-                       if ( (enemy_distance < friend_distance && vdist(o - org, <, enemy_distance)) ||
-                               (friend_distance > autocvar_bot_ai_friends_aware_pickup_radius ) || !discard )
-                               rating = it.bot_pickupevalfunc(this, it);
-               }
-               else
-                       rating = it.bot_pickupevalfunc(this, it);
+               if(!havocbot_goalrating_item_pickable_check_players(this, org, it, o))
+                       continue;
 
+               rating = it.bot_pickupevalfunc(this, it);
                if(rating > 0)
                        navigation_routerating(this, it, rating * ratingscale, 2000);
        });
@@ -174,6 +197,8 @@ void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org
                // TODO: Merge this logic with the bot_shouldattack function
                if(vdist(it.origin - org, <, 100) || vdist(it.origin - org, >, sradius))
                        continue;
+               if(vdist(vec2(it.velocity), >, autocvar_sv_maxspeed * 2))
+                       continue;
 
                // rate only visible enemies
                /*
@@ -188,6 +213,8 @@ void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org
                {
                        if (time < this.strength_finished - 1) t += 0.5;
                        if (time < it.strength_finished - 1) t -= 0.5;
+                       if (time < this.invincible_finished - 1) t += 0.2;
+                       if (time < it.invincible_finished - 1) t -= 0.4;
                }
                t += max(0, 8 - skill) * 0.05; // less skilled bots attack more mindlessly
                ratingscale *= t;
@@ -203,17 +230,15 @@ void havocbot_role_generic(entity this)
        if(IS_DEAD(this))
                return;
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
                havocbot_goalrating_items(this, 10000, this.origin, 10000);
                havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
                havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
                navigation_goalrating_end(this);
 
-               if(IS_PLAYER(this.goalentity))
-                       this.bot_strategytime = time + min(2, autocvar_bot_ai_strategyinterval);
+               navigation_goalrating_timeout_set(this);
        }
 }
 
@@ -225,7 +250,7 @@ void havocbot_chooserole_generic(entity this)
 void havocbot_chooserole(entity this)
 {
        LOG_TRACE("choosing a role...");
-       this.bot_strategytime = 0;
+       navigation_goalrating_timeout_force(this);
        if(!MUTATOR_CALLHOOK(HavocBot_ChooseRole, this))
                havocbot_chooserole_generic(this);
 }
index 8d592269341022695a551e8195eea9d19d88646e..3754897bda3fe5ff2554409d318933ad3e11e38a 100644 (file)
 
 .float speed;
 
+void navigation_goalrating_timeout_set(entity this)
+{
+       if(IS_MOVABLE(this.goalentity))
+               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval_movingtarget;
+       else
+               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+}
+
+// use this when current goal must be discarded immediately
+void navigation_goalrating_timeout_force(entity this)
+{
+       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)
+{
+       return this.bot_strategytime < time;
+}
+
+#define MAX_CHASE_DISTANCE 700
+bool navigation_goalrating_timeout_can_be_anticipated(entity this)
+{
+       if(time > this.bot_strategytime - (IS_MOVABLE(this.goalentity) ? 3 : 2))
+               return true;
+
+       if (this.goalentity.bot_pickup && time > this.bot_strategytime - 5)
+       {
+               vector gco = (this.goalentity.absmin + this.goalentity.absmax) * 0.5;
+               if(!havocbot_goalrating_item_pickable_check_players(this, this.origin, this.goalentity, gco))
+               {
+                       this.ignoregoal = this.goalentity;
+                       this.ignoregoaltime = time + autocvar_bot_ai_ignoregoal_timeout;
+                       return true;
+               }
+       }
+       return false;
+}
+
 void navigation_dynamicgoal_init(entity this, bool initially_static)
 {
        this.navigation_dynamicgoal = true;
@@ -30,6 +78,8 @@ void navigation_dynamicgoal_init(entity this, bool initially_static)
 void navigation_dynamicgoal_set(entity this)
 {
        this.nearestwaypointtimeout = time;
+       if (this.nearestwaypoint)
+               this.nearestwaypointtimeout += 2;
 }
 
 void navigation_dynamicgoal_unset(entity this)
@@ -39,6 +89,97 @@ void navigation_dynamicgoal_unset(entity this)
        this.nearestwaypointtimeout = -1;
 }
 
+// returns point of ent closer to org
+vector get_closer_dest(entity ent, vector org)
+{
+       vector dest = '0 0 0';
+       if ((ent.classname != "waypoint") || ent.wpisbox)
+       {
+               vector wm1 = ent.origin + ent.mins;
+               vector wm2 = ent.origin + ent.maxs;
+               dest.x = bound(wm1.x, org.x, wm2.x);
+               dest.y = bound(wm1.y, org.y, wm2.y);
+               dest.z = bound(wm1.z, org.z, wm2.z);
+       }
+       else
+               dest = ent.origin;
+       return dest;
+}
+
+void set_tracewalk_dest(entity ent, vector org, bool fix_player_dest)
+{
+       if ((ent.classname != "waypoint") || ent.wpisbox)
+       {
+               vector wm1 = ent.origin + ent.mins;
+               vector wm2 = ent.origin + ent.maxs;
+               if (IS_PLAYER(ent) || IS_MONSTER(ent))
+               {
+                       // move destination point out of player bbox otherwise tracebox always fails
+                       // (if bot_navigation_ignoreplayers is false)
+                       wm1 += vec2(PL_MIN_CONST) + '-1 -1 0';
+                       wm2 += vec2(PL_MAX_CONST) + '1 1 0';
+               }
+               // set destination point to x and y coords of ent that are closer to org
+               // z coord is set to ent's min height
+               tracewalk_dest.x = bound(wm1.x, org.x, wm2.x);
+               tracewalk_dest.y = bound(wm1.y, org.y, wm2.y);
+               tracewalk_dest.z = wm1.z;
+               tracewalk_dest_height = wm2.z - wm1.z; // destination height
+       }
+       else
+       {
+               tracewalk_dest = ent.origin;
+               tracewalk_dest_height = 0;
+       }
+       if (fix_player_dest && IS_PLAYER(ent) && !IS_ONGROUND(ent))
+       {
+               // snap player to the ground
+               if (org.x == tracewalk_dest.x && org.y == tracewalk_dest.y)
+               {
+                       // bot is right under the player
+                       tracebox(ent.origin, ent.mins, ent.maxs, ent.origin - '0 0 700', MOVE_NORMAL, ent);
+                       tracewalk_dest = trace_endpos;
+                       tracewalk_dest_height = 0;
+               }
+               else
+               {
+                       tracebox(tracewalk_dest, ent.mins, ent.maxs, tracewalk_dest - '0 0 700', MOVE_NORMAL, ent);
+                       if (!trace_startsolid && tracewalk_dest.z - trace_endpos.z > 0)
+                       {
+                               tracewalk_dest_height = tracewalk_dest.z - trace_endpos.z;
+                               tracewalk_dest.z = trace_endpos.z;
+                       }
+               }
+       }
+}
+
+// returns point of ent closer to org
+vector set_tracewalk_dest_2(entity ent, vector org)
+{
+       vector closer_dest = '0 0 0';
+       if ((ent.classname != "waypoint") || ent.wpisbox)
+       {
+               vector wm1 = ent.origin + ent.mins;
+               vector wm2 = ent.origin + ent.maxs;
+               closer_dest.x = bound(wm1.x, org.x, wm2.x);
+               closer_dest.y = bound(wm1.y, org.y, wm2.y);
+               closer_dest.z = bound(wm1.z, org.z, wm2.z);
+               // set destination point to x and y coords of ent that are closer to org
+               // z coord is set to ent's min height
+               tracewalk_dest.x = closer_dest.x;
+               tracewalk_dest.y = closer_dest.y;
+               tracewalk_dest.z = wm1.z;
+               tracewalk_dest_height = wm2.z - wm1.z; // destination height
+       }
+       else
+       {
+               closer_dest = ent.origin;
+               tracewalk_dest = closer_dest;
+               tracewalk_dest_height = 0;
+       }
+       return closer_dest;
+}
+
 bool navigation_check_submerged_state(entity ent, vector pos)
 {
        bool submerged;
@@ -586,9 +727,10 @@ bool tracewalk(entity e, vector start, vector m1, vector m2, vector end, float e
 void navigation_clearroute(entity this)
 {
        this.goalcurrent_prev = this.goalcurrent;
-       this.goalcurrent_distance = 10000000;
+       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;
@@ -633,7 +775,8 @@ void navigation_clearroute(entity this)
 void navigation_pushroute(entity this, entity e)
 {
        this.goalcurrent_prev = this.goalcurrent;
-       this.goalcurrent_distance = 10000000;
+       this.goalcurrent_distance_2d = FLOAT_MAX;
+       this.goalcurrent_distance_z = FLOAT_MAX;
        this.goalcurrent_distance_time = 0;
        //print("bot ", etos(this), " push ", etos(e), "\n");
        if(this.goalstack31 == this.goalentity)
@@ -678,11 +821,15 @@ void navigation_pushroute(entity this, entity e)
 void navigation_poproute(entity this)
 {
        this.goalcurrent_prev = this.goalcurrent;
-       this.goalcurrent_distance = 10000000;
+       this.goalcurrent_distance_2d = FLOAT_MAX;
+       this.goalcurrent_distance_z = FLOAT_MAX;
        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;
@@ -755,7 +902,14 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom
        IL_EACH(g_waypoints, it != ent && it != except,
        {
                if(boxesoverlap(pm1, pm2, it.absmin, it.absmax))
+               {
+                       if(!autocvar_g_waypointeditor && walkfromwp && !ent.navigation_dynamicgoal)
+                       {
+                               waypoint_clearlinks(ent); // initialize wpXXmincost fields
+                               navigation_item_addlink(it, ent);
+                       }
                        return it;
+               }
        });
 
        vector org = ent.origin;
@@ -763,8 +917,7 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom
                te_plasmaburn(org);
 
        entity best = NULL;
-       vector v = '0 0 0', v2 = '0 0 0';
-       float v2_height = 0;
+       vector v = '0 0 0';
 
        if(ent.size && !IS_PLAYER(ent))
        {
@@ -780,10 +933,13 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom
                        if(walkfromwp && (it.wpflags & WAYPOINTFLAG_NORELINK))
                                continue;
 
-                       SET_TRACEWALK_DESTCOORDS(it, org, v2, v2_height);
-                       if(vdist(v2 - org, <, 1050))
-                       if(tracewalk(ent, org, PL_MIN_CONST, PL_MAX_CONST, v2, v2_height, bot_navigation_movemode))
+                       set_tracewalk_dest(ent, it.origin, false);
+                       if (vdist(tracewalk_dest - it.origin, <, 1050)
+                               && tracewalk(ent, it.origin, PL_MIN_CONST, PL_MAX_CONST,
+                               tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode))
+                       {
                                navigation_item_addlink(it, ent);
+                       }
                });
        }
 
@@ -793,16 +949,45 @@ entity navigation_findnearestwaypoint_withdist_except(entity ent, float walkfrom
                if(walkfromwp && (it.wpflags & WAYPOINTFLAG_NORELINK))
                        continue;
                v = it.origin;
-               if(walkfromwp)
-                       SET_TRACEWALK_DESTCOORDS(ent, v, v2, v2_height);
+
+               if (walkfromwp)
+               {
+                       set_tracewalk_dest(ent, v, true);
+                       if (trace_ent == ent)
+                       {
+                               bestdist = 0;
+                               best = it;
+                               break;
+                       }
+               }
                else
-                       SET_TRACEWALK_DESTCOORDS(it, org, v2, v2_height);
-               if(navigation_waypoint_will_link(v, org, ent, v2, v2_height, v2, v2_height, walkfromwp, bestdist))
+                       set_tracewalk_dest(it, org, false);
+
+               if (navigation_waypoint_will_link(v, org, ent,
+                       tracewalk_dest, tracewalk_dest_height,
+                       tracewalk_dest, tracewalk_dest_height, walkfromwp, bestdist))
                {
-                       bestdist = vlen(v - org);
+                       if (walkfromwp)
+                               bestdist = vlen(tracewalk_dest - v);
+                       else
+                               bestdist = vlen(v - org);
                        best = it;
                }
        });
+       if(!best && !ent.navigation_dynamicgoal)
+       {
+               int solid_save = ent.solid;
+               ent.solid = SOLID_BSP;
+               IL_EACH(g_jumppads, true,
+               {
+                       if(trigger_push_test(it, ent))
+                       {
+                               best = it.nearestwaypoint;
+                               break;
+                       }
+               });
+               ent.solid = solid_save;
+       }
        return best;
 }
 entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
@@ -820,23 +1005,22 @@ entity navigation_findnearestwaypoint(entity ent, float walkfromwp)
 // finds the waypoints near the bot initiating a navigation query
 float navigation_markroutes_nearestwaypoints(entity this, float maxdist)
 {
-       vector v = '0 0 0';
        //navigation_testtracewalk = true;
        int c = 0;
-       float v_height = 0;
        IL_EACH(g_waypoints, !it.wpconsidered,
        {
-               SET_TRACEWALK_DESTCOORDS(it, this.origin, v, v_height);
+               set_tracewalk_dest(it, this.origin, false);
 
-               vector diff = v - this.origin;
+               vector diff = tracewalk_dest - this.origin;
                diff.z = max(0, diff.z);
                if(vdist(diff, <, maxdist))
                {
                        it.wpconsidered = true;
-                       if (tracewalk(this, this.origin, this.mins, this.maxs, v, v_height, bot_navigation_movemode))
+                       if (tracewalk(this, this.origin, this.mins, this.maxs,
+                               tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode))
                        {
-                               it.wpnearestpoint = v;
-                               it.wpcost = waypoint_gettravelcost(this.origin, v, this, it) + it.dmg;
+                               it.wpnearestpoint = tracewalk_dest;
+                               it.wpcost = waypoint_gettravelcost(this.origin, tracewalk_dest, this, it) + it.dmg;
                                it.wpfire = 1;
                                it.enemy = NULL;
                                c = c + 1;
@@ -1177,29 +1361,11 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
                if ((!e.nearestwaypoint || e.navigation_dynamicgoal)
                        && e.nearestwaypointtimeout >= 0 && time > e.nearestwaypointtimeout)
                {
-                       nwp = navigation_findnearestwaypoint(e, true);
-                       if(nwp)
-                       {
-                               e.nearestwaypoint = nwp;
-
-                               vector m1 = nwp.absmin, m2 = nwp.absmax;
-                               m1.x = nwp.origin.x; m1.y = nwp.origin.y;
-                               m2.x = nwp.origin.x; m2.y = nwp.origin.y;
-                               vector ve = (e.absmin - e.absmax) * 0.5;
-                               ve.x = bound(m1.x, ve.x, m2.x);
-                               ve.y = bound(m1.y, ve.y, m2.y);
-                               ve.z = bound(m1.z, ve.z, m2.z);
-
-                               m1 = e.absmin; m2 = e.absmax;
-                               m1.x = e.origin.x; m1.y = e.origin.y;
-                               m2.x = e.origin.x; m2.y = e.origin.y;
-                               vector vnwp = nwp.origin;
-                               vnwp.x = bound(m1.x, vnwp.x, m2.x);
-                               vnwp.y = bound(m1.y, vnwp.y, m2.y);
-                               vnwp.z = bound(m1.z, vnwp.z, m2.z);
-                               e.nearestwaypoint_dist = vlen(ve - vnwp);
-                       }
+                       if(IS_BOT_CLIENT(e) && e.goalcurrent && e.goalcurrent.classname == "waypoint")
+                               e.nearestwaypoint = nwp = e.goalcurrent;
                        else
+                               e.nearestwaypoint = nwp = navigation_findnearestwaypoint(e, true);
+                       if(!nwp)
                        {
                                LOG_DEBUG("FAILED to find a nearest waypoint to '", e.classname, "' #", etos(e));
 
@@ -1222,11 +1388,15 @@ void navigation_routerating(entity this, entity e, float f, float rangebias)
        }
 
        LOG_DEBUG("-- checking ", e.classname, " (with cost ", ftos(nwp.wpcost), ")");
-       if (nwp)
-       if (nwp.wpcost < 10000000)
+       if (nwp && nwp.wpcost < 10000000)
        {
                //te_wizspike(nwp.wpnearestpoint);
-               float cost = nwp.wpcost + waypoint_gettravelcost(nwp.wpnearestpoint, goal_org, nwp, e);
+               float nwptoitem_cost = 0;
+               if(nwp.wpflags & WAYPOINTFLAG_TELEPORT)
+                       nwptoitem_cost = nwp.wp00mincost;
+               else
+                       nwptoitem_cost = waypoint_gettravelcost(nwp.wpnearestpoint, goal_org, nwp, e);
+               float cost = nwp.wpcost + nwptoitem_cost;
                LOG_DEBUG(e.classname, " ", ftos(f), "/(1+", ftos(cost), "/", ftos(rangebias), ") = ");
                f = f * rangebias / (rangebias + cost);
                LOG_DEBUG("considering ", e.classname, " (with rating ", ftos(f), ")");
@@ -1276,11 +1446,13 @@ bool navigation_routetogoal(entity this, entity e, vector startposition)
                return true;
 
        // if it can reach the goal there is nothing more to do
-       vector dest = '0 0 0';
-       float dest_height = 0;
-       SET_TRACEWALK_DESTCOORDS(e, startposition, dest, dest_height);
-       if (tracewalk(this, startposition, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
+       set_tracewalk_dest(e, startposition, true);
+       if ((!IS_MOVABLE(this.goalcurrent) || vdist(tracewalk_dest - this.origin, <, MAX_CHASE_DISTANCE))
+               && (trace_ent == this || tracewalk(this, startposition, STAT(PL_MIN, this), STAT(PL_MAX, this),
+               tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode)))
+       {
                return true;
+       }
 
        entity nearest_wp = NULL;
        // see if there are waypoints describing a path to the item
@@ -1300,20 +1472,27 @@ bool navigation_routetogoal(entity this, entity e, vector startposition)
        if(nearest_wp && nearest_wp.enemy)
        {
                // often path can be optimized by not adding the nearest waypoint
-               if (this.goalentity.nearestwaypoint_dist < 8)
-                       e = nearest_wp.enemy;
-               else
+               if (this.goalentity.navigation_dynamicgoal || autocvar_g_waypointeditor)
                {
-                       if (this.goalentity.navigation_dynamicgoal || autocvar_g_waypointeditor)
+                       if (nearest_wp.enemy.wpcost < autocvar_bot_ai_strategyinterval_movingtarget)
                        {
-                               SET_TRACEWALK_DESTCOORDS(this.goalentity, nearest_wp.enemy.origin, dest, dest_height);
-                               if(vdist(dest - nearest_wp.enemy.origin, <, 1050))
-                               if(tracewalk(this, nearest_wp.enemy.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
+                               if (vdist(vec2(this.goalentity.origin - nearest_wp.origin), <, 32))
                                        e = nearest_wp.enemy;
+                               else
+                               {
+                                       set_tracewalk_dest(this.goalentity, nearest_wp.enemy.origin, true);
+                                       if (trace_ent == this || (vdist(tracewalk_dest - nearest_wp.enemy.origin, <, 1050)
+                                               && vlen2(tracewalk_dest - nearest_wp.enemy.origin) < vlen2(nearest_wp.origin - nearest_wp.enemy.origin)
+                                               && tracewalk(this, nearest_wp.enemy.origin, STAT(PL_MIN, this), STAT(PL_MAX, this),
+                                               tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode)))
+                                       {
+                                               e = nearest_wp.enemy;
+                                       }
+                               }
                        }
-                       else if(navigation_item_islinked(nearest_wp.enemy, this.goalentity))
-                               e = nearest_wp.enemy;
                }
+               else if(navigation_item_islinked(nearest_wp.enemy, this.goalentity))
+                       e = nearest_wp.enemy;
        }
 
        for (;;)
@@ -1329,10 +1508,86 @@ bool navigation_routetogoal(entity this, entity e, vector startposition)
        return false;
 }
 
+// shorten path by removing intermediate goals
+void navigation_shortenpath(entity this)
+{
+       if (!this.goalstack01 || wasfreed(this.goalstack01))
+               return;
+       if (this.bot_tracewalk_time > time)
+               return;
+       this.bot_tracewalk_time = max(time, this.bot_tracewalk_time) + 0.25;
+
+       bool cut_allowed = false;
+       entity next = this.goalentity;
+       // evaluate whether bot can discard current route and chase directly a player, trying to
+       // keep waypoint route as long as possible, as it is safer and faster (bot can bunnyhop)
+       if (IS_MOVABLE(next))
+       {
+               set_tracewalk_dest(next, this.origin, true);
+               if (vdist(this.origin - tracewalk_dest, <, 200))
+                       cut_allowed = true;
+               else if (vdist(tracewalk_dest - this.origin, <, MAX_CHASE_DISTANCE)
+                       && vdist(tracewalk_dest - this.goalcurrent.origin, >, 200)
+                       && vdist(this.origin - this.goalcurrent.origin, >, 100)
+                       && checkpvs(this.origin + this.view_ofs, next))
+               {
+                       if (vlen2(next.origin - this.origin) < vlen2(this.goalcurrent.origin - this.origin))
+                               cut_allowed = true;
+                       else
+                       {
+                               vector deviation = vectoangles(this.goalcurrent.origin - this.origin) - vectoangles(next.origin - this.origin);
+                               while (deviation.y < -180) deviation.y += 360;
+                               while (deviation.y > 180) deviation.y -= 360;
+                               if (fabs(deviation.y) > 25)
+                                       cut_allowed = true;
+                       }
+               }
+               if (cut_allowed)
+               {
+                       if (trace_ent == this || tracewalk(this, this.origin, this.mins, this.maxs,
+                               tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode))
+                       {
+                               LOG_DEBUG("path optimized for ", this.netname, ", route cleared");
+                               do
+                               {
+                                       navigation_poproute(this);
+                               }
+                               while (this.goalcurrent != next);
+                       }
+                       return;
+               }
+       }
+
+       next = this.goalstack01;
+       // if for some reason the bot is closer to the next goal, pop the current one
+       if (!IS_MOVABLE(next) // already checked in the previous case
+               && vlen2(this.goalcurrent.origin - next.origin) > vlen2(next.origin - this.origin)
+               && checkpvs(this.origin + this.view_ofs, next))
+       {
+               set_tracewalk_dest(next, this.origin, true);
+               cut_allowed = true;
+       }
+
+       if (cut_allowed)
+       {
+               if (trace_ent == this || tracewalk(this, this.origin, this.mins, this.maxs,
+                       tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode))
+               {
+                       LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue"); 
+                       navigation_poproute(this);
+               }
+       }
+}
+
 // removes any currently touching waypoints from the goal stack
 // (this is how bots detect if they reached a goal)
-void navigation_poptouchedgoals(entity this)
+int navigation_poptouchedgoals(entity this)
 {
+       int removed_goals = 0;
+
+       if(!this.goalcurrent)
+               return removed_goals;
+
        if(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
        {
                // make sure jumppad is really hit, don't rely on distance based checks
@@ -1353,32 +1608,11 @@ void navigation_poptouchedgoals(entity this)
                                this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
                        }
                        navigation_poproute(this);
+                       this.lastteleporttime = 0;
+                       ++removed_goals;
                }
                else
-                       return;
-       }
-
-       // If for some reason the bot is closer to the next goal, pop the current one
-       if(this.goalstack01 && !wasfreed(this.goalstack01))
-       if(vlen2(this.goalcurrent.origin - this.origin) > vlen2(this.goalstack01.origin - this.origin))
-       if(checkpvs(this.origin + this.view_ofs, this.goalstack01))
-       {
-               vector dest = (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5;
-               dest.z = this.goalstack01.absmin.z;
-               float dest_height = this.goalstack01.absmax.z - this.goalstack01.absmin.z;
-               if(tracewalk(this, this.origin, this.mins, this.maxs, dest, dest_height, bot_navigation_movemode))
-               {
-                       LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue");
-                       navigation_poproute(this);
-                       if(this.goalcurrent && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
-                               return;
-                       // TODO this may also be a nice idea to do "early" (e.g. by
-                       // manipulating the vlen() comparisons) to shorten paths in
-                       // general - this would make bots walk more "on rails" than
-                       // "zigzagging" which they currently do with sufficiently
-                       // random-like waypoints, and thus can make a nice bot
-                       // personality property
-               }
+                       return removed_goals;
        }
 
        // Loose goal touching check when running
@@ -1400,8 +1634,9 @@ void navigation_poptouchedgoals(entity this)
                                }
 
                                navigation_poproute(this);
+                               ++removed_goals;
                                if(this.goalcurrent && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
-                                       return;
+                                       return removed_goals;
                        }
                }
        }
@@ -1427,9 +1662,56 @@ void navigation_poptouchedgoals(entity this)
                }
 
                navigation_poproute(this);
+               ++removed_goals;
                if(this.goalcurrent && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
-                       return;
+                       return removed_goals;
+       }
+       return removed_goals;
+}
+
+entity navigation_get_really_close_waypoint(entity this)
+{
+       entity wp = this.goalcurrent;
+       if(!wp)
+               wp = this.goalcurrent_prev;
+       if(!wp)
+               return NULL;
+       if(wp != this.goalcurrent_prev && vdist(wp.origin - this.origin, >, 50))
+       {
+               wp = this.goalcurrent_prev;
+               if(!wp)
+                       return NULL;
        }
+       if(wp.classname != "waypoint")
+       {
+               wp = wp.nearestwaypoint;
+               if(!wp)
+                       return NULL;
+       }
+       if(vdist(wp.origin - this.origin, >, 50))
+       {
+               wp = NULL;
+               IL_EACH(g_waypoints, !(it.wpflags & WAYPOINTFLAG_TELEPORT),
+               {
+                       if(vdist(it.origin - this.origin, <, 50))
+                       {
+                               wp = it;
+                               break;
+                       }
+               });
+               if(!wp)
+                       return NULL;
+       }
+       if(wp.wpflags & WAYPOINTFLAG_TELEPORT)
+               return NULL;
+
+       set_tracewalk_dest(wp, this.origin, false);
+       if (!tracewalk(this, this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this),
+               tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode))
+       {
+               return NULL;
+       }
+       return wp;
 }
 
 // begin a goal selection session (queries spawnfunc_waypoint network)
@@ -1440,9 +1722,10 @@ void navigation_goalrating_start(entity this)
 
        this.navigation_jetpack_goal = NULL;
        navigation_bestrating = -1;
+       entity wp = navigation_get_really_close_waypoint(this);
        navigation_clearroute(this);
        navigation_bestgoal = NULL;
-       navigation_markroutes(this, NULL);
+       navigation_markroutes(this, wp);
 }
 
 // ends a goal selection session (updates goal stack to the best goal)
@@ -1522,10 +1805,9 @@ void navigation_unstuck(entity this)
                // evaluate the next goal on the queue
                float d = vlen2(this.origin - bot_waypoint_queue_goal.origin);
                LOG_DEBUG(this.netname, " evaluating ", bot_waypoint_queue_goal.classname, " with distance ", ftos(d));
-               vector dest = (bot_waypoint_queue_goal.absmin + bot_waypoint_queue_goal.absmax) * 0.5;
-               dest.z = bot_waypoint_queue_goal.absmin.z;
-               float dest_height = bot_waypoint_queue_goal.absmax.z - bot_waypoint_queue_goal.absmin.z;
-               if(tracewalk(bot_waypoint_queue_goal, this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this), dest, dest_height, bot_navigation_movemode))
+               set_tracewalk_dest(bot_waypoint_queue_goal, this.origin, false);
+               if (tracewalk(bot_waypoint_queue_goal, this.origin, STAT(PL_MIN, this), STAT(PL_MAX, this),
+                       tracewalk_dest, tracewalk_dest_height, bot_navigation_movemode))
                {
                        if( d > bot_waypoint_queue_bestgoalrating)
                        {
@@ -1541,7 +1823,7 @@ void navigation_unstuck(entity this)
                        {
                                LOG_DEBUG(this.netname, " stuck, reachable waypoint found, heading to it");
                                navigation_routetogoal(this, bot_waypoint_queue_bestgoal, this.origin);
-                               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+                               navigation_goalrating_timeout_set(this);
                                this.aistatus &= ~AI_STATUS_STUCK;
                        }
                        else
index ccf2cecee9a0a14d152810a22585f862257d928c..75713e8eb3d8510ec8807646e85520f8efedd5d6 100644 (file)
@@ -25,11 +25,13 @@ entity navigation_bestgoal;
 .entity goalstack28, goalstack29, goalstack30, goalstack31;
 
 .entity goalcurrent_prev;
-.float goalcurrent_distance;
+.float goalcurrent_distance_z;
+.float goalcurrent_distance_2d;
 .float goalcurrent_distance_time;
 
+.float goalentity_lock_timeout;
+
 .entity nearestwaypoint;
-.float nearestwaypoint_dist;
 .float nearestwaypointtimeout;
 
 /*
@@ -48,54 +50,8 @@ entity navigation_bestgoal;
 #define navigation_item_addlink(from_wp, to_item) \
        waypoint_addlink_customcost(to_item, from_wp, waypoint_getlinkcost(from_wp, to_item))
 
-// if ent is a box waypoint or an item v is set to coords of ent that are closer to org
-#define SET_DESTCOORDS(ent, org, v) MACRO_BEGIN { \
-       if ((ent.classname != "waypoint") || ent.wpisbox) { \
-               vector wm1 = ent.origin + ent.mins; \
-               vector wm2 = ent.origin + ent.maxs; \
-               v.x = bound(wm1.x, org.x, wm2.x); \
-               v.y = bound(wm1.y, org.y, wm2.y); \
-               v.z = bound(wm1.z, org.z, wm2.z); \
-       } else { \
-               v = ent.origin; \
-       } \
-} MACRO_END
-
-// if ent is a box waypoint or an item v is set to coords of ent that are closer to org
-// (but v.z is set to the lowest coord of ent), v_height is set to ent's height
-#define SET_TRACEWALK_DESTCOORDS(ent, org, v, v_height) MACRO_BEGIN { \
-       if ((ent.classname != "waypoint") || ent.wpisbox) { \
-               vector wm1 = ent.origin + ent.mins; \
-               vector wm2 = ent.origin + ent.maxs; \
-               v.x = bound(wm1.x, org.x, wm2.x); \
-               v.y = bound(wm1.y, org.y, wm2.y); \
-               v.z = wm1.z; \
-               v_height = wm2.z - wm1.z; \
-       } else { \
-               v = ent.origin; \
-               v_height = 0; \
-       } \
-} MACRO_END
-
-// if ent is a box waypoint or an item v and v2 are set to coords of ent that are closer to org
-// (but v2.z is set to the lowest coord of ent), v2_height is set to ent's height
-#define SET_TRACEWALK_DESTCOORDS_2(ent, org, v, v2, v2_height) MACRO_BEGIN { \
-       if ((ent.classname != "waypoint") || ent.wpisbox) { \
-               vector wm1 = ent.origin + ent.mins; \
-               vector wm2 = ent.origin + ent.maxs; \
-               v.x = bound(wm1.x, org.x, wm2.x); \
-               v.y = bound(wm1.y, org.y, wm2.y); \
-               v.z = bound(wm1.z, org.z, wm2.z); \
-               v2.x = v.x; \
-               v2.y = v.y; \
-               v2.z = wm1.z; \
-               v2_height = wm2.z - wm1.z; \
-       } else { \
-               v = ent.origin; \
-               v2 = v; \
-               v2_height = 0; \
-       } \
-} MACRO_END
+vector tracewalk_dest;
+float tracewalk_dest_height;
 
 .entity wp_goal_prev0;
 .entity wp_goal_prev1;
@@ -154,9 +110,13 @@ void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost2, vecto
 void navigation_markroutes(entity this, entity fixed_source_waypoint);
 void navigation_markroutes_inverted(entity fixed_source_waypoint);
 void navigation_routerating(entity this, entity e, float f, float rangebias);
-void navigation_poptouchedgoals(entity this);
+void navigation_shortenpath(entity this);
+int navigation_poptouchedgoals(entity this);
 void navigation_goalrating_start(entity this);
 void navigation_goalrating_end(entity this);
+void navigation_goalrating_timeout_set(entity this);
+void navigation_goalrating_timeout_force(entity this);
+bool navigation_goalrating_timeout(entity this);
 void navigation_unstuck(entity this);
 
 void botframe_updatedangerousobjects(float maxupdate);
index c20f6a92943ba6f2e169ed2777343230290a367e..fa82d926b63e92776cfd293dbebccf15ba20ad04 100644 (file)
@@ -576,8 +576,12 @@ void waypoint_think(entity this)
                                continue;
                        }
 
-                       SET_TRACEWALK_DESTCOORDS_2(this, it.origin, sv, sv2, sv2_height);
-                       SET_TRACEWALK_DESTCOORDS_2(it, this.origin, ev, ev2, ev2_height);
+                       sv = set_tracewalk_dest_2(this, it.origin);
+                       sv2 = tracewalk_dest;
+                       sv2_height = tracewalk_dest_height;
+                       ev = set_tracewalk_dest_2(it, this.origin);
+                       ev2 = tracewalk_dest;
+                       ev2_height = tracewalk_dest_height;
 
                        dv = ev - sv;
                        dv.z = 0;
index affa033de1da73e3082bd12b1c8925cf7ac85330..50861c32f7d005bf40435df9449128e62eb1d05e 100644 (file)
@@ -461,7 +461,7 @@ void havocbot_role_ast_offense(entity this)
        if(this.havocbot_attack_time>time)
                return;
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
                navigation_goalrating_start(this);
                havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
@@ -469,7 +469,7 @@ void havocbot_role_ast_offense(entity this)
                havocbot_goalrating_items(this, 15000, this.origin, 10000);
                navigation_goalrating_end(this);
 
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+               navigation_goalrating_timeout_set(this);
        }
 }
 
@@ -495,7 +495,7 @@ void havocbot_role_ast_defense(entity this)
        if(this.havocbot_attack_time>time)
                return;
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
                navigation_goalrating_start(this);
                havocbot_goalrating_enemyplayers(this, 20000, this.origin, 3000);
@@ -503,7 +503,7 @@ void havocbot_role_ast_defense(entity this)
                havocbot_goalrating_items(this, 15000, this.origin, 10000);
                navigation_goalrating_end(this);
 
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+               navigation_goalrating_timeout_set(this);
        }
 }
 
index f437d98b52c837c6db59520c37d840660ece1003..ea714e6a23ba4528f38b6e189386a69215dd6603 100644 (file)
@@ -31,9 +31,6 @@ const int HAVOCBOT_AST_ROLE_OFFENSE = 4;
 .int havocbot_role_flags;
 .float havocbot_attack_time;
 
-.void(entity this) havocbot_role;
-.void(entity this) havocbot_previous_role;
-
 void(entity this) havocbot_role_ast_defense;
 void(entity this) havocbot_role_ast_offense;
 
index 3cf560ebedf752c3fc99b33cfc2aa3248bcaad2b..3c714ad5396bbb2bf237a24782722d42162d551b 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))
@@ -594,6 +597,8 @@ void ctf_Handle_Capture(entity flag, entity toucher, int capturetype)
                        { GameRules_scoring_add_team(enemy_flag.ctf_dropper, SCORE, ((enemy_flag.score_assist) ? enemy_flag.score_assist : autocvar_g_ctf_score_capture_assist)); }
        }
 
+       flag.enemy = toucher;
+
        // reset the flag
        player.next_take_time = time + autocvar_g_ctf_flag_collect_delay;
        ctf_RespawnFlag(enemy_flag);
@@ -636,6 +641,8 @@ void ctf_Handle_Return(entity flag, entity player)
        if(player.flagcarried == flag)
                WaypointSprite_Kill(player.wps_flagcarrier);
 
+       flag.enemy = player;
+
        // reset the flag
        ctf_RespawnFlag(flag);
 }
@@ -773,6 +780,7 @@ void ctf_CheckFlagReturn(entity flag, int returntype)
                        }
                        _sound(flag, CH_TRIGGER, flag.snd_flag_respawn, VOL_BASE, ATTEN_NONE);
                        ctf_EventLog("returned", flag.team, NULL);
+                       flag.enemy = NULL;
                        ctf_RespawnFlag(flag);
                }
        }
@@ -1176,8 +1184,9 @@ void ctf_RespawnFlag(entity flag)
 void ctf_Reset(entity this)
 {
        if(this.owner && IS_PLAYER(this.owner))
-        ctf_Handle_Throw(this.owner, NULL, DROP_RESET);
+               ctf_Handle_Throw(this.owner, NULL, DROP_RESET);
 
+       this.enemy = NULL;
        ctf_RespawnFlag(this);
 }
 
@@ -1653,11 +1662,10 @@ void havocbot_role_ctf_carrier(entity this)
                return;
        }
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
-
                navigation_goalrating_start(this);
+
                if(ctf_oneflag)
                        havocbot_goalrating_ctf_enemybase(this, 50000);
                else
@@ -1668,6 +1676,19 @@ void havocbot_role_ctf_carrier(entity this)
 
                navigation_goalrating_end(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)
@@ -1729,14 +1750,17 @@ void havocbot_role_ctf_escort(entity this)
        }
 
        // Chase the flag carrier
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
+
                havocbot_goalrating_ctf_enemyflag(this, 30000);
                havocbot_goalrating_ctf_ourstolenflag(this, 40000);
                havocbot_goalrating_items(this, 10000, this.origin, 10000);
+
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
@@ -1809,15 +1833,18 @@ void havocbot_role_ctf_offense(entity this)
                return;
        }
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
+
                havocbot_goalrating_ctf_ourstolenflag(this, 50000);
                havocbot_goalrating_ctf_enemybase(this, 20000);
                havocbot_goalrating_items(this, 5000, this.origin, 1000);
                havocbot_goalrating_items(this, 1000, this.origin, 10000);
+
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
@@ -1842,11 +1869,8 @@ void havocbot_role_ctf_retriever(entity this)
        mf = havocbot_ctf_find_flag(this);
        if(mf.ctf_status==FLAG_BASE)
        {
-               if(this.goalcurrent == mf)
-               {
-                       navigation_clearroute(this);
-                       this.bot_strategytime = 0;
-               }
+               if (mf.enemy == this) // did this bot return the flag?
+                       navigation_goalrating_timeout_force(this);
                havocbot_ctf_reset_role(this);
                return;
        }
@@ -1860,18 +1884,21 @@ void havocbot_role_ctf_retriever(entity this)
                return;
        }
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
                float rt_radius;
                rt_radius = 10000;
 
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
+
                havocbot_goalrating_ctf_ourstolenflag(this, 50000);
                havocbot_goalrating_ctf_droppedflags(this, 40000, this.origin, rt_radius);
                havocbot_goalrating_ctf_enemybase(this, 30000);
                havocbot_goalrating_items(this, 500, this.origin, rt_radius);
+
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
@@ -1907,22 +1934,25 @@ void havocbot_role_ctf_middle(entity this)
                return;
        }
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
                vector org;
 
                org = havocbot_middlepoint;
                org.z = this.origin.z;
 
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
+
                havocbot_goalrating_ctf_ourstolenflag(this, 50000);
                havocbot_goalrating_ctf_droppedflags(this, 30000, this.origin, 10000);
                havocbot_goalrating_enemyplayers(this, 10000, org, havocbot_middlepoint_radius * 0.5);
                havocbot_goalrating_items(this, 5000, org, havocbot_middlepoint_radius * 0.5);
                havocbot_goalrating_items(this, 2500, this.origin, 10000);
                havocbot_goalrating_ctf_enemybase(this, 2500);
+
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
@@ -1958,11 +1988,10 @@ void havocbot_role_ctf_defense(entity this)
                havocbot_ctf_reset_role(this);
                return;
        }
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
                vector org = mf.dropped_origin;
 
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
 
                // if enemies are closer to our base, go there
@@ -1988,7 +2017,10 @@ void havocbot_role_ctf_defense(entity this)
                havocbot_goalrating_enemyplayers(this, 15000, org, havocbot_middlepoint_radius);
                havocbot_goalrating_items(this, 10000, org, havocbot_middlepoint_radius);
                havocbot_goalrating_items(this, 5000, this.origin, 10000);
+
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
@@ -2002,7 +2034,8 @@ void havocbot_role_ctf_setrole(entity bot, int role)
                        bot.havocbot_role = havocbot_role_ctf_carrier;
                        bot.havocbot_role_timeout = 0;
                        bot.havocbot_cantfindflag = time + 10;
-                       bot.bot_strategytime = 0;
+                       if (bot.havocbot_previous_role != bot.havocbot_role)
+                               navigation_goalrating_timeout_force(bot);
                        break;
                case HAVOCBOT_CTF_ROLE_DEFENSE:
                        s = "defense";
@@ -2024,14 +2057,16 @@ void havocbot_role_ctf_setrole(entity bot, int role)
                        bot.havocbot_previous_role = bot.havocbot_role;
                        bot.havocbot_role = havocbot_role_ctf_retriever;
                        bot.havocbot_role_timeout = time + 10;
-                       bot.bot_strategytime = 0;
+                       if (bot.havocbot_previous_role != bot.havocbot_role)
+                               navigation_goalrating_timeout_expire(bot, 2);
                        break;
                case HAVOCBOT_CTF_ROLE_ESCORT:
                        s = "escort";
                        bot.havocbot_previous_role = bot.havocbot_role;
                        bot.havocbot_role = havocbot_role_ctf_escort;
                        bot.havocbot_role_timeout = time + 30;
-                       bot.bot_strategytime = 0;
+                       if (bot.havocbot_previous_role != bot.havocbot_role)
+                               navigation_goalrating_timeout_expire(bot, 2);
                        break;
        }
        LOG_TRACE(bot.netname, " switched to ", s);
index 0b86a57f809936604fd51a5514b899108558dcac..33d64a074a290610fdb43a45dbfa7f08a996ede4 100644 (file)
@@ -133,6 +133,7 @@ float ctf_captimerecord; // record time for capturing the flag
 .float next_take_time;
 .bool ctf_flagdamaged_byworld;
 int ctf_teams;
+.entity enemy; // when flag is back in the base, it remembers last player who carried/touched the flag, useful to bots
 
 // passing/throwing properties
 .float pass_distance;
index 0bfdc02fa2380ceadd6fdde783eed9a6e08e24a9..daaf8a969592e810af3531a1cdcded327b46a8fc 100644 (file)
@@ -13,9 +13,8 @@ void havocbot_role_cts(entity this)
        if(IS_DEAD(this))
                return;
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
 
                bool raw_touch_check = true;
@@ -40,6 +39,8 @@ void havocbot_role_cts(entity this)
                });
 
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
index be38553c9588bcd4ba1bfd79042432f79aebd583..5980cfbaf38241826244c3f27e3b44d4998017aa 100644 (file)
@@ -402,15 +402,16 @@ void havocbot_role_dom(entity this)
        if(IS_DEAD(this))
                return;
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
                havocbot_goalrating_controlpoints(this, 10000, this.origin, 15000);
                havocbot_goalrating_items(this, 8000, this.origin, 8000);
                //havocbot_goalrating_enemyplayers(this, 3000, this.origin, 2000);
                havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
index 88afaa755d7b9f995419411e912d431b7d4ec166..2ea70c1f1ac16971c6af11a3aa33a4b3f3b0f9d5 100644 (file)
@@ -257,16 +257,16 @@ void havocbot_role_ft_offense(entity this)
                return;
        }
 
-       if (time > this.bot_strategytime)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
-
                navigation_goalrating_start(this);
                havocbot_goalrating_items(this, 10000, this.origin, 10000);
                havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
                havocbot_goalrating_freeplayers(this, 9000, this.origin, 10000);
                havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
@@ -286,16 +286,16 @@ void havocbot_role_ft_freeing(entity this)
                return;
        }
 
-       if (time > this.bot_strategytime)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
-
                navigation_goalrating_start(this);
                havocbot_goalrating_items(this, 8000, this.origin, 10000);
                havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
                havocbot_goalrating_freeplayers(this, 20000, this.origin, 10000);
                havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
index 7b33bea6f374dd585755e6a31f572830b514b73d..badae12c2d4897090aaec805bc594d4f1cc9de76 100644 (file)
@@ -232,21 +232,21 @@ void havocbot_role_ka_carrier(entity this)
        if (IS_DEAD(this))
                return;
 
-       if (time > this.bot_strategytime)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
-
                navigation_goalrating_start(this);
                havocbot_goalrating_items(this, 10000, this.origin, 10000);
                havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
                havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 
        if (!this.ballcarried)
        {
                this.havocbot_role = havocbot_role_ka_collector;
-               this.bot_strategytime = 0;
+               navigation_goalrating_timeout_expire(this, 2);
        }
 }
 
@@ -255,21 +255,21 @@ void havocbot_role_ka_collector(entity this)
        if (IS_DEAD(this))
                return;
 
-       if (time > this.bot_strategytime)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
-
                navigation_goalrating_start(this);
                havocbot_goalrating_items(this, 10000, this.origin, 10000);
                havocbot_goalrating_enemyplayers(this, 1000, this.origin, 10000);
                havocbot_goalrating_ball(this, 20000, this.origin);
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 
        if (this.ballcarried)
        {
                this.havocbot_role = havocbot_role_ka_carrier;
-               this.bot_strategytime = 0;
+               navigation_goalrating_timeout_expire(this, 2);
        }
 }
 
index 15b6e0f4a6251d81a94d9501858abca0ee0ae602..e6253b091fe49136f822a7e26c9b6df51de7bab4 100644 (file)
@@ -1071,9 +1071,8 @@ void havocbot_role_kh_carrier(entity this)
                return;
        }
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
 
                if(kh_Key_AllOwnedByWhichTeam() == this.team)
@@ -1082,6 +1081,8 @@ void havocbot_role_kh_carrier(entity this)
                        havocbot_goalrating_kh(this, 4, 4, 1); // play defensively
 
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
@@ -1108,10 +1109,9 @@ void havocbot_role_kh_defense(entity this)
                return;
        }
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
                float key_owner_team;
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
 
                key_owner_team = kh_Key_AllOwnedByWhichTeam();
@@ -1123,6 +1123,8 @@ void havocbot_role_kh_defense(entity this)
                        havocbot_goalrating_kh(this, 0.1, 0.1, 10); // ATTACK ANYWAY
 
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
@@ -1149,11 +1151,10 @@ void havocbot_role_kh_offense(entity this)
                return;
        }
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
                float key_owner_team;
 
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
 
                key_owner_team = kh_Key_AllOwnedByWhichTeam();
@@ -1165,6 +1166,8 @@ void havocbot_role_kh_offense(entity this)
                        havocbot_goalrating_kh(this, 0.1, 0.1, 10); // ATTACK! EMERGENCY!
 
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
@@ -1199,9 +1202,8 @@ void havocbot_role_kh_freelancer(entity this)
                return;
        }
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
 
                int key_owner_team = kh_Key_AllOwnedByWhichTeam();
@@ -1213,6 +1215,8 @@ void havocbot_role_kh_freelancer(entity this)
                        havocbot_goalrating_kh(this, 0.1, 0.1, 10); // ATTACK ANYWAY
 
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
index 9c2d60f38e7889991b0500fd22d7dcff660d4d52..690d23ca8bc3e2595df612f403185eba0975ee9c 100644 (file)
@@ -14,9 +14,8 @@ void havocbot_role_race(entity this)
        if(IS_DEAD(this))
                return;
 
-       if (this.bot_strategytime < time)
+       if (navigation_goalrating_timeout(this))
        {
-               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
                navigation_goalrating_start(this);
 
                bool raw_touch_check = true;
@@ -37,10 +36,11 @@ void havocbot_role_race(entity this)
                                        goto search_racecheckpoints;
                                }
                                navigation_routerating(this, it, 1000000, 5000);
-                       }
                });
 
                navigation_goalrating_end(this);
+
+               navigation_goalrating_timeout_set(this);
        }
 }
 
index 4a603c02256d244dd69fca54040a80b9f4faeed1..097685abf1766820a9e3f964928da71172c31d5b 100644 (file)
@@ -22,6 +22,8 @@ const string STR_OBSERVER = "observer";
 #define IS_VEHICLE(v) (v.vehicle_flags & VHF_ISVEHICLE)
 #define IS_TURRET(v) (v.turret_flags & TUR_FLAG_ISTURRET)
 
+#define IS_MOVABLE(v) ((IS_PLAYER(v) || IS_MONSTER(v)) && !STAT(FROZEN, v))
+
 // NOTE: FOR_EACH_CLIENTSLOT deprecated! Use the following instead: FOREACH_CLIENTSLOT(true, { code; });
 // NOTE: FOR_EACH_CLIENT deprecated! Use the following instead: FOREACH_CLIENT(true, { code; });
 // NOTE: FOR_EACH_REALCLIENT deprecated! Use the following instead: FOREACH_CLIENT(IS_REAL_CLIENT(it), { code; });