Aim crop farmers at targets with pitch limit
This commit is contained in:
+41
-22
@@ -2,37 +2,56 @@ import unittest
|
||||
|
||||
from munch import Munch
|
||||
|
||||
from mosfet.bot import FARMING_PITCH, pitch_lock_for_job, update_pitch
|
||||
from mosfet.bot import look_direction_from_eye, update_pitch
|
||||
from mosfet.vector import Point3D
|
||||
|
||||
|
||||
class LookDirection:
|
||||
def __init__(self, angle):
|
||||
self.angle = angle
|
||||
|
||||
def length(self):
|
||||
return 2.0
|
||||
|
||||
def normalized(self):
|
||||
return self
|
||||
|
||||
def angleDeg(self, _direction):
|
||||
return self.angle
|
||||
|
||||
|
||||
class TestFarmingPitch(unittest.TestCase):
|
||||
def test_crop_and_wart_farming_lock_pitch(self):
|
||||
def farm_crop():
|
||||
pass
|
||||
def test_aiming_at_a_same_level_crop_uses_eye_height_and_looks_down(self):
|
||||
player = Point3D((0.5, 64.0, 0.5))
|
||||
crop_center = Point3D((1.5, 64.5, 1.5))
|
||||
direction = look_direction_from_eye(player, crop_center)
|
||||
|
||||
def farm_wart():
|
||||
pass
|
||||
|
||||
def sleep():
|
||||
pass
|
||||
|
||||
self.assertEqual(
|
||||
pitch_lock_for_job(Munch(state=farm_crop)), FARMING_PITCH)
|
||||
self.assertEqual(
|
||||
pitch_lock_for_job(Munch(state=farm_wart)), FARMING_PITCH)
|
||||
self.assertIsNone(pitch_lock_for_job(Munch(state=sleep)))
|
||||
self.assertIsNone(pitch_lock_for_job(None))
|
||||
|
||||
def test_pitch_is_held_at_45_despite_look_target_changes(self):
|
||||
self.assertGreater(direction.y, 0)
|
||||
state = Munch(pitch=0.0)
|
||||
for _ in range(5):
|
||||
update_pitch(state, object(), FARMING_PITCH)
|
||||
update_pitch(state, direction)
|
||||
self.assertGreater(state.pitch, 0.0)
|
||||
|
||||
def test_pitch_never_looks_more_than_45_degrees_down(self):
|
||||
state = Munch(pitch=0.0)
|
||||
directly_below = LookDirection(0.0)
|
||||
for _ in range(8):
|
||||
update_pitch(state, directly_below)
|
||||
self.assertEqual(state.pitch, 45.0)
|
||||
|
||||
# Without the farming lock, ordinary look behavior is restored.
|
||||
update_pitch(state, None)
|
||||
def test_pitch_tracks_look_target_instead_of_a_fixed_farming_angle(self):
|
||||
state = Munch(pitch=0.0)
|
||||
direction_to_crop = LookDirection(45.0)
|
||||
for _ in range(5):
|
||||
update_pitch(state, direction_to_crop)
|
||||
self.assertEqual(state.pitch, 45.0)
|
||||
|
||||
# Looking level at another target pulls the pitch back toward zero.
|
||||
update_pitch(state, LookDirection(90.0))
|
||||
self.assertEqual(state.pitch, 35.0)
|
||||
|
||||
update_pitch(state, None)
|
||||
self.assertEqual(state.pitch, 25.0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user