Ejemplo n.º 1
0
    def Execute(self):
        if self.target_id != None:
            self.ai.enemy_id = self.target_id

            # default turning & throttle off
            self.ai.Throttle(0)
            self.ai.Turn(0)

            # other info
            heading = self.ai.GetHeadingToID(self.target_id, False)
            target_loc = plus.getLocation(self.target_id)
            clear_path = self.ai.IsStraightPathClear(self.ai.GetLocation(),
                                                     target_loc)
            distance = (vector3(target_loc) -
                        vector3(self.ai.GetLocation())).length()
            speed = self.ai.GetSpeed()

            # adjust sight range based on speed so we have time to react to obstacles
            self.sight_range = self.sight_range_base + (0.2 * abs(speed))

            # keep track of points in front of and behind us for obstacle detection
            fx = (self.sight_range * math.sin(
                self.ai.GetHeading(False))) + self.ai.GetLocation()[0]
            fz = (self.sight_range * math.cos(
                self.ai.GetHeading(False))) + self.ai.GetLocation()[2]
            rx = (-1 * self.sight_range * math.sin(
                self.ai.GetHeading(False))) + self.ai.GetLocation()[0]
            rz = (-1 * self.sight_range * math.cos(
                self.ai.GetHeading(False))) + self.ai.GetLocation()[2]
            fry = self.ai.GetLocation()[1]
            forloc = (fx, fry, fz)
            rearloc = (rx, fry, rz)

            # markers for detection points
            #plus.emitSmoke(30, (forloc), (0, 2, 0), (3, 3, 3))
            #plus.emitSmoke(30, (rearloc), (0, 2, 0), (3, 3, 3))

            # are there obstacles in front of us or behind us
            forclear = self.ai.IsStraightPathClear(self.ai.GetLocation(),
                                                   forloc)
            rearclear = self.ai.IsStraightPathClear(self.ai.GetLocation(),
                                                    rearloc)

            #self.tauntbox.get("taunt1").setText("fc:" + str(forclear) + " rc:" + str(rearclear) + " reorient:" + str(self.reorient) + " BUtimer:" + str(self.backuptimer))

            # if we're close to the enemy and not moving fast, try to get away for another ram
            if (distance < self.sight_range_base
                    and speed > -self.threshold_speed and
                    self.backuptimer < self.backuptime) or self.reorient == 1:
                # if the enemy is on our flank, turn to face them a bit better
                if (math.pi / 3) < abs(heading) < (2 * math.pi / 3):
                    self.ai.AimToHeading(heading)
                # if we're facing the enemy and there's nothing behind us, back up as far as possible
                if abs(heading) <= (math.pi / 3):
                    if rearclear:
                        self.reorient = 1
                        self.ai.Turn(0)
                        self.ai.Throttle(100)
                    else:
                        self.reorient = 0
                        # if we can't get away, push back
                        if abs(heading) < (math.pi - 0.25):
                            self.ai.AimToHeading(heading)
                        else:
                            self.ai.Throttle(100)
                # if we're facing away from the enemy and there's nothing in front of us, drive forward to get away
                if abs(heading) >= (2 * math.pi / 3):
                    if forclear:
                        self.reorient = 1
                        self.ai.Turn(0)
                        self.ai.Throttle(-100)
                    else:
                        self.reorient = 0
                        # if we can't get away, try to turn around and push back
                        if abs(heading) < (math.pi - 0.25):
                            self.ai.AimToHeading(heading)
                        else:
                            self.ai.Throttle(100)
                # optional timer for bots that go crazy after too long in reverse
                if self.reorient == 1:
                    self.backuptimer += 1
                if self.backuptimer >= self.backuptime:
                    self.reorient = 0
                # 2 times our base sight range is far enough away
                if distance >= (self.sight_range_base * 2):
                    self.backuptimer = 0
                    self.reorient = 0
            elif (distance < self.sight_range_base
                  and speed > -self.threshold_speed
                  and self.backuptimer >= self.backuptime):
                if abs(heading) < (math.pi - 0.25):
                    self.ai.AimToHeading(heading)
                else:
                    self.ai.Throttle(100)
                # reset backuptimer when we hit the enemy
                if plus.getTimeElapsed() - self.ai.GetLastDamageDone(
                )[2] <= 0.5:
                    self.backuptimer = 0
            elif not clear_path:
                # if we don't have a clear shot, get closer
                self.ai.DriveToLocation(plus.getLocation(self.target_id))
            else:
                # Ram the opponent
                if self.nosecone > 0:
                    if abs(heading) < math.pi - math.tan(
                            self.nosecone / distance):
                        self.ai.AimToHeading(heading)
                    else:
                        self.ai.Throttle(100)
                # stop charging if we're near the edge!
                if plus.getGameType() == "TABLETOP":
                    a = Arenas.currentArena
                    loc = vector3(self.ai.GetLocation())

                    # check to see if we're already over
                    dist, over, h = a.DistanceToEdge(loc.asTuple())
                    if over: return False

                    # now check to see if we're heading over
                    angle = self.ai.GetHeading(False)
                    dir = vector3(math.sin(angle), 0, math.cos(angle))
                    speed = self.ai.GetSpeed()

                    look_ahead = .5

                    loc += dir * speed * look_ahead

                    dist, over, h = a.DistanceToEdge(loc.asTuple())
                    if over: return False

                # drive as fast as we can toward the target
                if abs(heading) < (math.pi - 0.25):
                    self.ai.AimToHeading(heading)
                else:
                    self.ai.Throttle(100)
            return True
        else:
            return False
