From 1a66084d32d2ef356d8079f1ff571a0bf4c3652d Mon Sep 17 00:00:00 2001 From: Nate Bowman Date: Sat, 7 Nov 2026 18:50:46 -0500 Subject: [PATCH] Add trade --- aoe/costs.py | 1 + aoe/dependencies.py | 1 + aoe/gameplay.py | 10 ++++++++++ aoe/production.py | 2 ++ aoe/times.py | 1 + aoe/types.py | 1 + aoe/world.py | 19 +++++++++++++------ tests/test.py | 34 ++++++++++++++++++++++++++++++++++ 8 files changed, 63 insertions(+), 6 deletions(-) diff --git a/aoe/costs.py b/aoe/costs.py index 41350b0..c513544 100644 --- a/aoe/costs.py +++ b/aoe/costs.py @@ -140,4 +140,5 @@ class Costs(): Units.ARCHER: (0, 25, 45, 0), Units.MONK: (0, 0, 100, 0), Units.FISHINGSHIP: (0, 75, 0, 0), + Units.TRADECOG: (0, 100, 50, 0), } diff --git a/aoe/dependencies.py b/aoe/dependencies.py index 3e2c5dd..412345e 100644 --- a/aoe/dependencies.py +++ b/aoe/dependencies.py @@ -271,4 +271,5 @@ class Dependencies(): Units.ARCHER: [Ages.FEUDAL, Buildings.ARCHERYRANGE], Units.MONK: [Ages.CASTLE, Buildings.MONASTERY], Units.FISHINGSHIP: [Ages.FEUDAL, Buildings.DOCK], + Units.TRADECOG: [Ages.FEUDAL, Buildings.DOCK], } diff --git a/aoe/gameplay.py b/aoe/gameplay.py index c8ae4e8..58c3091 100644 --- a/aoe/gameplay.py +++ b/aoe/gameplay.py @@ -55,6 +55,16 @@ class Gameplay(): (initial_task,))) + def queue_trade_cog(self, action_time): + self._check_time(action_time) + 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, ())) + + def queue_unit(self, action_time, unit): self._check_time(action_time) self.actions[action_time].append((self.world.queue_unit, (unit,))) diff --git a/aoe/production.py b/aoe/production.py index 53c2a06..3432107 100644 --- a/aoe/production.py +++ b/aoe/production.py @@ -27,6 +27,8 @@ class Production(): Units.ARCHER: Buildings.ARCHERYRANGE, Units.MONK: Buildings.MONASTERY, Units.FISHINGSHIP: Buildings.DOCK, + Units.TRADECOG: Buildings.DOCK, + Units.TRADECART: Buildings.MARKET, Research.TOWNWATCH: Buildings.TOWNCENTER, Research.TOWNPATROL: Buildings.TOWNCENTER, Research.TREADMILLCRANE: Buildings.UNIVERSITY, diff --git a/aoe/times.py b/aoe/times.py index f48483a..2dddf49 100644 --- a/aoe/times.py +++ b/aoe/times.py @@ -137,4 +137,5 @@ class Times(): Units.ARCHER: 35, Units.MONK: 51, Units.FISHINGSHIP: 40, + Units.TRADECOG: 36, } diff --git a/aoe/types.py b/aoe/types.py index 7df363f..7965833 100644 --- a/aoe/types.py +++ b/aoe/types.py @@ -173,3 +173,4 @@ class Units(Enum): ARCHER = auto() MONK = auto() FISHINGSHIP = auto() + TRADECOG = auto() diff --git a/aoe/world.py b/aoe/world.py index 433f67f..63bec34 100644 --- a/aoe/world.py +++ b/aoe/world.py @@ -43,16 +43,11 @@ class World(): # to farms with the highest capacity. # We keep track of only the closest upcoming farm deletion. - # TODO fishing ships - # TODO relics - # TODO trade carts + # TODO fishtraps # 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 food spoilage # TODO use market for buy/sell @@ -419,6 +414,10 @@ class World(): if not initial_task: initial_task = Tasks.FISH_SHIP_IDLE self.villager_tasks[initial_task] += 1 + elif thing == Units.TRADECOG: + self.villager_tasks[Tasks.TRADECOG] += 1 + elif thing == Units.TRADECART: + self.villager_tasks[Tasks.TRADECART] += 1 def _start_producing(self, thing, initial_task): @@ -455,6 +454,14 @@ class World(): self._queue_thing(Units.FISHINGSHIP, initial_task) + def queue_trade_cog(self): + self._queue_thing(Units.TRADECOG) + + + def queue_trade_cart(self): + self._queue_thing(Units.TRADECART) + + def _handle_events(self): for func, args in self.events[self.current_time]: func(*args) diff --git a/tests/test.py b/tests/test.py index 349aa89..146b46b 100644 --- a/tests/test.py +++ b/tests/test.py @@ -307,3 +307,37 @@ class TestWorld(unittest.TestCase): game.play_until(training + 60) self.assertResourcesMatch([500 + gathered, 425, 500, 500], game.world) + + + def test_trade_cog(self): + game = Gameplay() + + # just cheat + game.world.age = Ages.FEUDAL + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.DOCK, {}, {}) + + game.queue_trade_cog(0) + + training = 36 + gathered = 25.9 + + game.play_until(training + 60) + self.assertResourcesMatch([500, 400, 450 + gathered, 500], game.world) + + + def test_trade_cart(self): + game = Gameplay() + + # just cheat + game.world.age = Ages.FEUDAL + game.world.gather.resources = [500, 500, 500, 500] + game.world._add_building(Buildings.MARKET, {}, {}) + + game.queue_trade_cart(0) + + training = 51 + gathered = 25.9 + + game.play_until(training + 60) + self.assertResourcesMatch([500, 400, 450 + gathered, 500], game.world)