Compare commits
6 Commits
0fa68c6e32
...
54050235f0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54050235f0 | ||
|
|
622bdc38fb | ||
|
|
e67085aab7 | ||
|
|
c6550fb007 | ||
|
|
9e45d182b0 | ||
|
|
1f19740355 |
@@ -49,12 +49,31 @@ class Gameplay():
|
|||||||
(initial_task,)))
|
(initial_task,)))
|
||||||
|
|
||||||
|
|
||||||
|
def queue_unit(self, action_time, unit):
|
||||||
|
self._check_time(action_time)
|
||||||
|
self.actions[action_time].append((self.world.queue_unit, (unit,)))
|
||||||
|
|
||||||
|
|
||||||
def assign_villager(self, action_time, old_task, new_task, count=1):
|
def assign_villager(self, action_time, old_task, new_task, count=1):
|
||||||
self._check_time(action_time)
|
self._check_time(action_time)
|
||||||
self.actions[action_time].append((self.world.assign_villager,
|
self.actions[action_time].append((self.world.assign_villager,
|
||||||
(old_task, new_task, count,)))
|
(old_task, new_task, count,)))
|
||||||
|
|
||||||
|
|
||||||
|
def lure_huntable_with_villager(self,
|
||||||
|
action_time,
|
||||||
|
previous_task,
|
||||||
|
walking_time=30):
|
||||||
|
self._check_time(action_time)
|
||||||
|
self.actions[action_time].append((self.world.lure_huntable_with_villager,
|
||||||
|
(previous_task, walking_time)))
|
||||||
|
|
||||||
|
|
||||||
|
def increase_age(self, action_time):
|
||||||
|
self._check_time(action_time)
|
||||||
|
self.actions[action_time].append((self.world.increase_age, ()))
|
||||||
|
|
||||||
|
|
||||||
def _check_time(self, action_time):
|
def _check_time(self, action_time):
|
||||||
# TODO will it work if we do something at current time?
|
# TODO will it work if we do something at current time?
|
||||||
if self.world.current_time > action_time:
|
if self.world.current_time > action_time:
|
||||||
|
|||||||
@@ -141,7 +141,11 @@ class Gather():
|
|||||||
|
|
||||||
|
|
||||||
def check_gather(self, world, task, count=1):
|
def check_gather(self, world, task, count=1):
|
||||||
if task in [Tasks.IDLE, Tasks.BUILD]:
|
if task in [
|
||||||
|
Tasks.IDLE,
|
||||||
|
Tasks.BUILD,
|
||||||
|
Tasks.LURE,
|
||||||
|
]:
|
||||||
return
|
return
|
||||||
|
|
||||||
required = self.required_gather_buildings[task]
|
required = self.required_gather_buildings[task]
|
||||||
@@ -266,10 +270,18 @@ class Gather():
|
|||||||
return len(self.farms)
|
return len(self.farms)
|
||||||
|
|
||||||
|
|
||||||
|
def add_huntable(self):
|
||||||
|
self.improve_gather_rate_by_building(Tasks.LURE, None)
|
||||||
|
|
||||||
|
|
||||||
def gather_resources_for_duration(self, villager_tasks, duration):
|
def gather_resources_for_duration(self, villager_tasks, duration):
|
||||||
# assumes there are sufficient resources in gatherable_amounts
|
# assumes there are sufficient resources in gatherable_amounts
|
||||||
for task, count in villager_tasks.items():
|
for task, count in villager_tasks.items():
|
||||||
if task in [Tasks.BUILD, Tasks.IDLE]:
|
if task in [
|
||||||
|
Tasks.BUILD,
|
||||||
|
Tasks.LURE,
|
||||||
|
Tasks.IDLE,
|
||||||
|
]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
rate = self.gather_rates[task]
|
rate = self.gather_rates[task]
|
||||||
@@ -372,7 +384,7 @@ class Gather():
|
|||||||
# 4 deer
|
# 4 deer
|
||||||
Tasks.BERRIES: 6*125,
|
Tasks.BERRIES: 6*125,
|
||||||
Tasks.SHEEP: 8*100,
|
Tasks.SHEEP: 8*100,
|
||||||
Tasks.BOAR: 2*340,
|
Tasks.BOAR: 0,
|
||||||
Tasks.HUNT: 4*140,
|
Tasks.HUNT: 4*140,
|
||||||
Tasks.FARM: 0,
|
Tasks.FARM: 0,
|
||||||
# TODO next two should be shared
|
# TODO next two should be shared
|
||||||
@@ -401,8 +413,9 @@ class Gather():
|
|||||||
Tasks.GOLD: 4*800,
|
Tasks.GOLD: 4*800,
|
||||||
Tasks.STONE: 4*350,
|
Tasks.STONE: 4*350,
|
||||||
Tasks.BERRIES: 6*125,
|
Tasks.BERRIES: 6*125,
|
||||||
Tasks.HUNT: 4*140}
|
Tasks.HUNT: 4*140},
|
||||||
#Buildings.FISHTRAP: {Tasks.WOOD: 100},
|
#Buildings.FISHTRAP: {Tasks.WOOD: 100},
|
||||||
|
Tasks.LURE: {Tasks.BOAR: 340},
|
||||||
}
|
}
|
||||||
|
|
||||||
self.gather_decrease_rates = {
|
self.gather_decrease_rates = {
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class Tasks(Enum):
|
|||||||
SHEEP = auto()
|
SHEEP = auto()
|
||||||
BOAR = auto()
|
BOAR = auto()
|
||||||
HUNT = auto()
|
HUNT = auto()
|
||||||
|
LURE = auto()
|
||||||
FARM = auto()
|
FARM = auto()
|
||||||
FISH_VILLAGER = auto()
|
FISH_VILLAGER = auto()
|
||||||
FISH_SHIP_SHORE = auto()
|
FISH_SHIP_SHORE = auto()
|
||||||
|
|||||||
34
aoe/world.py
34
aoe/world.py
@@ -65,6 +65,10 @@ class World():
|
|||||||
self.gather.spend_resources(cost)
|
self.gather.spend_resources(cost)
|
||||||
|
|
||||||
|
|
||||||
|
def has_building(self, building):
|
||||||
|
return building in self.buildings
|
||||||
|
|
||||||
|
|
||||||
def _remove_event_at_time(self, removed_event, scheduled_time):
|
def _remove_event_at_time(self, removed_event, scheduled_time):
|
||||||
if not scheduled_time:
|
if not scheduled_time:
|
||||||
return
|
return
|
||||||
@@ -76,7 +80,7 @@ class World():
|
|||||||
|
|
||||||
|
|
||||||
def _schedule_next_gather_rate_decrease(self, task):
|
def _schedule_next_gather_rate_decrease(self, task):
|
||||||
if task in [Tasks.IDLE, Tasks.BUILD]:
|
if task in [Tasks.IDLE, Tasks.BUILD, Tasks.LURE]:
|
||||||
return
|
return
|
||||||
|
|
||||||
# remove old decrease
|
# remove old decrease
|
||||||
@@ -129,6 +133,18 @@ class World():
|
|||||||
self._schedule_next_gather_rate_decrease(task)
|
self._schedule_next_gather_rate_decrease(task)
|
||||||
|
|
||||||
|
|
||||||
|
def lure_huntable_with_villager(self, previous_task, walking_time=30):
|
||||||
|
update_time = self.current_time + walking_time
|
||||||
|
self.events[update_time].append((self._add_huntable, ()))
|
||||||
|
|
||||||
|
self.assign_villager(previous_task, Tasks.LURE)
|
||||||
|
|
||||||
|
|
||||||
|
def _add_huntable(self):
|
||||||
|
self.gather.add_huntable()
|
||||||
|
self.assign_villager(Tasks.LURE, Tasks.BOAR)
|
||||||
|
|
||||||
|
|
||||||
def assign_villager(self, previous_task, new_task, count=1):
|
def assign_villager(self, previous_task, new_task, count=1):
|
||||||
# new_task of None means kill the villager
|
# new_task of None means kill the villager
|
||||||
|
|
||||||
@@ -273,10 +289,10 @@ class World():
|
|||||||
while (self.get_effective_population() < pop_space and
|
while (self.get_effective_population() < pop_space and
|
||||||
i < len(self.production_queue)):
|
i < len(self.production_queue)):
|
||||||
|
|
||||||
thing = self.production_queue[i]
|
thing, task = self.production_queue[i]
|
||||||
if self.housing.check_housing(self, thing) and \
|
if self.housing.check_housing(self, thing) and \
|
||||||
self.production.check_production(self, thing):
|
self.production.check_production(self, thing):
|
||||||
self._start_producing(thing)
|
self._start_producing(thing, task)
|
||||||
del self.production_queue[i]
|
del self.production_queue[i]
|
||||||
else:
|
else:
|
||||||
i += 1
|
i += 1
|
||||||
@@ -298,18 +314,18 @@ class World():
|
|||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(self.production_queue):
|
while i < len(self.production_queue):
|
||||||
thing = self.production_queue[i]
|
thing, task = self.production_queue[i]
|
||||||
if self.production.building[thing] == building and \
|
if self.production.building[thing] == building and \
|
||||||
self.housing.check_housing(self, thing):
|
self.housing.check_housing(self, thing):
|
||||||
self._start_producing(thing)
|
self._start_producing(thing, task)
|
||||||
del self.production_queue[i]
|
del self.production_queue[i]
|
||||||
break
|
break
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
def _use_housing_and_production(self, thing):
|
def _use_housing_and_production(self, thing):
|
||||||
self.housing.check_housing(self, thing)
|
|
||||||
self.production.check_production(self, thing)
|
self.production.check_production(self, thing)
|
||||||
|
self.housing.check_housing(self, thing)
|
||||||
|
|
||||||
building = self.production.building[thing]
|
building = self.production.building[thing]
|
||||||
if building is not None:
|
if building is not None:
|
||||||
@@ -350,7 +366,7 @@ class World():
|
|||||||
try:
|
try:
|
||||||
self._use_housing_and_production(thing)
|
self._use_housing_and_production(thing)
|
||||||
except ProductionBuildingNotAvailableException:
|
except ProductionBuildingNotAvailableException:
|
||||||
self.production_queue.append(thing)
|
self.production_queue.append((thing, initial_task))
|
||||||
else:
|
else:
|
||||||
update_time = self.current_time + self.build_times.build_times[thing]
|
update_time = self.current_time + self.build_times.build_times[thing]
|
||||||
self.events[update_time].append((self._add_thing, (thing, initial_task,)))
|
self.events[update_time].append((self._add_thing, (thing, initial_task,)))
|
||||||
@@ -390,9 +406,9 @@ class World():
|
|||||||
if self.age == Ages.IMPERIAL:
|
if self.age == Ages.IMPERIAL:
|
||||||
raise Exception("no.")
|
raise Exception("no.")
|
||||||
|
|
||||||
new_age = self.age + 1
|
new_age = Ages(self.age + 1)
|
||||||
|
|
||||||
self.dependencies.check_dependencies(new_age)
|
self.dependencies.check_dependencies(self, new_age)
|
||||||
self.pay_cost(new_age)
|
self.pay_cost(new_age)
|
||||||
|
|
||||||
update_time = self.current_time + self.build_times.build_times[new_age]
|
update_time = self.current_time + self.build_times.build_times[new_age]
|
||||||
|
|||||||
69
runner.py
69
runner.py
@@ -1,69 +0,0 @@
|
|||||||
from aoe.exceptions import *
|
|
||||||
from aoe.types import *
|
|
||||||
from aoe.gameplay import *
|
|
||||||
#import ipdb; breakpoint()
|
|
||||||
|
|
||||||
|
|
||||||
# for testing
|
|
||||||
# TODO need to go back through old tasks when new housing is added
|
|
||||||
# TODO wherever we test against Age, it's probably wrong
|
|
||||||
# TODO add building to production_available when finished
|
|
||||||
# TODO need some warning, penalty, etc. if villager is assigned to task
|
|
||||||
# without appropriate building (e.g., mining with no camp)
|
|
||||||
# TODO building time assumes just 1 vil is working for now
|
|
||||||
# TODO need efficiency penalties on, e.g., "stale" lumber camp
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Set up world
|
|
||||||
game = Gameplay()
|
|
||||||
|
|
||||||
# should work even before we do anything
|
|
||||||
#game.print_status()
|
|
||||||
|
|
||||||
game.queue_villager(5, Tasks.WOOD) # first number is time in seconds
|
|
||||||
|
|
||||||
# should generate exception
|
|
||||||
#game.assign_villager(40, Tasks.SHEEP, Tasks.WOOD)
|
|
||||||
|
|
||||||
game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
|
|
||||||
game.assign_villager(2, Tasks.IDLE, Tasks.SHEEP, 2)
|
|
||||||
|
|
||||||
# should generate exception
|
|
||||||
#game.assign_villager(0, Tasks.IDLE, Tasks.SHEEP)
|
|
||||||
|
|
||||||
# should generate exception
|
|
||||||
#game.build(45, Buildings.STABLE, Tasks.WOOD, Tasks.IDLE)
|
|
||||||
|
|
||||||
#game.build(45, Buildings.LUMBERCAMP, Tasks.WOOD, Tasks.IDLE)
|
|
||||||
game.build(45, Buildings.LUMBERCAMP, Tasks.WOOD, Tasks.WOOD)
|
|
||||||
|
|
||||||
game.queue_research(45, Research.LOOM)
|
|
||||||
|
|
||||||
game.queue_villager(45, Tasks.WOOD)
|
|
||||||
game.queue_villager(45, Tasks.WOOD)
|
|
||||||
|
|
||||||
game.play_until(46)
|
|
||||||
game.print_status()
|
|
||||||
|
|
||||||
game.build(100, Buildings.HOUSE, [Tasks.SHEEP, Tasks.WOOD], [Tasks.IDLE]*2)
|
|
||||||
#game.assign_villager(Build.Stable(), "food", wait_until_finished=True)
|
|
||||||
|
|
||||||
'''
|
|
||||||
game.queue_unit(s1, Scout)
|
|
||||||
'''
|
|
||||||
|
|
||||||
game.assign_villager(130, Tasks.IDLE, Tasks.WOOD, 2)
|
|
||||||
|
|
||||||
# should generate exception
|
|
||||||
#game.build(200, Buildings.FARM, [Tasks.SHEEP], [Tasks.WOOD])
|
|
||||||
|
|
||||||
game.build(200, Buildings.MILL, [Tasks.SHEEP], [Tasks.WOOD])
|
|
||||||
game.build(250, Buildings.FARM, [Tasks.SHEEP, Tasks.WOOD], [Tasks.IDLE]*2)
|
|
||||||
|
|
||||||
# Evaluate game
|
|
||||||
game.play_until(800)
|
|
||||||
game.print_status()
|
|
||||||
|
|
||||||
# should generate exception
|
|
||||||
#game.assign_villager(0, Tasks.SHEEP, Tasks.WOOD)
|
|
||||||
Reference in New Issue
Block a user