本文整理汇总了Python中tests.game.settle函数的典型用法代码示例。如果您正苦于以下问题:Python settle函数的具体用法?Python settle怎么用?Python settle使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了settle函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_productivity_low
def test_productivity_low(session, player):
settlement, island = settle(session)
lj = Build(BUILDINGS.CHARCOAL_BURNER_CLASS, 30, 30, island, settlement=settlement)(player)
called = [False]
def add_icon(message):
isinstance(message, AddStatusIcon)
if message.icon.__class__ == ProductivityLowStatus:
called.__setitem__(0, True)
session.message_bus.subscribe_globally(AddStatusIcon, add_icon)
# precondition
assert abs(lj.get_component(Producer).capacity_utilisation) < 0.0001
# Not yet low
assert not called[0]
session.run(seconds=60)
# Now low
assert called[0]
开发者ID:perher,项目名称:unknown-horizons,代码行数:25,代码来源:test_status_icons.py
示例2: test_ticket_979
def test_ticket_979(s, p):
settlement, island = settle(s)
storage_collectors = settlement.warehouse.get_component(CollectingComponent).get_local_collectors()
farm = _build_farm(30, 30, BUILDINGS.POTATO_FIELD, island, settlement, p)
# Let it work for a bit
s.run(seconds=60)
assert farm.get_component(StorageComponent).inventory[RES.FOOD]
# Depending on auto unloading (which we aren't interested in here),
# the settlement inventory may already be full of food: dispose of it
settlement.get_component(StorageComponent).inventory.alter(RES.FOOD, -settlement.get_component(StorageComponent).inventory[RES.FOOD])
assert settlement.get_component(StorageComponent).inventory[RES.FOOD] == 0
# Build a road, connecting farm and warehouse
for y in range(23, 30):
assert Build(BUILDINGS.TRAIL, 30, y, island, settlement=settlement)(p)
# Step forward in time until a collector picked a job
got_job = False
while not got_job:
s.run()
if any(c.job for c in storage_collectors):
got_job = True
Tear(farm)(p)
# Let the collector reach the not existing target
s.run(seconds=10)
开发者ID:BenjaminHarper,项目名称:unknown-horizons,代码行数:30,代码来源:test_bugs.py
示例3: test_pastryshop_production_chain
def test_pastryshop_production_chain(s, p):
"""
The pastryshop makes candles and sugar out of honeycombs. Sugar is later used in combination with
grapes and cocoa to produce confectioneries. Honeycombs, cocoa and grapes are generated at a farm.
"""
settlement, island = settle(s)
assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
assert Build(BUILDINGS.COCOA_FIELD, 26, 30, island, settlement=settlement)(p)
assert Build(BUILDINGS.VINEYARD, 30, 34, island, settlement=settlement)(p)
assert Build(BUILDINGS.ALVEARIES, 34, 30, island, settlement=settlement)(p)
pastryshop = Build(BUILDINGS.PASTRY_SHOP, 30, 26, island, settlement=settlement)(p)
assert pastryshop
assert pastryshop.get_component(StorageComponent).inventory[RES.HONEYCOMBS] == 0
assert pastryshop.get_component(StorageComponent).inventory[RES.SUGAR] == 0
assert pastryshop.get_component(StorageComponent).inventory[RES.COCOA] == 0
assert pastryshop.get_component(StorageComponent).inventory[RES.GRAPES] == 0
assert pastryshop.get_component(StorageComponent).inventory[RES.CANDLES] == 0
assert pastryshop.get_component(StorageComponent).inventory[RES.CONFECTIONERY] == 0
s.run(seconds=120) # 30s alvearies, 30s vineyard, 30s cocoa field, 45s pastry shop
assert pastryshop.get_component(StorageComponent).inventory[RES.CANDLES]
assert pastryshop.get_component(StorageComponent).inventory[RES.CONFECTIONERY] >= 2
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:25,代码来源:test_buildings.py
示例4: test_tool_production_chain
def test_tool_production_chain(s, p):
"""
Check if a iron mine gathers raw iron, a smeltery produces iron ingots, boards are converted
to charcoal and tools are produced.
Pretty much for a single test, but these are rather trivial in their assertions anyway.
"""
settlement, island = settle(s)
assert Build(BUILDINGS.MOUNTAIN, 30, 35, island, ownerless=True)(None)
assert Build(BUILDINGS.IRON_MINE, 30, 35, island, settlement=settlement)(p)
charcoal = Build(BUILDINGS.CHARCOAL_BURNER, 25, 35, island, settlement=settlement)(p)
assert charcoal
charcoal.get_component(StorageComponent).inventory.alter(RES.BOARDS, 10) # give him boards directly
assert Build(BUILDINGS.SMELTERY, 25, 30, island, settlement=settlement)(p)
toolmaker = Build(BUILDINGS.TOOLMAKER, 22, 32, island, settlement=settlement)(p)
assert toolmaker
toolmaker.get_component(StorageComponent).inventory.alter(RES.BOARDS, 10) # give him boards directly
assert toolmaker.get_component(StorageComponent).inventory[RES.TOOLS] == 0
s.run(seconds=120)
assert toolmaker.get_component(StorageComponent).inventory[RES.TOOLS]
开发者ID:DanielStephens,项目名称:unknown-horizons,代码行数:25,代码来源:test_buildings.py
示例5: test_farm_crop_production
def test_farm_crop_production(s, p):
"""
Check whether the fields produce crops and the crops are collected at the farm
"""
settlement, island = settle(s)
farm = _build_farm(30, 30, island, settlement, p, BUILDINGS.HERBARY, BUILDINGS.SUGARCANE_FIELD,
BUILDINGS.VINEYARD, BUILDINGS.TOBACCO_FIELD, BUILDINGS.SPICE_FIELD,
BUILDINGS.HOP_FIELD, BUILDINGS.COCOA_FIELD, BUILDINGS.CORN_FIELD)
assert farm
primary_resources = (RES.HERBS, RES.RAW_SUGAR, RES.VINES, RES.TOBACCO_PLANTS, RES.SPICE_PLANTS,
RES.HOP_PLANTS, RES.COCOA_BEANS, RES.GRAIN)
secondary_resources = (RES.MEDICAL_HERBS, RES.SUGAR, RES.GRAPES, RES.TOBACCO_LEAVES, RES.SPICES,
RES.HOPS, RES.COCOA, RES.CORN)
for p_res, s_res in zip(primary_resources, secondary_resources):
assert farm.get_component(StorageComponent).inventory[p_res] == 0
assert farm.get_component(StorageComponent).inventory[s_res] == 0
s.run(seconds=60)
for s_res in secondary_resources:
assert farm.get_component(StorageComponent).inventory[s_res]
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:26,代码来源:test_buildings.py
示例6: test_ticket_1232
def test_ticket_1232(s, p):
settlement, island = settle(s)
assert len(s.world.ships) == 2
boat_builder = Build(BUILDINGS.BOAT_BUILDER, 35, 20, island, settlement=settlement)(p)
boat_builder.get_component(StorageComponent).inventory.alter(RES.TEXTILE, 10)
boat_builder.get_component(StorageComponent).inventory.alter(RES.BOARDS, 8)
assert isinstance(boat_builder.get_component(Producer), QueueProducer)
production_finished = [False]
boat_builder.get_component(Producer).add_production_by_id(PRODUCTIONLINES.HUKER)
production1 = boat_builder.get_component(Producer)._get_production(PRODUCTIONLINES.HUKER)
production1.add_production_finished_listener(lambda _: production_finished.__setitem__(0, True))
assert boat_builder.get_component(Producer).is_active()
while not production_finished[0]:
s.run(ticks=1)
assert not boat_builder.get_component(Producer).is_active()
assert len(s.world.ships) == 3
# Make sure enough res are available
boat_builder.get_component(StorageComponent).inventory.alter(RES.TEXTILE, 10)
boat_builder.get_component(StorageComponent).inventory.alter(RES.BOARDS, 8)
boat_builder.get_component(StorageComponent).inventory.alter(RES.TOOLS, 5)
boat_builder.get_component(Producer).add_production_by_id(PRODUCTIONLINES.HUKER)
assert boat_builder.get_component(Producer).is_active()
s.run(seconds=130)
assert not boat_builder.get_component(Producer).is_active()
assert len(s.world.ships) == 4
开发者ID:BenjaminHarper,项目名称:unknown-horizons,代码行数:28,代码来源:test_bugs.py
示例7: test_ticket_979
def test_ticket_979(s, p):
settlement, island = settle(s)
storage_collectors = settlement.branch_office.get_local_collectors()
farm = _build_farm(30, 30, BUILDINGS.POTATO_FIELD_CLASS, island, settlement, p)
# Let it work for a bit
s.run(seconds=60)
assert farm.inventory[RES.FOOD_ID]
# The settlement inventory is already full of food (from the ship): dispose of it
assert settlement.inventory[RES.FOOD_ID] > 0
settlement.inventory.alter(RES.FOOD_ID, -settlement.inventory[RES.FOOD_ID])
assert settlement.inventory[RES.FOOD_ID] == 0
# Build a road, connecting farm and branch office
for y in range(23, 30):
assert Build(BUILDINGS.TRAIL_CLASS, 30, y, island, settlement=settlement)(p)
# Step forward in time until a collector picked a job
got_job = False
while not got_job:
s.run()
if any(c.job for c in storage_collectors):
got_job = True
Tear(farm)(p)
# Let the collector reach the not existing target
s.run(seconds=10)
开发者ID:mihaibivol,项目名称:unknown-horizons,代码行数:30,代码来源:test_bugs.py
示例8: test_hunter_save_load
def test_hunter_save_load():
"""Save/loading hunter in different states"""
session, player = new_session()
settlement, island = settle(session)
# setup hunter, trees (to keep animals close) and animals
hunter = Build(BUILDINGS.HUNTER_CLASS, 30, 30, island, settlement=settlement)(player)
hunter_worldid = hunter.worldid
del hunter # invalid after save/load
for x in xrange(27, 29):
for y in xrange(25, 28):
assert Build(BUILDINGS.TREE_CLASS, x, y, island, settlement=settlement)(player)
CreateUnit(island.worldid, UNITS.WILD_ANIMAL_CLASS, 27, 27)(issuer=None)
CreateUnit(island.worldid, UNITS.WILD_ANIMAL_CLASS, 28, 27)(issuer=None)
CreateUnit(island.worldid, UNITS.WILD_ANIMAL_CLASS, 29, 27)(issuer=None)
# utility
def saveload(session):
fd, filename = tempfile.mkstemp()
os.close(fd)
assert session.save(savegamename=filename)
session.end(keep_map=True)
session = load_session(filename)
Scheduler().before_ticking() # late init finish (not ticking already)
return session
def get_hunter_collector(session):
hunter = WorldObject.get_object_by_id(hunter_worldid)
return hunter.get_component(CollectingComponent)._CollectingComponent__collectors[0]
def await_transition(session, collector, old_state, new_state):
assert collector.state == old_state, "expected old state %s, got %s" % (old_state, collector.state)
while collector.state == old_state:
session.run(seconds=1)
assert collector.state == new_state, "expected new state %s, got %s" % (old_state, collector.state)
sequence = [
Collector.states.idle,
Collector.states.waiting_for_animal_to_stop,
Collector.states.moving_to_target,
Collector.states.working,
Collector.states.moving_home,
Collector.states.idle
]
# do full run without saveload
collector = get_hunter_collector(session)
for i in xrange(len(sequence)-1):
await_transition(session, collector, sequence[i], sequence[i+1])
# do full run with saveload
for i in xrange(len(sequence)-1):
collector = get_hunter_collector(session)
await_transition(session, collector, sequence[i], sequence[i+1])
session = saveload(session)
开发者ID:ranjithtanj,项目名称:unknown-horizons,代码行数:59,代码来源:test_load_save.py
示例9: test_ticket_1427
def test_ticket_1427():
"""Boatbuilder production progress should be saved properly"""
session, player = new_session()
settlement, island = settle(session)
boat_builder = Build(BUILDINGS.BOATBUILDER_CLASS, 35, 20, island, settlement=settlement)(player)
worldid = boat_builder.worldid
# Make sure no boards are available
settlement.get_component(StorageComponent).inventory.alter(RES.BOARDS_ID, -1000)
bb_storage = boat_builder.get_component(StorageComponent)
# Add production to use resources
bb_producer = boat_builder.get_component(Producer)
bb_producer.add_production_by_id(PRODUCTIONLINES.HUKER)
production = bb_producer._productions[PRODUCTIONLINES.HUKER]
assert production.progress == 0.0
bb_storage.inventory.alter(RES.TEXTILE_ID, 10)
bb_storage.inventory.alter(RES.BOARDS_ID, 6)
production_line = production._prod_line
# Make sure the boatbuilder consumes everything in his inventory
session.run(seconds=10)
# Check if correctly consumed wood
assert production_line.consumed_res[RES.BOARDS_ID] == -2
# Save all production process for later
expected_consumed_res = production_line.consumed_res
expected_produced_res = production_line.produced_res
expected_production = production_line.production
expected_progress = production.progress
# Make sure the producer used the boards
assert bb_storage.inventory[RES.BOARDS_ID] == 0
fd, filename = tempfile.mkstemp()
os.close(fd)
assert session.save(savegamename=filename)
session.end(keep_map=True)
# Load game
session = load_session(filename)
loadedbb = WorldObject.get_object_by_id(worldid)
production_loaded = loadedbb.get_component(Producer)._productions[PRODUCTIONLINES.HUKER]
production_line_loaded = production_loaded._prod_line
# Make sure everything is loaded correctly
assert expected_consumed_res == production_line_loaded.consumed_res
assert expected_produced_res == production_line_loaded.produced_res
assert expected_production == production_line_loaded.production
assert expected_progress == production_loaded.progress
开发者ID:perher,项目名称:unknown-horizons,代码行数:58,代码来源:test_bugs.py
示例10: test_ticket_1427
def test_ticket_1427():
"""Boatbuilder production progress should be saved properly"""
session, player = new_session()
settlement, island = settle(session)
boat_builder = Build(BUILDINGS.BOAT_BUILDER, 35, 20, island, settlement=settlement)(player)
worldid = boat_builder.worldid
# Make sure no boards are available
settlement.get_component(StorageComponent).inventory.alter(RES.BOARDS, -1000)
bb_storage = boat_builder.get_component(StorageComponent)
# Add production to use resources
bb_producer = boat_builder.get_component(Producer)
bb_producer.add_production_by_id(PRODUCTIONLINES.HUKER)
production = bb_producer._productions[PRODUCTIONLINES.HUKER]
assert production.progress == 0.0
bb_storage.inventory.alter(RES.TEXTILE, 10)
bb_storage.inventory.alter(RES.BOARDS, 6)
production_line = production._prod_line
# Make sure the boatbuilder consumes everything in its inventory
session.run(seconds=10)
# Check if correctly consumed wood
assert production_line.consumed_res[RES.BOARDS] == -2
# Save all production process for later
expected_consumed_res = production_line.consumed_res
expected_produced_res = production_line.produced_res
expected_production = production_line.production
expected_progress = production.progress
# Make sure the producer used the boards
assert bb_storage.inventory[RES.BOARDS] == 0
# Save and reload game
session = saveload(session)
loadedbb = WorldObject.get_object_by_id(worldid)
production_loaded = loadedbb.get_component(Producer)._productions[PRODUCTIONLINES.HUKER]
production_line_loaded = production_loaded._prod_line
# Make sure everything is loaded correctly
assert expected_consumed_res == production_line_loaded.consumed_res
assert expected_produced_res == production_line_loaded.produced_res
assert expected_production == production_line_loaded.production
assert expected_progress == production_loaded.progress
# if you don't let the session run for a bit then collectors won't be fully initialized and can't be killed => another test will fail in session.end()
session.run(seconds=1)
session.end()
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:57,代码来源:test_bugs.py
示例11: test_pavilion_production
def test_pavilion_production(s, p):
"""
Check whether the pavilion produces faith
"""
settlement, island = settle(s)
pavilion = Build(BUILDINGS.PAVILION, 30, 30, island, settlement=settlement)(p)
assert pavilion
assert pavilion.get_component(StorageComponent).inventory[RES.FAITH] == 0
s.run(seconds=30)
assert pavilion.get_component(StorageComponent).inventory[RES.FAITH]
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:11,代码来源:test_buildings.py
示例12: test_ticket_1847
def test_ticket_1847(s, p):
"""Tearing down MineProducer (clay pit, mine) crashes game"""
settlement, island = settle(s)
assert Build(BUILDINGS.CLAY_DEPOSIT, 30, 30, island, ownerless=True)(None)
claypit = Build(BUILDINGS.CLAY_PIT, 30, 30, island, settlement=settlement)(p)
assert claypit
Tear(claypit)(p)
s.run(seconds=5)
开发者ID:BenjaminHarper,项目名称:unknown-horizons,代码行数:11,代码来源:test_bugs.py
示例13: test_saltpond_production
def test_saltpond_production(s, p):
"""
Check whether saltponds produce salt
"""
settlement, island = settle(s)
saltpond = Build(BUILDINGS.SALT_PONDS, 25, 20, island, settlement=settlement)(p)
assert saltpond
assert saltpond.get_component(StorageComponent).inventory[RES.SALT] == 0
s.run(seconds=60)
assert saltpond.get_component(StorageComponent).inventory[RES.SALT] >= 2 # ponds produce salt in units of 2
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:12,代码来源:test_buildings.py
示例14: test_school_production
def test_school_production(s, p):
"""
Check whether schools produce education
"""
settlement, island = settle(s)
school = Build(BUILDINGS.VILLAGE_SCHOOL, 30, 30, island, settlement=settlement)(p)
assert school
assert school.get_component(StorageComponent).inventory[RES.EDUCATION] == 0
s.run(seconds=30)
assert school.get_component(StorageComponent).inventory[RES.EDUCATION]
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:12,代码来源:test_buildings.py
示例15: test_ticket_1005
def test_ticket_1005(s, p):
settlement, island = settle(s)
assert len(s.world.ships) == 2
builder = Build(BUILDINGS.BOATBUILDER_CLASS, 35, 20, island, settlement=settlement)(p)
builder.inventory.alter(RES.TEXTILE_ID, 5)
builder.inventory.alter(RES.BOARDS_ID, 4)
builder.add_production_by_id(15)
s.run(seconds=130)
assert len(s.world.ships) == 3
开发者ID:mihaibivol,项目名称:unknown-horizons,代码行数:12,代码来源:test_bugs.py
示例16: test_ticket_1005
def test_ticket_1005(s, p):
settlement, island = settle(s)
assert len(s.world.ships) == 2
builder = Build(BUILDINGS.BOAT_BUILDER, 35, 20, island, settlement=settlement)(p)
builder.get_component(StorageComponent).inventory.alter(RES.TEXTILE, 5)
builder.get_component(StorageComponent).inventory.alter(RES.BOARDS, 4)
builder.get_component(Producer).add_production_by_id(15)
s.run(seconds=130)
assert len(s.world.ships) == 3
开发者ID:BenjaminHarper,项目名称:unknown-horizons,代码行数:12,代码来源:test_bugs.py
示例17: test_ticket_1523
def test_ticket_1523(s, p):
settlement, island = settle(s)
farm = _build_farm(30, 30, BUILDINGS.POTATO_FIELD, island, settlement, p)
# Let it work for a bit
s.run(seconds=60)
assert farm.get_component(StorageComponent).inventory[RES.FOOD]
assert isinstance(farm.get_component(Producer)._Producer__utilisation, FieldUtilisation)
# Should be 0.5
assert not farm.get_component(Producer).capacity_utilisation_below(0.4)
assert farm.get_component(Producer).capacity_utilisation > 0.4
开发者ID:MasterofJOKers,项目名称:unknown-horizons,代码行数:13,代码来源:test_bugs.py
示例18: test_decommissioned
def test_decommissioned(session, player):
settlement, island = settle(session)
lj = Build(BUILDINGS.LUMBERJACK, 30, 30, island, settlement=settlement)(player)
cb = mock.Mock()
AddStatusIcon.subscribe(cb)
assert not cb.called
ToggleActive(lj.get_component(Producer))(player)
assert_called_with_icon(cb, DecommissionedStatus)
开发者ID:kenygia,项目名称:unknown-horizons,代码行数:13,代码来源:test_status_icons.py
示例19: test_potato_field
def test_potato_field(s, p):
"""
A farm collects potatoes from the field and produces food.
"""
settlement, island = settle(s)
farm = _build_farm(30, 30, BUILDINGS.POTATO_FIELD_CLASS, island, settlement, p)
assert farm.inventory[RES.FOOD_ID] == 0
assert farm.inventory[RES.POTATOES_ID] == 0
s.run(seconds=60) # potato field 26s, farm 1s
assert farm.inventory[RES.FOOD_ID]
开发者ID:mihaibivol,项目名称:unknown-horizons,代码行数:13,代码来源:test_farm.py
示例20: test_settler_level_save_load
def test_settler_level_save_load(s, p):
"""
Verify that settler level up with save/load works
"""
# test all available upgrades: 0->1, 1->2, 2->3...
for test_level in range(TIER.CURRENT_MAX):
session, player = new_session()
settlement, island = settle(s)
settler = Build(BUILDINGS.RESIDENTIAL, 22, 22, island, settlement=settlement)(p)
settler.level += test_level
settler._update_level_data(True, True)
settler_worldid = settler.worldid
settlement.tax_settings[settler.level] = -0.5
# make it happy
inv = settler.get_component(StorageComponent).inventory
to_give = inv.get_free_space_for(RES.HAPPINESS)
inv.alter(RES.HAPPINESS, to_give)
settler.inhabitants = settler.inhabitants_max
level = settler.level
# wait for it to realize it's supposed to upgrade
s.run(seconds=GAME.INGAME_TICK_INTERVAL)
assert settler.level == level
session = saveload(session)
settler = WorldObject.get_object_by_id(settler_worldid)
inv = settler.get_component(StorageComponent).inventory
assert settler.level == level
# continue
s.run(seconds=GAME.INGAME_TICK_INTERVAL)
assert inv[RES.BOARDS] == 0
assert inv[RES.BRICKS] == 0
assert settler.level == level
# give upgrade res
inv.alter(RES.BOARDS, 100)
inv.alter(RES.BRICKS, 100)
# give it max population
settler.inhabitants = settler.inhabitants_max
s.run(seconds=GAME.INGAME_TICK_INTERVAL)
# should have leveled up
assert settler.level == level + 1
开发者ID:MarkusHackspacher,项目名称:unknown-horizons,代码行数:51,代码来源:test_load_save.py
注:本文中的tests.game.settle函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论