Ejemplo n.º 2
0
 def Activate(self, on):
     if on:
         self.king_of_hill = (plus.getGameType() == "KING OF THE HILL")
     
     Arenas.SuperArena.Activate(self, on)
Ejemplo n.º 3
0
    def Execute(self):
        if self.target_id != None:
            self.ai.enemy_id = self.target_id

            # default turning & throttle off
            self.ai.Throttle(0)
            self.ai.Turn(0)

            heading = self.ai.GetHeadingToID(self.target_id, False)
            target_loc = plus.getLocation(self.target_id)
            clear_path = self.ai.IsStraightPathClear(self.ai.GetLocation(),
                                                     target_loc)

            distance = (vector3(target_loc) -
                        vector3(self.ai.GetLocation())).length()
            speed = self.ai.GetSpeed()

            # if we're close but not moving very fast, pick a new location and back toward it
            if (distance < 3 and speed < 2.0) or (distance < 5 and speed < 0):
                if self.regroupPos == None or self.regroupTime <= 0:
                    self.regroupPos = None
                    # pick a point near us that has a clear shot at the target?
                    for r in (0, 1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6):
                        angle = self.ai.GetHeading(True) + r * (math.pi / 6)
                        new_dir = vector3(math.sin(angle), 0, math.cos(angle))
                        dest = vector3(target_loc) + new_dir * 5

                        clear_path = self.ai.IsStraightPathClear(
                            dest.asTuple(), target_loc)
                        if clear_path:
                            self.regroupPos = dest.asTuple()
                            self.regroupDir = (abs(r) <= 3)
                            self.regroupTime = 16
                            break

                # sanity check: if we can't find a valid position, drive forward or backward
                if self.regroupPos == None:
                    self.regroupDir = not self.regroupDir
                    range = 5
                    if self.regroupDir: range = -5
                    self.regroupPos = (
                        vector3(self.ai.GetLocation()) +
                        vector3(self.ai.GetDirection()) * range).asTuple()
                    self.regroupTime = 16

                self.ai.DriveToLocation(self.regroupPos, self.regroupDir)
                self.regroupTime -= 1
            elif distance > 3 and abs(heading) > .35 or not clear_path:
                # if we don't have a clear shot, get closer
                self.ai.DriveToLocation(plus.getLocation(self.target_id))
            else:
                # stop charging if we're near the edge!
                if plus.getGameType() == "TABLETOP":
                    a = Arenas.currentArena
                    loc = vector3(self.ai.GetLocation())

                    # check to see if we're already over
                    dist, over, h = a.DistanceToEdge(loc.asTuple())
                    if over: return False

                    # now check to see if we're heading over
                    angle = self.ai.GetHeading(False)
                    dir = vector3(math.sin(angle), 0, math.cos(angle))
                    speed = self.ai.GetSpeed()

                    look_ahead = .5

                    loc += dir * speed * look_ahead

                    dist, over, h = a.DistanceToEdge(loc.asTuple())
                    if over: return False

                # drive as fast as we can toward the target
                self.ai.AimToHeading(heading)
                self.ai.Throttle(100)
                self.regroupPos = None

            return True
        else:
            return False
Ejemplo n.º 4
0
    def __init__(self, **args):
        import Tactics

        plus.AI.__init__(self)
        self.bActivated = False

        self.countdownToEvaluation = 0
        self.tactics = []
        self.lastTactic = None
        self.enemy_id = None

        self.zone = None
        self.sensors = {}  # used to track SmartZones
        self.weapons = []  # used to track our weapons
        self.sweapons = []  # used to track our secondary weapons
        self.timeOfLastGoodHit = 0

        self.tickCounter = 0

        self.debug = None

        self.bImmobile = False
        self.immobile_list = {}
        self.bInvertible = False
        self.bCarSteering = False

        # customize these for each robot
        self.top_speed = 4.0
        self.max_throttle = 100
        self.max_turn_speed = 2.5
        self.max_turn = 60
        self.fRadius = 1.0
        self.botName = Botname

        self.boost_throttle = self.max_throttle
        self.boost_turn = self.max_turn

        self.last_throttle = self.set_throttle = 0
        self.last_turn_throttle = self.set_turn_throttle = 0

        # DEFAULT TACTICS: Appended to include Race for game type Obstacle Course

        self.tactics.append(Tactics.Invert(self, self.InvertHandler()))
        self.tactics.append(Tactics.Unstuck(self, self.StuckHandler()))

        if plus.getGameType() == "TABLETOP":
            self.tactics.append(Tactics.AvoidEdges(self))
            self.tactics.append(Tactics.PushOffEdge(self))
        elif plus.getGameType() == "KING OF THE HILL":
            self.tactics.append(Tactics.Dethrone(self))
            self.tactics.append(Tactics.Reign(self))
        elif plus.getGameType() == "OBSTACLE COURSE":
            self.tactics.append(Tactics.Race(self))

        if 'nose' in args: self.fNoseOffset = args['nose']
        if 'topspeed' in args: self.top_speed = args['topspeed']
        if 'throttle' in args: self.max_throttle = args['throttle']
        if 'turnspeed' in args: self.max_turn_speed = args['turnspeed']
        if 'turn' in args: self.max_turn = args['turn']
        if 'invertible' in args: self.bInvertible = args['invertible']
        if 'car' in args: self.bCarSteering = args['car']
        if 'weapons' in args: self.weapons = list(args['weapons'])
        if 'radius' in args: self.fRadius = args['radius']
        if 'sweapons' in args: self.sweapons = list(args['sweapons'])