Add decay for huntables
This commit is contained in:
@@ -186,6 +186,7 @@ class Gather():
|
|||||||
|
|
||||||
def compute_next_gather_rate_decrease(self, task, villagers):
|
def compute_next_gather_rate_decrease(self, task, villagers):
|
||||||
rate = self.gather_rates[task]
|
rate = self.gather_rates[task]
|
||||||
|
decay = self.decay_rates[task]
|
||||||
|
|
||||||
if task == Tasks.FARM:
|
if task == Tasks.FARM:
|
||||||
available = self.farms[0]
|
available = self.farms[0]
|
||||||
@@ -193,14 +194,12 @@ class Gather():
|
|||||||
else:
|
else:
|
||||||
available = self.gatherable_amounts[task]
|
available = self.gatherable_amounts[task]
|
||||||
|
|
||||||
try:
|
if rate == 0 or (villagers == 0 and decay == 0):
|
||||||
next_decrease = available/(villagers*rate)
|
next_decrease = None
|
||||||
|
else:
|
||||||
|
next_decrease = available/(villagers*rate + decay)
|
||||||
# rounding error will give 1 extra second of gathering
|
# rounding error will give 1 extra second of gathering
|
||||||
next_decrease = math.ceil(next_decrease)
|
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
|
return next_decrease
|
||||||
|
|
||||||
@@ -300,6 +299,11 @@ class Gather():
|
|||||||
amount_gathered = count*rate*mult*duration
|
amount_gathered = count*rate*mult*duration
|
||||||
self.resources[resource] += amount_gathered
|
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):
|
def __init__(self):
|
||||||
self.resources = [200, 200, 100, 200]
|
self.resources = [200, 200, 100, 200]
|
||||||
@@ -329,6 +333,12 @@ class Gather():
|
|||||||
|
|
||||||
self.original_gather_rates = copy.deepcopy(self.gather_rates)
|
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 = {
|
self.gathered_resources = {
|
||||||
Tasks.BERRIES: {Resources.FOOD: 1},
|
Tasks.BERRIES: {Resources.FOOD: 1},
|
||||||
Tasks.SHEEP: {Resources.FOOD: 1},
|
Tasks.SHEEP: {Resources.FOOD: 1},
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ class TestWorld(unittest.TestCase):
|
|||||||
self.assertResourcesMatch([200 + gathered, 200, 100, 200], game.world)
|
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
|
walking = 20
|
||||||
|
|
||||||
game = Gameplay()
|
game = Gameplay()
|
||||||
@@ -221,8 +221,13 @@ class TestWorld(unittest.TestCase):
|
|||||||
game.play_until(1000)
|
game.play_until(1000)
|
||||||
|
|
||||||
boar_total = 340
|
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):
|
def test_age_increase(self):
|
||||||
@@ -232,6 +237,7 @@ class TestWorld(unittest.TestCase):
|
|||||||
game.lure_huntable_with_villager(0, Tasks.IDLE, walking)
|
game.lure_huntable_with_villager(0, Tasks.IDLE, walking)
|
||||||
game.build(0, Buildings.MILL, Tasks.IDLE, Tasks.BOAR)
|
game.build(0, Buildings.MILL, Tasks.IDLE, Tasks.BOAR)
|
||||||
game.build(0, Buildings.LUMBERCAMP, 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.increase_age(300)
|
||||||
game.play_until(400)
|
game.play_until(400)
|
||||||
self.assertEqual(Ages.DARK, game.world.age)
|
self.assertEqual(Ages.DARK, game.world.age)
|
||||||
|
|||||||
Reference in New Issue
Block a user