]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Set the right hit flags for bot aiming
authormand1nga <mand1nga@xonotic.org>
Thu, 18 Aug 2011 12:38:23 +0000 (09:38 -0300)
committermand1nga <mand1nga@xonotic.org>
Thu, 18 Aug 2011 12:38:23 +0000 (09:38 -0300)
qcsrc/server/bot/aim.qc
qcsrc/server/bot/havocbot/havocbot.qc

index 699748fdae58401b0fe3d9002977e88ac17f7993..b678bf1b660de2a9920d29ebc5e8af7a2ef554ab 100644 (file)
@@ -320,7 +320,7 @@ vector bot_shotlead(vector targorigin, vector targvelocity, float shotspeed, flo
 
 float bot_aim(float shotspeed, float shotspeedupward, float maxshottime, float applygravity)
 {
 
 float bot_aim(float shotspeed, float shotspeedupward, float maxshottime, float applygravity)
 {
-       local float f, r;
+       local float f, r, hf, distanceratio;
        local vector v;
        /*
        eprint(self);
        local vector v;
        /*
        eprint(self);
@@ -330,6 +330,10 @@ float bot_aim(float shotspeed, float shotspeedupward, float maxshottime, float a
        dprint(", ", ftos(applygravity));
        dprint(");\n");
        */
        dprint(", ", ftos(applygravity));
        dprint(");\n");
        */
+
+       hf = self.dphitcontentsmask;
+       self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
+
        shotspeed *= g_weaponspeedfactor;
        shotspeedupward *= g_weaponspeedfactor;
        if (!shotspeed)
        shotspeed *= g_weaponspeedfactor;
        shotspeedupward *= g_weaponspeedfactor;
        if (!shotspeed)
@@ -346,15 +350,18 @@ float bot_aim(float shotspeed, float shotspeedupward, float maxshottime, float a
        shotorg = self.origin + self.view_ofs;
        shotdir = v_forward;
        v = bot_shotlead(self.bot_aimtargorigin, self.bot_aimtargvelocity, shotspeed, self.bot_aimlatency);
        shotorg = self.origin + self.view_ofs;
        shotdir = v_forward;
        v = bot_shotlead(self.bot_aimtargorigin, self.bot_aimtargvelocity, shotspeed, self.bot_aimlatency);
-       local float distanceratio;
-       distanceratio =sqrt(bound(0,skill,10000))*0.3*(vlen(v-shotorg)-100)/autocvar_bot_ai_aimskill_firetolerance_distdegrees;
+       distanceratio = sqrt(bound(0,skill,10000))*0.3*(vlen(v-shotorg)-100)/autocvar_bot_ai_aimskill_firetolerance_distdegrees;
        distanceratio = bound(0,distanceratio,1);
        r =  (autocvar_bot_ai_aimskill_firetolerance_maxdegrees-autocvar_bot_ai_aimskill_firetolerance_mindegrees)
                * (1-distanceratio) + autocvar_bot_ai_aimskill_firetolerance_mindegrees;
        if (applygravity && self.bot_aimtarg)
        {
                if (!findtrajectorywithleading(shotorg, '0 0 0', '0 0 0', self.bot_aimtarg, shotspeed, shotspeedupward, maxshottime, 0, self))
        distanceratio = bound(0,distanceratio,1);
        r =  (autocvar_bot_ai_aimskill_firetolerance_maxdegrees-autocvar_bot_ai_aimskill_firetolerance_mindegrees)
                * (1-distanceratio) + autocvar_bot_ai_aimskill_firetolerance_mindegrees;
        if (applygravity && self.bot_aimtarg)
        {
                if (!findtrajectorywithleading(shotorg, '0 0 0', '0 0 0', self.bot_aimtarg, shotspeed, shotspeedupward, maxshottime, 0, self))
+               {
+                       self.dphitcontentsmask = hf;
                        return FALSE;
                        return FALSE;
+               }
+
                f = bot_aimdir(findtrajectory_velocity - shotspeedupward * '0 0 1', r);
        }
        else
                f = bot_aimdir(findtrajectory_velocity - shotspeedupward * '0 0 1', r);
        }
        else
@@ -370,10 +377,14 @@ float bot_aim(float shotspeed, float shotspeedupward, float maxshottime, float a
                if (trace_fraction < 1)
                if (trace_ent != self.enemy)
                if (!bot_shouldattack(trace_ent))
                if (trace_fraction < 1)
                if (trace_ent != self.enemy)
                if (!bot_shouldattack(trace_ent))
+               {
+                       self.dphitcontentsmask = hf;
                        return FALSE;
                        return FALSE;
+               }
        }
 
        //if (r > maxshottime * shotspeed)
        //      return FALSE;
        }
 
        //if (r > maxshottime * shotspeed)
        //      return FALSE;
+       self.dphitcontentsmask = hf;
        return TRUE;
 };
        return TRUE;
 };
index 79f305a2673af51b9cfe7cfe6326ebe2035d683d..7e511350c1bad4700eb03810bf360613c3fb5559 100644 (file)
@@ -863,7 +863,7 @@ void havocbot_movetogoal()
 void havocbot_chooseenemy()
 {
        local entity head, best, head2;
 void havocbot_chooseenemy()
 {
        local entity head, best, head2;
-       local float rating, bestrating, i, f;
+       local float rating, bestrating, i, hf;
        local vector eye, v;
        if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(self))
        {
        local vector eye, v;
        if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(self))
        {
@@ -908,7 +908,13 @@ void havocbot_chooseenemy()
        bestrating = 100000000;
        head = head2 = findchainfloat(bot_attack, TRUE);
 
        bestrating = 100000000;
        head = head2 = findchainfloat(bot_attack, TRUE);
 
+       // Backup hit flags
+       hf = self.dphitcontentsmask;
+
        // Search for enemies, if no enemy can be seen directly try to look through transparent objects
        // Search for enemies, if no enemy can be seen directly try to look through transparent objects
+
+       self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
+
        for(;;)
        {
                while (head)
        for(;;)
        {
                while (head)
@@ -937,16 +943,14 @@ void havocbot_chooseenemy()
                        break;
 
                // Set flags to see through transparent objects
                        break;
 
                // Set flags to see through transparent objects
-               f = self.dphitcontentsmask;
-               self.dphitcontentsmask = DPCONTENTS_OPAQUE;
+               self.dphitcontentsmask |= DPCONTENTS_OPAQUE;
 
                head = head2;
                ++i;
        }
 
 
                head = head2;
                ++i;
        }
 
-       // Restore hit flags if needed
-       if(i)
-               self.dphitcontentsmask = f;
+       // Restore hit flags
+       self.dphitcontentsmask = hf;
 
        self.enemy = best;
        self.havocbot_stickenemy = TRUE;
 
        self.enemy = best;
        self.havocbot_stickenemy = TRUE;