From: mand1nga Date: Thu, 18 Aug 2011 12:38:23 +0000 (-0300) Subject: Set the right hit flags for bot aiming X-Git-Tag: xonotic-v0.5.0~121 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=41b6732cfca1b6f5a3387f402103631e4ae1ba6a;p=xonotic%2Fxonotic-data.pk3dir.git Set the right hit flags for bot aiming --- diff --git a/qcsrc/server/bot/aim.qc b/qcsrc/server/bot/aim.qc index 699748fda..b678bf1b6 100644 --- a/qcsrc/server/bot/aim.qc +++ b/qcsrc/server/bot/aim.qc @@ -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) { - local float f, r; + local float f, r, hf, distanceratio; 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"); */ + + hf = self.dphitcontentsmask; + self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE; + 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); - 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)) + { + self.dphitcontentsmask = hf; return FALSE; + } + 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)) + { + self.dphitcontentsmask = hf; return FALSE; + } } //if (r > maxshottime * shotspeed) // return FALSE; + self.dphitcontentsmask = hf; return TRUE; }; diff --git a/qcsrc/server/bot/havocbot/havocbot.qc b/qcsrc/server/bot/havocbot/havocbot.qc index 79f305a26..7e511350c 100644 --- a/qcsrc/server/bot/havocbot/havocbot.qc +++ b/qcsrc/server/bot/havocbot/havocbot.qc @@ -863,7 +863,7 @@ void havocbot_movetogoal() 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)) { @@ -908,7 +908,13 @@ void havocbot_chooseenemy() 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 + + self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE; + for(;;) { while (head) @@ -937,16 +943,14 @@ void havocbot_chooseenemy() break; // Set flags to see through transparent objects - f = self.dphitcontentsmask; - self.dphitcontentsmask = DPCONTENTS_OPAQUE; + self.dphitcontentsmask |= DPCONTENTS_OPAQUE; 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;