]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'master' into mand1nga/pathfinding-optimizations
authormand1nga <mand1nga@xonotic.org>
Sat, 13 Aug 2011 03:51:05 +0000 (00:51 -0300)
committermand1nga <mand1nga@xonotic.org>
Sat, 13 Aug 2011 03:51:05 +0000 (00:51 -0300)
Conflicts:
qcsrc/server/bot/navigation.qc

qcsrc/server/bot/aim.qc
qcsrc/server/bot/havocbot/havocbot.qc
qcsrc/server/bot/havocbot/roles.qc
qcsrc/server/bot/navigation.qc

index 63e971b17da9c52cacc638e8ae6c3f006cff096f..699748fdae58401b0fe3d9002977e88ac17f7993 100644 (file)
@@ -7,7 +7,7 @@ entity ka_ball;
 float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, float shotspeed, float shotspeedupward, float maxtime, float shotdelay, entity ignore)
 {
        local float c, savesolid, shottime;
-       local vector dir, end, v;
+       local vector dir, end, v, o;
        if (shotspeed < 1)
                return FALSE; // could cause division by zero if calculated
        if (targ.solid < SOLID_BBOX) // SOLID_NOT and SOLID_TRIGGER
@@ -18,9 +18,10 @@ float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, f
        setsize(tracetossent, m1, m2);
        savesolid = targ.solid;
        targ.solid = SOLID_NOT;
-       shottime = ((vlen(targ.origin - org) / shotspeed) + shotdelay);
-       v = targ.velocity * shottime + targ.origin;
-       tracebox(targ.origin, targ.mins, targ.maxs, v, FALSE, targ);
+       o = (targ.absmin + targ.absmax) * 0.5;
+       shottime = ((vlen(o - org) / shotspeed) + shotdelay);
+       v = targ.velocity * shottime + o;
+       tracebox(o, targ.mins, targ.maxs, v, FALSE, targ);
        v = trace_endpos;
        end = v + (targ.mins + targ.maxs) * 0.5;
        if ((vlen(end - org) / shotspeed + 0.2) > maxtime)
index 7c2f986346677e73b2cefc533cf45651ebd18cf0..377dc2ef97237b60ccdc91ff06c4414f5da03f88 100644 (file)
@@ -120,7 +120,7 @@ void havocbot_ai()
 
                local vector now,v,next;//,heading;
                local float aimdistance,skillblend,distanceblend,blend;
-               next = now = self.goalcurrent.origin - (self.origin + self.view_ofs);
+               next = now = ( (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5) - (self.origin + self.view_ofs);
                aimdistance = vlen(now);
                //heading = self.velocity;
                //dprint(self.goalstack01.classname,etos(self.goalstack01),"\n");
@@ -128,7 +128,7 @@ void havocbot_ai()
                        self.goalstack01 != self && self.goalstack01 != world && self.aistatus & AI_STATUS_RUNNING == 0 &&
                        !(self.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
                )
-                       next = self.goalstack01.origin - (self.origin + self.view_ofs);
+                       next = ((self.goalstack01.absmin + self.goalstack01.absmax) * 0.5) - (self.origin + self.view_ofs);
 
                skillblend=bound(0,(skill+self.bot_moveskill-2.5)*0.5,1); //lower skill player can't preturn
                distanceblend=bound(0,aimdistance/autocvar_bot_ai_keyboard_distance,1);
@@ -254,6 +254,7 @@ void havocbot_bunnyhop(vector dir)
        local float bunnyhopdistance;
        local vector deviation;
        local float maxspeed;
+       vector gco, gno;
 
        if(autocvar_g_midair)
                return;
@@ -291,7 +292,8 @@ void havocbot_bunnyhop(vector dir)
                self.bot_timelastseengoal = 0;
        }
 
-       bunnyhopdistance = vlen(self.origin - self.goalcurrent.origin);
+       gco = (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5;
+       bunnyhopdistance = vlen(self.origin - gco);
 
        // Run only to visible goals
        if(self.flags & FL_ONGROUND)
@@ -324,18 +326,19 @@ void havocbot_bunnyhop(vector dir)
                                        if(self.aistatus & AI_STATUS_ROAMING)
                                        if(self.goalcurrent.classname=="waypoint")
                                        if not(self.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL)
-                                       if(fabs(self.goalcurrent.origin_z - self.origin_z) < self.maxs_z - self.mins_z)
+                                       if(fabs(gco_z - self.origin_z) < self.maxs_z - self.mins_z)
                                        if(self.goalstack01!=world)
                                        {
-                                               deviation = vectoangles(self.goalstack01.origin - self.origin) - vectoangles(self.goalcurrent.origin - self.origin);
+                                               gno = (self.goalstack01.absmin + self.goalstack01.absmax) * 0.5;
+                                               deviation = vectoangles(gno - self.origin) - vectoangles(gco - self.origin);
                                                while (deviation_y < -180) deviation_y = deviation_y + 360;
                                                while (deviation_y > 180) deviation_y = deviation_y - 360;
 
                                                if(fabs(deviation_y) < 20)
-                                               if(bunnyhopdistance < vlen(self.origin - self.goalstack01.origin))
-                                               if(fabs(self.goalstack01.origin_z - self.goalcurrent.origin_z) < self.maxs_z - self.mins_z)
+                                               if(bunnyhopdistance < vlen(self.origin - gno))
+                                               if(fabs(gno_z - gco_z) < self.maxs_z - self.mins_z)
                                                {
-                                                       if(vlen(self.goalcurrent.origin - self.goalstack01.origin) > autocvar_bot_ai_bunnyhop_startdistance)
+                                                       if(vlen(gco - gno) > autocvar_bot_ai_bunnyhop_startdistance)
                                                        if(checkpvs(self.origin + self.view_ofs, self.goalstack01))
                                                        {
                                                                checkdistance = FALSE;
@@ -405,6 +408,7 @@ void havocbot_movetogoal()
        local vector evadelava;
        local float s;
        local float maxspeed;
+       local vector gco;
        //local float dist;
        local vector dodge;
        //if (self.goalentity)
@@ -443,7 +447,7 @@ void havocbot_movetogoal()
                        float db, v, d;
                        vector dxy;
 
-                       dxy = self.origin - self.goalcurrent.origin; dxy_z = 0;
+                       dxy = self.origin - ( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ); dxy_z = 0;
                        d = vlen(dxy);
                        v = vlen(self.velocity -  self.velocity_z * '0 0 1');
                        db = (pow(v,2) / (autocvar_g_jetpack_acceleration_side * 2)) + 100;
@@ -501,7 +505,7 @@ void havocbot_movetogoal()
                                        if(distance>1000)
                                                continue;
 
-                                       traceline(self.origin + self.view_ofs , head.origin, TRUE, world);
+                                       traceline(self.origin + self.view_ofs , ( ( head.absmin + head.absmax ) * 0.5 ), TRUE, world);
 
                                        if(trace_fraction<1)
                                                continue;
@@ -571,7 +575,7 @@ void havocbot_movetogoal()
                        if(self.goalcurrent==world)
                                dir = v_forward;
                        else
-                               dir = normalize(self.goalcurrent.origin - self.origin);
+                               dir = normalize(( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ) - self.origin);
 
                        local vector xyvelocity = self.velocity; xyvelocity_z = 0;
                        local float xyspeed = xyvelocity * dir;
@@ -656,6 +660,7 @@ void havocbot_movetogoal()
                return;
        }
 
+
        if(autocvar_bot_debug_goalstack)
                debuggoalstack();
 
@@ -670,6 +675,7 @@ void havocbot_movetogoal()
        dir = normalize(diff);
        flatdir = diff;flatdir_z = 0;
        flatdir = normalize(flatdir);
+       gco = (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5;
 
        //if (self.bot_dodgevector_time < time)
        {
@@ -687,7 +693,7 @@ void havocbot_movetogoal()
                        }
                        else
                        {
-                               if(self.velocity_z >= 0 && !(self.watertype == CONTENT_WATER && self.goalcurrent.origin_z < self.origin_z) &&
+                               if(self.velocity_z >= 0 && !(self.watertype == CONTENT_WATER && gco_z < self.origin_z) &&
                                        ( !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER) || self.aistatus & AI_STATUS_OUT_WATER))
                                        self.BUTTON_JUMP = TRUE;
                                else
@@ -783,7 +789,11 @@ void havocbot_movetogoal()
                                                {
                                                        // Remove dangerous dynamic goals from stack
                                                        if (self.goalcurrent.classname == "player" || self.goalcurrent.classname == "droppedweapon")
+                                                       {
                                                                navigation_poproute();
+                                                               if(self.goalcurrent)
+                                                                       gco = (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5;
+                                                       }
                                                        // try to stop
                                                        flatdir = '0 0 0';
                                                        evadeobstacle = normalize(self.velocity) * -1;
@@ -804,7 +814,7 @@ void havocbot_movetogoal()
                dodge = havocbot_dodge();
                dodge = dodge * bound(0,0.5+(skill+self.bot_dodgeskill)*0.1,1);
                evadelava = evadelava * bound(1,3-(skill+self.bot_dodgeskill),3); //Noobs fear lava a lot and take more distance from it
-               traceline(self.origin, self.enemy.origin, TRUE, world);
+               traceline(self.origin, ( ( self.enemy.absmin + self.enemy.absmax ) * 0.5 ), TRUE, world);
                if(trace_ent.classname == "player")
                        dir = dir * bound(0,(skill+self.bot_dodgeskill)/7,1);
 
@@ -874,9 +884,9 @@ void havocbot_chooseenemy()
                        // and not really really far away
                        // and we're not severely injured
                        // then keep tracking for a half second into the future
-                       traceline(self.origin+self.view_ofs, self.enemy.origin+self.enemy.view_ofs*0.5,FALSE,world);
+                       traceline(self.origin+self.view_ofs, ( self.enemy.absmin + self.enemy.absmax ) * 0.5,FALSE,world);
                        if (trace_ent == self.enemy || trace_fraction == 1)
-                       if (vlen(self.enemy.origin - self.origin) < 1000)
+                       if (vlen((( self.enemy.absmin + self.enemy.absmax ) * 0.5) - self.origin) < 1000)
                        if (self.health > 30)
                        {
                                // remain tracking him for a shot while (case he went after a small corner or pilar
@@ -1084,10 +1094,10 @@ void havocbot_aim()
                enemyvel = self.enemy.velocity;
                if (!self.enemy.waterlevel)
                        enemyvel_z = 0;
-               lag_additem(time + self.ping, 0, 0, self.enemy, self.origin, selfvel, self.enemy.origin, enemyvel);
+               lag_additem(time + self.ping, 0, 0, self.enemy, self.origin, selfvel, (self.enemy.absmin + self.enemy.absmax) * 0.5, enemyvel);
        }
        else
-               lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, self.goalcurrent.origin, '0 0 0');
+               lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5, '0 0 0');
 };
 
 float havocbot_moveto_refresh_route()
@@ -1145,7 +1155,7 @@ float havocbot_moveto(vector pos)
                        debuggoalstack();
 
                // Heading
-               local vector dir = self.goalcurrent.origin - (self.origin + self.view_ofs);
+               local vector dir = ( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ) - (self.origin + self.view_ofs);
                dir_z = 0;
                bot_aimdir(dir, -1);
 
index ac52c698f6cdb10c6387799898f9f400ebc5ef54..18699a7bd6f310001cc50e3ac359d250a55f6e5a 100644 (file)
@@ -10,12 +10,14 @@ void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
        local entity head;
        local entity player;
        local float rating, d, discard, distance, friend_distance, enemy_distance;
+       vector o;
        ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
        head = findchainfloat(bot_pickup, TRUE);
 
        while (head)
        {
-               distance = vlen(head.origin - org);
+               o = (head.absmin + head.absmax) * 0.5;
+               distance = vlen(o - org);
                friend_distance = 10000; enemy_distance = 10000;
                rating = 0;
 
@@ -28,7 +30,7 @@ void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
                // Check if the item can be picked up safely
                if(head.classname == "droppedweapon")
                {
-                       traceline(head.origin, head.origin + '0 0 -1500', TRUE, world);
+                       traceline(o, o + '0 0 -1500', TRUE, world);
 
                        d = pointcontents(trace_endpos + '0 0 1');
                        if(d & CONTENT_WATER || d & CONTENT_SLIME || d & CONTENT_LAVA)
@@ -63,7 +65,7 @@ void havocbot_goalrating_items(float ratingscale, vector org, float sradius)
                                if ( self == player || player.deadflag )
                                        continue;
 
-                               d = vlen(player.origin - head.origin); // distance between player and item
+                               d = vlen(player.origin - o); // distance between player and item
 
                                if ( player.team == self.team )
                                {
@@ -131,7 +133,7 @@ void havocbot_goalrating_controlpoints(float ratingscale, vector org, float srad
        head = findchain(classname, "dom_controlpoint");
        while (head)
        {
-               if (vlen(head.origin - org) < sradius)
+               if (vlen(( ( head.absmin + head.absmax ) * 0.5 ) - org) < sradius)
                {
                        if(head.cnt > -1) // this is just being fought for
                                navigation_routerating(head, ratingscale, 5000);
index ee1d60ffa4422c989d23d8400e9a7225e1b7a79a..2d66b021327e116231d567c989b2f77c7728d388 100644 (file)
@@ -641,19 +641,22 @@ void navigation_markroutes_inverted(entity fixed_source_waypoint)
 void navigation_routerating(entity e, float f, float rangebias)
 {
        entity nwp;
+       vector o;
        if (!e)
                return;
 
        if(e.blacklisted)
                return;
 
+       o = (e.absmin + e.absmax) * 0.5;
+
        //print("routerating ", etos(e), " = ", ftos(f), " - ", ftos(rangebias), "\n");
 
        // Evaluate path using jetpack
        if(g_jetpack)
        if(self.items & IT_JETPACK)
        if(autocvar_bot_ai_navigation_jetpack)
-       if(vlen(self.origin - e.origin) > autocvar_bot_ai_navigation_jetpack_mindistance)
+       if(vlen(self.origin - o) > autocvar_bot_ai_navigation_jetpack_mindistance)
        {
                vector pointa, pointb;
 
@@ -664,7 +667,7 @@ void navigation_routerating(entity e, float f, float rangebias)
                pointa = trace_endpos - '0 0 1';
 
                // Point B
-               traceline(e.origin, e.origin + '0 0 65535', MOVE_NORMAL, e);
+               traceline(o, o + '0 0 65535', MOVE_NORMAL, e);
                pointb = trace_endpos - '0 0 1';
 
                // Can I see these two points from the sky?
@@ -805,7 +808,7 @@ void navigation_routerating(entity e, float f, float rangebias)
        {
                //te_wizspike(nwp.wpnearestpoint);
        //      dprint(e.classname, " ", ftos(f), "/(1+", ftos((nwp.wpcost + vlen(e.origin - nwp.wpnearestpoint))), "/", ftos(rangebias), ") = ");
-               f = f * rangebias / (rangebias + (nwp.wpcost + vlen(e.origin - nwp.wpnearestpoint)));
+               f = f * rangebias / (rangebias + (nwp.wpcost + vlen(o - nwp.wpnearestpoint)));
                //dprint("considering ", e.classname, " (with rating ", ftos(f), ")\n");
                //dprint(ftos(f));
                if (navigation_bestrating < f)
@@ -838,7 +841,7 @@ float navigation_routetogoal(entity e, vector startposition)
                return TRUE;
 
        // if it can reach the goal there is nothing more to do
-       if (tracewalk(self, startposition, PL_MIN, PL_MAX, e.origin, bot_navigation_movemode))
+       if (tracewalk(self, startposition, PL_MIN, PL_MAX, (e.absmin + e.absmax) * 0.5, bot_navigation_movemode))
                return TRUE;
 
        // see if there are waypoints describing a path to the item
@@ -964,7 +967,7 @@ void navigation_goalrating_end()
 void botframe_updatedangerousobjects(float maxupdate)
 {
        local entity head, bot_dodgelist;
-       local vector m1, m2, v;
+       local vector m1, m2, v, o;
        local float c, d, danger;
        c = 0;
        bot_dodgelist = findchainfloat(bot_dodge, TRUE);
@@ -981,10 +984,11 @@ void botframe_updatedangerousobjects(float maxupdate)
                        v_x = bound(m1_x, v_x, m2_x);
                        v_y = bound(m1_y, v_y, m2_y);
                        v_z = bound(m1_z, v_z, m2_z);
-                       d = head.bot_dodgerating - vlen(head.origin - v);
+                       o = (head.absmin + head.absmax) * 0.5;
+                       d = head.bot_dodgerating - vlen(o - v);
                        if (d > 0)
                        {
-                               traceline(head.origin, v, TRUE, world);
+                               traceline(o, v, TRUE, world);
                                if (trace_fraction == 1)
                                        danger = danger + d;
                        }
@@ -1141,7 +1145,7 @@ void debugnodestatus(vector position, float status)
 void debuggoalstack()
 {
        local entity goal;
-       local vector org;
+       local vector org, go;
 
        if(self.goalcounter==0)goal=self.goalcurrent;
        else if(self.goalcounter==1)goal=self.goalstack01;
@@ -1189,8 +1193,9 @@ void debuggoalstack()
                org = self.lastposition;
 
 
-       te_lightning2(world, org, goal.origin);
-       self.lastposition = goal.origin;
+       go = ( goal.absmin + goal.absmax ) * 0.5;
+       te_lightning2(world, org, go);
+       self.lastposition = go;
 
        self.goalcounter++;
 }