Add fish traps
Also likely fixes bugs in farming and fishing, which were not tested before
This commit is contained in:
230
tests/test.py
230
tests/test.py
@@ -455,3 +455,233 @@ class TestWorld(unittest.TestCase):
|
||||
with self.assertRaises(InvalidMarketAmountException):
|
||||
game.market_sell(0, Resources.FOOD, 50)
|
||||
game.play_until(1)
|
||||
|
||||
|
||||
def test_farm_simple(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.DARK
|
||||
game.world.gather.resources = [500, 500, 500, 500]
|
||||
game.world._add_building(Buildings.MILL, {}, {})
|
||||
game.world._add_building(Buildings.FARM, {}, {})
|
||||
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.FARM)
|
||||
|
||||
rate_per_60 = 20
|
||||
|
||||
game.play_until(60)
|
||||
|
||||
new_food = 500 + rate_per_60
|
||||
|
||||
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
||||
|
||||
|
||||
def test_farm_build(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.DARK
|
||||
game.world.gather.resources = [500, 500, 500, 500]
|
||||
game.world._add_building(Buildings.MILL, {}, {})
|
||||
|
||||
game.build(0, Buildings.FARM, Tasks.IDLE, Tasks.IDLE)
|
||||
game.assign_villager(30, Tasks.IDLE, Tasks.FARM)
|
||||
|
||||
rate_per_60 = 20
|
||||
|
||||
game.play_until(90)
|
||||
|
||||
new_food = 500 + rate_per_60
|
||||
|
||||
self.assertResourcesMatch([new_food, 440, 500, 500], game.world)
|
||||
|
||||
|
||||
def test_farm_depleted(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.DARK
|
||||
game.world.gather.resources = [500, 500, 500, 500]
|
||||
game.world._add_building(Buildings.MILL, {}, {})
|
||||
game.world._add_building(Buildings.FARM, {}, {})
|
||||
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.FARM)
|
||||
|
||||
amount_per_farm = 175
|
||||
|
||||
game.play_until(1000)
|
||||
|
||||
new_food = 500 + amount_per_farm
|
||||
|
||||
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
||||
self.assertEqual(0, len(game.world.gather.farms))
|
||||
self.assertEqual(0, len(game.world.gather.unused_farms))
|
||||
|
||||
|
||||
def test_farm_too_many_farmers(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.DARK
|
||||
game.world.gather.resources = [500, 500, 500, 500]
|
||||
game.world._add_building(Buildings.MILL, {}, {})
|
||||
game.world._add_building(Buildings.FARM, {}, {})
|
||||
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.FARM)
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.FARM)
|
||||
|
||||
with self.assertRaises(GatherBuildingNotAvailableException):
|
||||
game.play_until(1)
|
||||
|
||||
|
||||
def test_farm_off_and_on(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.DARK
|
||||
game.world.gather.resources = [500, 500, 500, 500]
|
||||
game.world._add_building(Buildings.MILL, {}, {})
|
||||
game.world._add_building(Buildings.FARM, {}, {})
|
||||
|
||||
game.assign_villager(0, Tasks.IDLE, Tasks.FARM)
|
||||
game.assign_villager(30, Tasks.FARM, Tasks.IDLE)
|
||||
game.assign_villager(60, Tasks.IDLE, Tasks.FARM)
|
||||
|
||||
rate_per_60 = 20
|
||||
|
||||
game.play_until(90)
|
||||
|
||||
new_food = 500 + rate_per_60
|
||||
|
||||
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
||||
|
||||
|
||||
def test_fishing_ship(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.DARK
|
||||
game.world.gather.resources = [500, 500, 500, 500]
|
||||
game.world._add_building(Buildings.DOCK, {}, {})
|
||||
|
||||
game.queue_fishing_ship(0)
|
||||
|
||||
rate_per_60 = 29.4
|
||||
ship_training = 40
|
||||
|
||||
game.play_until(ship_training - 1)
|
||||
self.assertResourcesMatch([500, 425, 500, 500], game.world)
|
||||
|
||||
game.play_until(ship_training + 60)
|
||||
new_food = 500 + rate_per_60
|
||||
|
||||
self.assertResourcesMatch([new_food, 425, 500, 500], game.world)
|
||||
|
||||
|
||||
def test_fishtrap_simple(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.FEUDAL
|
||||
game.world.gather.resources = [500, 500, 500, 500]
|
||||
game.world._add_building(Buildings.DOCK, {}, {})
|
||||
game.world._add_building(Buildings.FISHTRAP, {}, {})
|
||||
game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_TRAP)
|
||||
|
||||
rate_per_60 = 21
|
||||
|
||||
game.play_until(60)
|
||||
|
||||
new_food = 500 + rate_per_60
|
||||
|
||||
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
||||
|
||||
|
||||
def test_fishtrap_build(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.FEUDAL
|
||||
game.world.gather.resources = [500, 500, 500, 500]
|
||||
game.world._add_building(Buildings.DOCK, {}, {})
|
||||
game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE)
|
||||
|
||||
game.build(0,
|
||||
Buildings.FISHTRAP,
|
||||
Tasks.FISH_SHIP_IDLE,
|
||||
Tasks.FISH_SHIP_IDLE)
|
||||
|
||||
game.play_until(10)
|
||||
|
||||
game.assign_villager(50, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP)
|
||||
|
||||
rate_per_60 = 21
|
||||
|
||||
game.play_until(110)
|
||||
|
||||
new_food = 500 + rate_per_60
|
||||
|
||||
self.assertResourcesMatch([new_food, 400, 500, 500], game.world)
|
||||
|
||||
|
||||
def test_fishtrap_depleted(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.FEUDAL
|
||||
game.world.gather.resources = [500, 500, 500, 500]
|
||||
game.world._add_building(Buildings.DOCK, {}, {})
|
||||
game.world._add_building(Buildings.FISHTRAP, {}, {})
|
||||
game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE)
|
||||
|
||||
game.assign_villager(0, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP)
|
||||
|
||||
amount_per_fishtrap = 715
|
||||
rate_per_60 = 21
|
||||
duration = (amount_per_fishtrap/rate_per_60)*60 + 1
|
||||
|
||||
game.play_until(duration)
|
||||
|
||||
new_food = 500 + amount_per_fishtrap
|
||||
|
||||
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
||||
self.assertEqual(0, len(game.world.gather.fishtraps))
|
||||
self.assertEqual(0, len(game.world.gather.unused_fishtraps))
|
||||
|
||||
# fishing ships go back to fishing after trap is depleted
|
||||
deep_rate_per_60 = 29.4
|
||||
game.play_until(duration + 60)
|
||||
new_food += deep_rate_per_60
|
||||
|
||||
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
||||
|
||||
|
||||
def test_fishtrap_too_many_fish_ships(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.FEUDAL
|
||||
game.world.gather.resources = [500, 500, 500, 500]
|
||||
game.world._add_building(Buildings.DOCK, {}, {})
|
||||
game.world._add_building(Buildings.FISHTRAP, {}, {})
|
||||
game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE)
|
||||
game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE)
|
||||
|
||||
game.assign_villager(0, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP)
|
||||
game.assign_villager(0, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP)
|
||||
|
||||
with self.assertRaises(GatherBuildingNotAvailableException):
|
||||
game.play_until(1)
|
||||
|
||||
|
||||
def test_fishtrap_off_and_on(self):
|
||||
game = Gameplay()
|
||||
|
||||
game.world.age = Ages.FEUDAL
|
||||
game.world.gather.resources = [500, 500, 500, 500]
|
||||
game.world._add_building(Buildings.DOCK, {}, {})
|
||||
game.world._add_building(Buildings.FISHTRAP, {}, {})
|
||||
game.world._add_thing(Units.FISHINGSHIP, Tasks.FISH_SHIP_IDLE)
|
||||
|
||||
game.assign_villager(0, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP)
|
||||
game.assign_villager(30, Tasks.FISH_SHIP_TRAP, Tasks.FISH_SHIP_IDLE)
|
||||
game.assign_villager(60, Tasks.FISH_SHIP_IDLE, Tasks.FISH_SHIP_TRAP)
|
||||
|
||||
rate_per_60 = 21
|
||||
|
||||
game.play_until(90)
|
||||
|
||||
new_food = 500 + rate_per_60
|
||||
|
||||
self.assertResourcesMatch([new_food, 500, 500, 500], game.world)
|
||||
|
||||
Reference in New Issue
Block a user