From 9feb4745d469262ef8b5b485a3edf3482259a83f Mon Sep 17 00:00:00 2001 From: INeedBots Date: Thu, 11 Mar 2021 15:11:19 -0600 Subject: [PATCH] FIx rubberbanding --- main_shared/maps/mp/bots/_bot_internal.gsc | 72 ++++++++++++---------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/main_shared/maps/mp/bots/_bot_internal.gsc b/main_shared/maps/mp/bots/_bot_internal.gsc index bb8d048..a48d33e 100644 --- a/main_shared/maps/mp/bots/_bot_internal.gsc +++ b/main_shared/maps/mp/bots/_bot_internal.gsc @@ -133,6 +133,8 @@ resetBotVars() self.bot.stop_move = false; self.bot.greedy_path = false; self.bot.climbing = false; + self.bot.last_next_wp = -1; + self.bot.last_second_next_wp = -1; self.bot.isfrozen = false; self.bot.sprintendtime = -1; @@ -147,6 +149,7 @@ resetBotVars() self.bot.semi_time = false; self.bot.jump_time = undefined; + self.bot.last_fire_time = -1; self.bot.is_cur_full_auto = false; self.bot.cur_weap_dist_multi = 1; @@ -250,7 +253,7 @@ doBotMovement() // check if need to jump bt = bulletTrace(startPosForward, startPosForward - (0, 0, 40), false, self); - if (bt["fraction"] < 1 && bt["normal"][2] > 0.75 && i > 1.5 && !self isOnLadder()) + if (bt["fraction"] < 1 && bt["normal"][2] > 0.9 && i > 1.5 && !self isOnLadder()) { i = 0; self thread jump(); @@ -310,7 +313,7 @@ watchHoldBreath() if(self.bot.isfrozen) continue; - self holdbreath(self playerADS() >= 1); + self holdbreath(self playerADS() > 0); } } @@ -1177,7 +1180,7 @@ aim() //c4 logic here, but doesnt work anyway - canADS = (self canAds(dist, curweap) && conedot > 0.65); + canADS = (self canAds(dist, curweap) && conedot > 0.75); if (canADS) self thread pressADS(); @@ -1214,7 +1217,7 @@ aim() if(!self canFire(curweap) || !self isInRange(dist, curweap)) continue; - canADS = (self canAds(dist, curweap) && conedot > 0.65); + canADS = (self canAds(dist, curweap) && conedot > 0.75); if (canADS) self thread pressADS(); @@ -1254,6 +1257,8 @@ aim() */ botFire() { + self.bot.last_fire_time = getTime(); + if(self.bot.is_cur_full_auto) { self thread pressFire(); @@ -1368,6 +1373,8 @@ walk() if(self maps\mp\_flashgrenades::isFlashbanged()) { + self.bot.last_next_wp = -1; + self.bot.last_second_next_wp = -1; self botMoveTo(self.origin + self GetVelocity()*500); continue; } @@ -1480,6 +1487,8 @@ strafe(target) if(traceRight["fraction"] > traceLeft["fraction"]) strafe = traceRight["position"]; + self.bot.last_next_wp = -1; + self.bot.last_second_next_wp = -1; self botMoveTo(strafe); wait 2; self notify("kill_goal"); @@ -1591,39 +1600,34 @@ doWalk(goal, dist, isScriptGoal) self thread watchOnGoal(goal, distsq); current = self initAStar(goal); - // if a waypoint is closer than the goal - //if (current >= 0 && DistanceSquared(self.origin, level.waypoints[self.bot.astar[current]].origin) < DistanceSquared(self.origin, goal)) - //{ - while(current >= 0) + // skip waypoints we already completed to prevent rubber banding + if (current > 0 && self.bot.astar[current] == self.bot.last_next_wp && self.bot.astar[current-1] == self.bot.last_second_next_wp) + current = self removeAStar(); + + if (current >= 0) + { + // check if a waypoint is closer than the goal + wpOrg = level.waypoints[self.bot.astar[current]].origin; + ppt = PlayerPhysicsTrace(self.origin + (0,0,32), wpOrg, false, self); + if (DistanceSquared(self.origin, wpOrg) < DistanceSquared(self.origin, goal) || DistanceSquared(wpOrg, ppt) > 1.0) { - // skip down the line of waypoints and go to the waypoint we have a direct path too - /*for (;;) + while(current >= 0) { - if (current <= 0) - break; - - ppt = PlayerPhysicsTrace(self.origin + (0,0,32), level.waypoints[self.bot.astar[current-1]].origin, false, self); - if (DistanceSquared(level.waypoints[self.bot.astar[current-1]].origin, ppt) > 1.0) - break; - - if (level.waypoints[self.bot.astar[current-1]].type == "climb" || level.waypoints[self.bot.astar[current]].type == "climb") - break; - + self.bot.next_wp = self.bot.astar[current]; + self.bot.second_next_wp = -1; + if(current > 0) + self.bot.second_next_wp = self.bot.astar[current-1]; + + self notify("new_static_waypoint"); + + self movetowards(level.waypoints[self.bot.next_wp].origin); + self.bot.last_next_wp = self.bot.next_wp; + self.bot.last_second_next_wp = self.bot.second_next_wp; + current = self removeAStar(); - }*/ - - self.bot.next_wp = self.bot.astar[current]; - self.bot.second_next_wp = -1; - if(current != 0) - self.bot.second_next_wp = self.bot.astar[current-1]; - - self notify("new_static_waypoint"); - - self movetowards(level.waypoints[self.bot.next_wp].origin); - - current = self removeAStar(); + } } - //} + } self.bot.next_wp = -1; self.bot.second_next_wp = -1; @@ -1631,6 +1635,8 @@ doWalk(goal, dist, isScriptGoal) if(DistanceSquared(self.origin, goal) > distsq) { + self.bot.last_next_wp = -1; + self.bot.last_second_next_wp = -1; self movetowards(goal); // any better way?? }