Merge pull request #19 from Dmitry450/master

Added self.target_flag.node.exists() check in spazBot.update_ai()
This commit is contained in:
Eric Froemling 2020-04-13 12:15:29 -07:00 committed by GitHub
commit 996b33809e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -253,31 +253,32 @@ class SpazBot(basespaz.Spaz):
# Otherwise try to go pick it up. # Otherwise try to go pick it up.
else: else:
assert self.target_flag.node assert self.target_flag.node
target_pt_raw = ba.Vec3(*self.target_flag.node.position) if self.target_flag.node.exists():
diff = (target_pt_raw - our_pos) target_pt_raw = ba.Vec3(*self.target_flag.node.position)
diff = ba.Vec3(diff[0], 0, diff[2]) # Don't care about y. diff = (target_pt_raw - our_pos)
dist = diff.length() diff = ba.Vec3(diff[0], 0, diff[2]) # Don't care about y.
to_target = diff.normalized() dist = diff.length()
to_target = diff.normalized()
# If we're holding some non-flag item, drop it. # If we're holding some non-flag item, drop it.
if self.node.hold_node: if self.node.hold_node:
self.node.pickup_pressed = True self.node.pickup_pressed = True
self.node.pickup_pressed = False self.node.pickup_pressed = False
return return
# If we're a runner, run only when not super-near the flag. # If we're a runner, run only when not super-near the flag.
if self.run and dist > 3.0: if self.run and dist > 3.0:
self._running = True self._running = True
self.node.run = 1.0 self.node.run = 1.0
else: else:
self._running = False self._running = False
self.node.run = 0.0 self.node.run = 0.0
self.node.move_left_right = to_target.x self.node.move_left_right = to_target.x
self.node.move_up_down = -to_target.z self.node.move_up_down = -to_target.z
if dist < 1.25: if dist < 1.25:
self.node.pickup_pressed = True self.node.pickup_pressed = True
self.node.pickup_pressed = False self.node.pickup_pressed = False
return return
# Not a flag-bearer. If we're holding anything but a bomb, drop it. # Not a flag-bearer. If we're holding anything but a bomb, drop it.