Allow hunting and building as initial villager tasks

This commit is contained in:
Nate Bowman
2026-11-15 16:29:13 -05:00
parent e4aaba0320
commit 8a8effe3d1
3 changed files with 134 additions and 41 deletions

View File

@@ -34,78 +34,99 @@ class Gameplay():
self.actions[action_time].append((self.world.build,
(building,
villagers_from,
villagers_to,)))
villagers_to,),
{}))
def market_buy(self, action_time, resource, amount):
self._check_time(action_time)
self.actions[action_time].append((self.world.market_buy,
(resource, amount)))
(resource, amount),
{}))
def market_sell(self, action_time, resource, amount):
self._check_time(action_time)
self.actions[action_time].append((self.world.market_sell,
(resource, amount)))
(resource, amount),
{}))
def queue_research(self, action_time, research):
self._check_time(action_time)
self.actions[action_time].append((self.world.queue_research,
(research,)))
(research,),
{}))
def queue_villagers_over_time(self, from_time, until_time, initial_task):
def queue_villagers_over_time(self,
from_time,
until_time,
initial_task,
**kwargs):
train_time = self.world.build_times.build_times[Units.VILLAGER]
duration = max(0, until_time - from_time)
for i in range(duration//train_time + 1):
self.queue_villager(from_time + i*train_time, initial_task)
self.queue_villager(from_time + i*train_time,
initial_task,
**kwargs)
def queue_villager(self, action_time, initial_task):
def queue_villager(self, action_time, initial_task, **kwargs):
self._check_time(action_time)
self.actions[action_time].append((self.world.queue_villager,
(initial_task,)))
(initial_task,),
kwargs))
def queue_fishing_ship(self, action_time, initial_task=Tasks.FISH_SHIP_DEEP):
self._check_time(action_time)
self.actions[action_time].append((self.world.queue_fishing_ship,
(initial_task,)))
(initial_task,),
{}))
def queue_trade_cog(self, action_time):
self._check_time(action_time)
self.actions[action_time].append((self.world.queue_trade_cog, ()))
self.actions[action_time].append((self.world.queue_trade_cog,
(),
{}))
def queue_trade_cart(self, action_time):
self._check_time(action_time)
self.actions[action_time].append((self.world.queue_trade_cart, ()))
self.actions[action_time].append((self.world.queue_trade_cart,
(),
{}))
def queue_unit(self, action_time, unit):
self._check_time(action_time)
self.actions[action_time].append((self.world.queue_unit, (unit,)))
self.actions[action_time].append((self.world.queue_unit,
(unit,),
{}))
def assign_villager(self, action_time, old_task, new_task, count=1):
self._check_time(action_time)
self.actions[action_time].append((self.world.assign_villager,
(old_task, new_task, count,)))
(old_task, new_task, count,),
{}))
def get_relic(self, action_time, walking_time=60):
self._check_time(action_time)
self.actions[action_time].append((self.world.get_relic,
(walking_time,)))
(walking_time,),
{}))
def set_housed_is_error(self, action_time, is_error=True):
self._check_time(action_time)
self.actions[action_time].append((self.world.set_housed_is_error,
(is_error,)))
(is_error,),
{}))
def lure_huntable_with_villager(self,
@@ -114,12 +135,15 @@ class Gameplay():
walking_time=30):
self._check_time(action_time)
self.actions[action_time].append((self.world.lure_huntable_with_villager,
(previous_task, walking_time)))
(previous_task, walking_time),
{}))
def increase_age(self, action_time):
self._check_time(action_time)
self.actions[action_time].append((self.world.increase_age, ()))
self.actions[action_time].append((self.world.increase_age,
(),
{}))
def _check_time(self, action_time):
@@ -150,12 +174,12 @@ class Gameplay():
def _handle_actions(self):
for func, args in self.actions[self.world.current_time]:
for func, args, kwargs in self.actions[self.world.current_time]:
try:
func(*args)
func(*args, **kwargs)
except Exception as e:
raise type(e)(
f'Error in {func.__name__}{args}'
f'Error in {func.__name__}{args}{kwargs}'
f' at time {self.world.current_time}.') from e
del self.actions[self.world.current_time]