Add research and finish most buildings

This commit is contained in:
Nate Bowman
2026-07-27 22:20:29 -04:00
parent 013468d34e
commit 9ff2613579
9 changed files with 688 additions and 45 deletions

View File

@@ -8,6 +8,7 @@ from aoe.dependencies import *
from aoe.gather import *
from aoe.housing import *
from aoe.production import *
from aoe.research import *
from aoe.times import *
from aoe.types import *
@@ -44,14 +45,16 @@ class World():
# to farms with the highest capacity.
# We keep track of only the closest upcoming farm deletion.
# TODO research
# TODO fishing ships
# TODO relics
# TODO trade carts
# TODO allow automation:
# reseeding of farms
# queuing of villagers
# possibly other things
# TODO gathering boars and hunting
# spend villager time in exchange for adding gatherable resource
# TODO relics
# TODO use market for buy/sell
MAX_WORLD_TIME = 3*60*60 # 3 hours
@@ -100,14 +103,11 @@ class World():
raise MissingDependencyException
def buy_research(self, research):
def queue_research(self, research):
self._check_research_dependencies(research)
self._pay_cost(research)
self._update_costs(research)
def _update_costs(self, research):
pass
self._start_research(research)
def _schedule_next_gather_rate_decrease(self, task):
@@ -180,6 +180,24 @@ class World():
self._schedule_next_gather_rate_decrease(task)
def _permanently_modify_farm_capacity(self, increase):
current_initial_farm = self.gather.buildings_gather_increase[Buildings.FARM]
for i in range(len(farms)):
farms[i] += (farms[i]/current_initial_farm)*increase
for i in range(len(unused_farms)):
unused_farms[i] += (unused_farms[i]/current_initial_farm)*increase
self.gather.buildings_gather_increase[Buildings.FARM] += increase
self._schedule_next_gather_rate_decrease(Task.FARM)
def _permanently_modify_gather_rate(self, task, rate_multiplier):
self.gather.gather_rates[tasks] *= rate_multiplier
self.gather.original_gather_rates[tasks] *= rate_multiplier
self._schedule_next_gather_rate_decrease(task)
def assign_villager(self, previous_task, new_task, count=1):
# new_task of None means kill the villager
@@ -333,12 +351,15 @@ class World():
unit = self.production_queue[i]
if self._check_production(unit):
self._build_unit(unit)
if unit in Units:
self._build_unit(unit)
elif unit in Research:
self._start_research(unit)
new_builds.append(i)
i += 1
self.production_queue = [self.production_queue[i]
self.production_queue = [self.production_queue[i]
for i in range(original_queue_len)
if i not in new_builds]
@@ -363,7 +384,10 @@ class World():
if ready_index:
self.production_queue.remove(i)
self._build_unit(unit)
if unit in Units:
self._build_unit(unit)
elif unit in Research:
self._start_research(unit)
def _check_housing(self, unit):
@@ -396,6 +420,29 @@ class World():
raise ProductionBuildingNotAvailableException
def _use_production_for_research(self, research):
self._check_production(research)
building = self.production.building[research]
self.production_available[building] -= 1
def _add_research(self, research):
self.research.append(research)
ResearchEffects.complete_research(self, research)
self._free_production_building_of_unit(research)
def _start_research(self, research):
try:
self._use_production_for_research(research)
except ProductionBuildingNotAvailableException:
self.production_queue.append(research)
else:
update_time = self.current_time + self.build_times.build_times[research]
self.events[update_time].append((self._add_research, (research,)))
def _use_housing_and_production(self, unit):
self._check_housing(unit)
self._check_production(unit)