Add decay for huntables

This commit is contained in:
Nate Bowman
2026-11-05 21:37:17 -05:00
parent 85e441927b
commit 0d40fe5dc0
2 changed files with 24 additions and 8 deletions

View File

@@ -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},

View File

@@ -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)