From 0d40fe5dc09842dce3dd33a4827985b75118aa30 Mon Sep 17 00:00:00 2001 From: Nate Bowman Date: Thu, 5 Nov 2026 21:37:17 -0500 Subject: [PATCH] Add decay for huntables --- aoe/gather.py | 22 ++++++++++++++++------ tests/test.py | 10 ++++++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/aoe/gather.py b/aoe/gather.py index 3fa5888..48e38e8 100644 --- a/aoe/gather.py +++ b/aoe/gather.py @@ -186,6 +186,7 @@ class Gather(): def compute_next_gather_rate_decrease(self, task, villagers): rate = self.gather_rates[task] + decay = self.decay_rates[task] if task == Tasks.FARM: available = self.farms[0] @@ -193,14 +194,12 @@ class Gather(): else: available = self.gatherable_amounts[task] - try: - next_decrease = available/(villagers*rate) + if rate == 0 or (villagers == 0 and decay == 0): + next_decrease = None + else: + next_decrease = available/(villagers*rate + decay) # rounding error will give 1 extra second of gathering next_decrease = math.ceil(next_decrease) - except ZeroDivisionError: - # either villagers or rate was 0, so no next decrease should - # be scheduled - next_decrease = None return next_decrease @@ -300,6 +299,11 @@ class Gather(): amount_gathered = count*rate*mult*duration self.resources[resource] += amount_gathered + for task in self.decay_rates.keys(): + self.gatherable_amounts[task] -= self.decay_rates[task]*duration + if self.gatherable_amounts[task] < 0: + self.gatherable_amounts[task] = 0 + def __init__(self): self.resources = [200, 200, 100, 200] @@ -329,6 +333,12 @@ class Gather(): self.original_gather_rates = copy.deepcopy(self.gather_rates) + self.decay_rates = defaultdict(int, { + Tasks.SHEEP: 0.25, + Tasks.BOAR: 0.4, + Tasks.HUNT: 0.25, + }) + self.gathered_resources = { Tasks.BERRIES: {Resources.FOOD: 1}, Tasks.SHEEP: {Resources.FOOD: 1}, diff --git a/tests/test.py b/tests/test.py index ae04686..349aa89 100644 --- a/tests/test.py +++ b/tests/test.py @@ -212,7 +212,7 @@ class TestWorld(unittest.TestCase): self.assertResourcesMatch([200 + gathered, 200, 100, 200], game.world) - def test_gather_boar_limited_no_decay(self): + def test_gather_boar_limited(self): walking = 20 game = Gameplay() @@ -221,8 +221,13 @@ class TestWorld(unittest.TestCase): game.play_until(1000) boar_total = 340 + boar_per_60 = 24.6 + boar_decay_per_60 = 0.4*60 + boar_gone_time = boar_total/(boar_decay_per_60 + boar_per_60*3) - self.assertResourcesMatch([200 + boar_total, 200, 100, 200], game.world) + boar_eaten = boar_gone_time*boar_per_60*3 + + self.assertResourcesMatch([200 + boar_eaten, 200, 100, 200], game.world) def test_age_increase(self): @@ -232,6 +237,7 @@ class TestWorld(unittest.TestCase): game.lure_huntable_with_villager(0, Tasks.IDLE, walking) game.build(0, Buildings.MILL, Tasks.IDLE, Tasks.BOAR) game.build(0, Buildings.LUMBERCAMP, Tasks.IDLE, Tasks.BOAR) + game.lure_huntable_with_villager(walking, Tasks.BOAR, walking) game.increase_age(300) game.play_until(400) self.assertEqual(Ages.DARK, game.world.age)