Add trade

This commit is contained in:
Nate Bowman
2026-11-07 18:50:46 -05:00
parent 0d40fe5dc0
commit 1a66084d32
8 changed files with 63 additions and 6 deletions

View File

@@ -140,4 +140,5 @@ class Costs():
Units.ARCHER: (0, 25, 45, 0), Units.ARCHER: (0, 25, 45, 0),
Units.MONK: (0, 0, 100, 0), Units.MONK: (0, 0, 100, 0),
Units.FISHINGSHIP: (0, 75, 0, 0), Units.FISHINGSHIP: (0, 75, 0, 0),
Units.TRADECOG: (0, 100, 50, 0),
} }

View File

@@ -271,4 +271,5 @@ class Dependencies():
Units.ARCHER: [Ages.FEUDAL, Buildings.ARCHERYRANGE], Units.ARCHER: [Ages.FEUDAL, Buildings.ARCHERYRANGE],
Units.MONK: [Ages.CASTLE, Buildings.MONASTERY], Units.MONK: [Ages.CASTLE, Buildings.MONASTERY],
Units.FISHINGSHIP: [Ages.FEUDAL, Buildings.DOCK], Units.FISHINGSHIP: [Ages.FEUDAL, Buildings.DOCK],
Units.TRADECOG: [Ages.FEUDAL, Buildings.DOCK],
} }

View File

@@ -55,6 +55,16 @@ class Gameplay():
(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, ()))
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): def queue_unit(self, action_time, unit):
self._check_time(action_time) 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,)))

View File

@@ -27,6 +27,8 @@ class Production():
Units.ARCHER: Buildings.ARCHERYRANGE, Units.ARCHER: Buildings.ARCHERYRANGE,
Units.MONK: Buildings.MONASTERY, Units.MONK: Buildings.MONASTERY,
Units.FISHINGSHIP: Buildings.DOCK, Units.FISHINGSHIP: Buildings.DOCK,
Units.TRADECOG: Buildings.DOCK,
Units.TRADECART: Buildings.MARKET,
Research.TOWNWATCH: Buildings.TOWNCENTER, Research.TOWNWATCH: Buildings.TOWNCENTER,
Research.TOWNPATROL: Buildings.TOWNCENTER, Research.TOWNPATROL: Buildings.TOWNCENTER,
Research.TREADMILLCRANE: Buildings.UNIVERSITY, Research.TREADMILLCRANE: Buildings.UNIVERSITY,

View File

@@ -137,4 +137,5 @@ class Times():
Units.ARCHER: 35, Units.ARCHER: 35,
Units.MONK: 51, Units.MONK: 51,
Units.FISHINGSHIP: 40, Units.FISHINGSHIP: 40,
Units.TRADECOG: 36,
} }

View File

@@ -173,3 +173,4 @@ class Units(Enum):
ARCHER = auto() ARCHER = auto()
MONK = auto() MONK = auto()
FISHINGSHIP = auto() FISHINGSHIP = auto()
TRADECOG = auto()

View File

@@ -43,16 +43,11 @@ class World():
# to farms with the highest capacity. # to farms with the highest capacity.
# We keep track of only the closest upcoming farm deletion. # We keep track of only the closest upcoming farm deletion.
# TODO fishing ships # TODO fishtraps
# TODO relics
# TODO trade carts
# TODO allow automation: # TODO allow automation:
# reseeding of farms # reseeding of farms
# queuing of villagers # queuing of villagers
# possibly other things # 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 # TODO use market for buy/sell
@@ -419,6 +414,10 @@ class World():
if not initial_task: if not initial_task:
initial_task = Tasks.FISH_SHIP_IDLE initial_task = Tasks.FISH_SHIP_IDLE
self.villager_tasks[initial_task] += 1 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): def _start_producing(self, thing, initial_task):
@@ -455,6 +454,14 @@ class World():
self._queue_thing(Units.FISHINGSHIP, initial_task) 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): def _handle_events(self):
for func, args in self.events[self.current_time]: for func, args in self.events[self.current_time]:
func(*args) func(*args)

View File

@@ -307,3 +307,37 @@ class TestWorld(unittest.TestCase):
game.play_until(training + 60) game.play_until(training + 60)
self.assertResourcesMatch([500 + gathered, 425, 500, 500], game.world) 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)