示例#1
0
def test_settler_save_load():
    """Save/loading """
    session, player = new_session()
    settlement, island = settle(session)

    # setup:
    # 1) build settler
    # 2) save/load
    # 3) build main square
    # -> settler won't load properly and not use the resources and die

    settler = Build(BUILDINGS.RESIDENTIAL,
                    25,
                    22,
                    island,
                    settlement=settlement)(player)
    assert settler

    main_square = Build(BUILDINGS.MAIN_SQUARE,
                        23,
                        24,
                        island,
                        settlement=settlement)(player)
    assert main_square
    main_square.get_component(StorageComponent).inventory.alter(RES.FOOD, 100)

    session = saveload(session)

    session.run(seconds=500)

    tile = session.world.get_tile(Point(25, 22))

    # tile will contain ruin in case of failure
    assert tile.object.id == BUILDINGS.RESIDENTIAL
    session.end()
def test_tobbaconist_production_chain(s, p):
    """
	Tobacco is generated by tobacco fields and transferred to the tobacconist for tobacco
	products making
	"""
    settlement, island = settle(s)

    assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
    assert Build(BUILDINGS.TOBACCO_FIELD,
                 26,
                 30,
                 island,
                 settlement=settlement)(p)

    tobacconist = Build(BUILDINGS.TOBACCONIST,
                        30,
                        26,
                        island,
                        settlement=settlement)(p)

    assert tobacconist

    assert tobacconist.get_component(StorageComponent).inventory[
        RES.TOBACCO_LEAVES] == 0
    assert tobacconist.get_component(StorageComponent).inventory[
        RES.TOBACCO_PRODUCTS] == 0
    s.run(seconds=120)  # 30s tobacco field, 15s tobacconist
    assert tobacconist.get_component(StorageComponent).inventory[
        RES.TOBACCO_PRODUCTS]
示例#3
0
def test_load_inactive_production():
    """
	create a savegame with a inactive production, load it
	"""
    session, player = new_session()
    settlement, island = settle(session)

    lj = Build(BUILDINGS.LUMBERJACK, 30, 30, island,
               settlement=settlement)(player)
    # Set lumberjack to inactive
    lj.get_component(Producer).set_active(active=False)
    worldid = lj.worldid

    session.run(seconds=1)

    # Save and reload game
    session = saveload(session)

    loadedlj = WorldObject.get_object_by_id(worldid)

    # Make sure it really is not active
    producer = loadedlj.get_component(Producer)
    assert not producer.is_active()

    # Trigger bug #1359
    ToggleActive(producer).execute(session)

    session.end()
def test_distillery_production_chain(s, p):
    """
	Raw sugar is generated by sugarcane fields and transferred to the distillery
	for liquor production
	"""
    settlement, island = settle(s)

    assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
    assert Build(BUILDINGS.SUGARCANE_FIELD,
                 26,
                 30,
                 island,
                 settlement=settlement)(p)

    distillery = Build(BUILDINGS.DISTILLERY,
                       30,
                       26,
                       island,
                       settlement=settlement)(p)

    assert distillery

    assert distillery.get_component(StorageComponent).inventory[RES.SUGAR] == 0
    assert distillery.get_component(StorageComponent).inventory[
        RES.LIQUOR] == 0
    s.run(seconds=60)  # 30s sugarcane field, 12s distillery
    assert distillery.get_component(StorageComponent).inventory[RES.LIQUOR]
def test_weaponsmith_production_chain(s, p):
    """
	The mine generates iron ore. The charcoal burner produces charcoal out of wooden boards.
	Later the smeltery produces iron ingots out of iron ore and charcoal. Finally, the weaponsmith
	produces swords out of charcoal and iron ingots.
	"""
    settlement, island = settle(s)

    assert Build(BUILDINGS.MOUNTAIN, 30, 35, island, ownerless=True)(None)
    assert Build(BUILDINGS.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)

    weaponsmith = Build(BUILDINGS.WEAPONSMITH,
                        22,
                        32,
                        island,
                        settlement=settlement)(p)
    assert weaponsmith

    assert weaponsmith.get_component(StorageComponent).inventory[
        RES.SWORD] == 0
    s.run(seconds=120)
    assert weaponsmith.get_component(StorageComponent).inventory[RES.SWORD]
示例#6
0
def test_settler_save_load():
	"""Save/loading """
	session, player = new_session()
	settlement, island = settle(session)

	# setup:
	# 1) build settler
	# 2) save/load
	# 3) build main square
	# -> settler won't load properly and not use the resources and die

	settler = Build(BUILDINGS.RESIDENTIAL, 25, 22, island, settlement=settlement)(player)
	assert settler

	main_square = Build(BUILDINGS.MAIN_SQUARE, 23, 24, island, settlement=settlement)(player)
	assert main_square
	main_square.get_component(StorageComponent).inventory.alter(RES.FOOD, 100)

	session = saveload(session)

	session.run(seconds=500)

	tile = session.world.get_tile(Point(25, 22))

	# tile will contain ruin in case of failure
	assert tile.object.id == BUILDINGS.RESIDENTIAL
示例#7
0
def test_load_inactive_production():
	"""
	create a savegame with a inactive production, load it
	"""
	session, player = new_session()
	settlement, island = settle(session)

	lj = Build(BUILDINGS.LUMBERJACK, 30, 30, island, settlement=settlement)(player)
	# Set lumberjack to inactive
	lj.get_component(Producer).set_active(active = False)
	worldid = lj.worldid

	session.run(seconds=1)

	fd, filename = tempfile.mkstemp()
	os.close(fd)

	assert session.save(savegamename=filename)

	session.end(keep_map=True)

	# Load game
	session = load_session(filename)
	loadedlj = WorldObject.get_object_by_id(worldid)

	# Make sure it really is not active
	producer = loadedlj.get_component(Producer)
	assert not producer.is_active()

	# Trigger bug #1359
	ToggleActive(producer).execute(session)

	session.end()
示例#8
0
def add_nature_objects(world, natural_resource_multiplier):
    """
	Place trees, wild animals, fish deposits, clay deposits, and mountains.

	@param natural_resource_multiplier: multiply the amount of fish deposits, clay deposits, and mountains by this.
	"""

    if not int(world.properties.get('RandomTrees', 1)):
        return

    add_resource_deposits(world, natural_resource_multiplier)
    Tree = Entities.buildings[BUILDINGS.TREE]
    FishDeposit = Entities.buildings[BUILDINGS.FISH_DEPOSIT]
    fish_directions = [(i, j) for i in xrange(-1, 2) for j in xrange(-1, 2)]

    # TODO HACK BAD THING hack the component template to make trees start finished
    Tree.component_templates[1]['ProducerComponent']['start_finished'] = True

    # add trees, wild animals, and fish
    for island in world.islands:
        for (x, y), tile in sorted(island.ground_map.iteritems()):
            # add tree to every nth tile and an animal to one in every M trees
            if world.session.random.randint(0, 2) == 0 and \
               Tree.check_build(world.session, tile, check_settlement=False):
                building = Build(Tree,
                                 x,
                                 y,
                                 island,
                                 45 + world.session.random.randint(0, 3) * 90,
                                 ownerless=True)(issuer=None)
                if world.session.random.randint(
                        0, WILD_ANIMAL.POPULATION_INIT_RATIO
                ) == 0:  # add animal to every nth tree
                    CreateUnit(island.worldid, UNITS.WILD_ANIMAL, x,
                               y)(issuer=None)
                if world.session.random.random(
                ) > WILD_ANIMAL.FOOD_AVAILABLE_ON_START:
                    building.get_component(StorageComponent).inventory.alter(
                        RES.WILDANIMALFOOD, -1)

            if 'coastline' in tile.classes and world.session.random.random(
            ) < natural_resource_multiplier / 4.0:
                # try to place fish: from the current position go to a random directions twice
                for (x_dir,
                     y_dir) in world.session.random.sample(fish_directions, 2):
                    # move a random amount in both directions
                    fish_x = x + x_dir * world.session.random.randint(3, 9)
                    fish_y = y + y_dir * world.session.random.randint(3, 9)
                    # now we have the location, check if we can build here
                    if (fish_x, fish_y) in world.ground_map:
                        Build(FishDeposit,
                              fish_x,
                              fish_y,
                              world,
                              45 + world.session.random.randint(0, 3) * 90,
                              ownerless=True)(issuer=None)

    # TODO HACK BAD THING revert hack so trees don't start finished
    Tree.component_templates[1]['ProducerComponent']['start_finished'] = False
示例#9
0
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
示例#10
0
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()
示例#11
0
def add_nature_objects(world, natural_resource_multiplier):
	"""
	Place trees, wild animals, fish deposits, clay deposits, and mountains.

	@param natural_resource_multiplier: multiply the amount of fish deposits, clay deposits, and mountains by this.
	"""

	if not int(world.properties.get('RandomTrees', 1)):
		return

	add_resource_deposits(world, natural_resource_multiplier)
	Tree = Entities.buildings[BUILDINGS.TREE]
	FishDeposit = Entities.buildings[BUILDINGS.FISH_DEPOSIT]
	fish_directions = [(i, j) for i in xrange(-1, 2) for j in xrange(-1, 2)]

	# TODO HACK BAD THING hack the component template to make trees start finished
	Tree.component_templates[1]['ProducerComponent']['start_finished'] = True
	# add trees, wild animals, and fish
	for island in world.islands:
		for (x, y), tile in sorted(island.ground_map.iteritems()):
			# add trees based on adjacent trees
			for (dx, dy) in fish_directions:
				position = Point(x+dx, y+dy)
				newTile = world.get_tile(position)
				if newTile.object is not None and newTile.object.id == BUILDINGS.TREE and world.session.random.randint(0, 2) == 0 and Tree.check_build(world.session, tile, check_settlement=False):
					building = Build(Tree, x, y, island, 45 + world.session.random.randint(0, 3) * 90, ownerless=True)(issuer=None)
					if world.session.random.randint(0, WILD_ANIMAL.POPULATION_INIT_RATIO) == 0:
						CreateUnit(island.worldid, UNITS.WILD_ANIMAL, x, y)(issuer=None)
					if world.session.random.random() > WILD_ANIMAL.FOOD_AVAILABLE_ON_START:
						building.get_component(StorageComponent).inventory.alter(RES.WILDANIMALFOOD, -1)
				
				
			# add tree to every nth tile and an animal to one in every M trees
			if world.session.random.randint(0, 20) == 0 and \
			   Tree.check_build(world.session, tile, check_settlement=False):
				building = Build(Tree, x, y, island, 45 + world.session.random.randint(0, 3) * 90,
				                 ownerless=True)(issuer=None)
				if world.session.random.randint(0, WILD_ANIMAL.POPULATION_INIT_RATIO) == 0: # add animal to every nth tree
					CreateUnit(island.worldid, UNITS.WILD_ANIMAL, x, y)(issuer=None)
				if world.session.random.random() > WILD_ANIMAL.FOOD_AVAILABLE_ON_START:
					building.get_component(StorageComponent).inventory.alter(RES.WILDANIMALFOOD, -1)
			
			if 'coastline' in tile.classes and world.session.random.random() < natural_resource_multiplier / 4.0:
				# try to place fish: from the current position go to a random directions twice
				for (x_dir, y_dir) in world.session.random.sample(fish_directions, 2):
					# move a random amount in both directions
					fish_x = x + x_dir * world.session.random.randint(3, 9)
					fish_y = y + y_dir * world.session.random.randint(3, 9)
					# now we have the location, check if we can build here
					if (fish_x, fish_y) in world.ground_map:
						Build(FishDeposit, fish_x, fish_y, world,
						      45 + world.session.random.randint(0, 3) * 90,
						      ownerless=True)(issuer=None)

	# TODO HACK BAD THING revert hack so trees don't start finished
	Tree.component_templates[1]['ProducerComponent']['start_finished'] = False
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]
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]
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
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]
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
示例#17
0
def test_brick_production_chain(s, p):
	"""
	A brickyard makes bricks from clay. Clay is collected by a clay pit on a deposit.
	"""
	settlement, island = settle(s)

	assert Build(BUILDINGS.CLAY_DEPOSIT, 30, 30, island, ownerless=True)(None)
	assert Build(BUILDINGS.CLAY_PIT, 30, 30, island, settlement=settlement)(p)

	brickyard = Build(BUILDINGS.BRICKYARD, 30, 25, island, settlement=settlement)(p)
	assert brickyard.get_component(StorageComponent).inventory[RES.BRICKS] == 0
	assert brickyard.get_component(StorageComponent).inventory[RES.CLAY] == 0

	s.run(seconds=60) # 15s clay pit, 15s brickyard

	assert brickyard.get_component(StorageComponent).inventory[RES.BRICKS]
示例#18
0
def test_settler_level(s, p):
    """
	Verify that settler level up works.
	"""
    settlement, island = settle(s)

    settler = Build(BUILDINGS.RESIDENTIAL,
                    22,
                    22,
                    island,
                    settlement=settlement)(p)

    # make it happy
    inv = settler.get_component(StorageComponent).inventory
    to_give = inv.get_free_space_for(RES.HAPPINESS)
    inv.alter(RES.HAPPINESS, to_give)
    level = settler.level

    s.run(seconds=GAME.INGAME_TICK_INTERVAL)

    # give upgrade res
    inv.alter(RES.BOARDS, 100)

    s.run(seconds=GAME.INGAME_TICK_INTERVAL)

    # should have leveled up
    assert settler.level == level + 1
示例#19
0
def test_distillery(s, p):
	"""
	Distillery produces liquor out of sugar. A farm will collect raw sugar from a
	sugar field and produce sugar.
	"""
	settlement, island = settle(s)

	_build_farm(30, 30, BUILDINGS.SUGARCANE_FIELD, island, settlement, p)

	distillery = Build(BUILDINGS.DISTILLERY, 27, 30, island, settlement=settlement)(p)
	assert distillery
	assert distillery.get_component(StorageComponent).inventory[RES.LIQUOR] == 0

	s.run(seconds=60)	# sugarfield 30s, farm 1s, distillery 12s

	assert distillery.get_component(StorageComponent).inventory[RES.LIQUOR]
def create_lumberjack_production_session():
    """Create a saved game with a producing production and then load it."""
    session, player = new_session()
    settlement, island = settle(session)

    for x in [29, 30, 31, 32]:
        Build(
            BUILDINGS.TREE,
            x,
            29,
            island,
            settlement=settlement,
        )(player)
    building = Build(BUILDINGS.LUMBERJACK,
                     30,
                     30,
                     island,
                     settlement=settlement)(player)
    production = building.get_component(Producer).get_productions()[0]

    # wait for the lumberjack to start producing
    while True:
        if production.get_state() is PRODUCTION.STATES.producing:
            break
        session.run(ticks=1)

    fd1, filename1 = tempfile.mkstemp()
    os.close(fd1)
    assert session.save(savegamename=filename1)
    session.end(keep_map=True)

    # load the game
    session = load_session(filename1)
    return session
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]
示例#22
0
def test_settler_unhappy(session, player):
	settlement, island = settle(session)

	cb = mock.Mock()
	AddStatusIcon.subscribe(cb)

	settler = Build(BUILDINGS.RESIDENTIAL, 30, 30, island, settlement=settlement)(player)

	# certainly not unhappy
	assert settler.happiness > 0.45
	assert not cb.called

	# make it unhappy
	settler.get_component(StorageComponent).inventory.alter(RES.HAPPINESS, -settler.happiness)
	assert settler.happiness < 0.1
	assert_called_with_icon(cb, SettlerUnhappyStatus)
示例#23
0
def test_weaver(s, p):
	"""
	A weaver produces textiles from wool. A pasture provides lamb wool for a farm,
	which it converts to wool for the weaver.
	"""
	settlement, island = settle(s)

	_build_farm(30, 30, BUILDINGS.PASTURE, island, settlement, p)

	weaver = Build(BUILDINGS.WEAVER, 27, 30, island, settlement=settlement)(p)
	assert weaver
	assert weaver.get_component(StorageComponent).inventory[RES.TEXTILE] == 0

	s.run(seconds=60)	# pasture 30s, farm 1s, weaver 12s

	assert weaver.get_component(StorageComponent).inventory[RES.TEXTILE]
示例#24
0
def create_lumberjack_production_session():
    """Create a saved game with a producing production and then load it."""
    session, player = new_session()
    settlement, island = settle(session)

    for x in [29, 30, 31, 32]:
        Build(
            BUILDINGS.TREE,
            x,
            29,
            island,
            settlement=settlement,
        )(player)
    building = Build(BUILDINGS.LUMBERJACK,
                     30,
                     30,
                     island,
                     settlement=settlement)(player)
    production = building.get_component(Producer).get_productions()[0]

    # wait for the lumberjack to start producing
    while True:
        if production.get_state() is PRODUCTION.STATES.producing:
            break
        session.run(ticks=1)

    # Save and reload game
    session = saveload(session)
    return session
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]
def test_settler_unhappy(session, player):
    settlement, island = settle(session)

    cb = mock.Mock()
    AddStatusIcon.subscribe(cb)

    settler = Build(BUILDINGS.RESIDENTIAL, 30, 30, island, settlement=settlement)(player)

    # certainly not unhappy
    assert settler.happiness > 0.45
    assert not cb.called

    # make it unhappy
    settler.get_component(StorageComponent).inventory.alter(RES.HAPPINESS, -settler.happiness)
    assert settler.happiness < 0.1
    assert_called_with_icon(cb, SettlerUnhappyStatus)
示例#27
0
def test_distillery(s, p):
	"""
	Distillery produces liquor out of sugar. A farm will collect raw sugar from a
	sugar field and produce sugar.
	"""
	settlement, island = settle(s)

	_build_farm(30, 30, BUILDINGS.SUGARCANE_FIELD, island, settlement, p)

	distillery = Build(BUILDINGS.DISTILLERY, 27, 30, island, settlement=settlement)(p)
	assert distillery
	assert distillery.get_component(StorageComponent).inventory[RES.LIQUOR] == 0

	s.run(seconds=60)	# sugarfield 30s, farm 1s, distillery 12s

	assert distillery.get_component(StorageComponent).inventory[RES.LIQUOR]
def test_brick_production_chain(s, p):
	"""
	A brickyard makes bricks from clay. Clay is collected by a clay pit on a deposit.
	"""
	settlement, island = settle(s)

	assert Build(BUILDINGS.CLAY_DEPOSIT, 30, 30, island, ownerless=True)(None)
	assert Build(BUILDINGS.CLAY_PIT, 30, 30, island, settlement=settlement)(p)

	brickyard = Build(BUILDINGS.BRICKYARD, 30, 25, island, settlement=settlement)(p)
	assert brickyard.get_component(StorageComponent).inventory[RES.BRICKS] == 0
	assert brickyard.get_component(StorageComponent).inventory[RES.CLAY] == 0

	s.run(seconds=60) # 15s clay pit, 15s brickyard

	assert brickyard.get_component(StorageComponent).inventory[RES.BRICKS]
示例#29
0
def test_weaver(s, p):
    """
	A weaver produces textiles from wool. A pasture provides lamb wool for a farm,
	which it converts to wool for the weaver.
	"""
    settlement, island = settle(s)

    _build_farm(30, 30, BUILDINGS.PASTURE, island, settlement, p)

    weaver = Build(BUILDINGS.WEAVER, 27, 30, island, settlement=settlement)(p)
    assert weaver
    assert weaver.get_component(StorageComponent).inventory[RES.TEXTILE] == 0

    s.run(seconds=60)  # pasture 30s, farm 1s, weaver 12s

    assert weaver.get_component(StorageComponent).inventory[RES.TEXTILE]
def test_blender_production_chain(s, p):
	"""
	Spices are grown in spice fields and processed by the blender into condiments
	"""
	settlement, island = settle(s)

	assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
	assert Build(BUILDINGS.SPICE_FIELD, 26, 30, island, settlement=settlement)(p)

	blender = Build(BUILDINGS.BLENDER, 30, 26, island, settlement=settlement)(p)

	assert blender

	assert blender.get_component(StorageComponent).inventory[RES.CONDIMENTS] == 0
	assert blender.get_component(StorageComponent).inventory[RES.SPICES] == 0
	s.run(seconds=120) # 2x 30s spicefield, 15s blender
	assert blender.get_component(StorageComponent).inventory[RES.CONDIMENTS]
def test_brewery_production_chain(s, p):
	"""
	Hops are generated by hop fields and transferred to the brewery for beer production
	"""
	settlement, island = settle(s)

	assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
	assert Build(BUILDINGS.HOP_FIELD, 26, 30, island, settlement=settlement)(p)

	brewery = Build(BUILDINGS.BREWERY, 30, 26, island, settlement=settlement)(p)

	assert brewery

	assert brewery.get_component(StorageComponent).inventory[RES.HOPS] == 0
	assert brewery.get_component(StorageComponent).inventory[RES.BEER] == 0
	s.run(seconds=60) # 26s hop field, 12s brewery
	assert brewery.get_component(StorageComponent).inventory[RES.BEER]
def test_stonemason_production_chain(s, p):
	"""
	Stone tops are collected at a stone pit from a stone deposit and processed into bricks by a stonemason
	"""
	settlement, island = settle(s)

	assert Build(BUILDINGS.STONE_DEPOSIT, 30, 30, island, ownerless=True)(None)
	assert Build(BUILDINGS.STONE_PIT, 30, 30, island, settlement=settlement)(p)

	stonemason = Build(BUILDINGS.STONEMASON, 30, 25, island, settlement=settlement)(p)

	assert stonemason

	assert stonemason.get_component(StorageComponent).inventory[RES.STONE_TOPS] == 0
	assert stonemason.get_component(StorageComponent).inventory[RES.BRICKS] == 0
	s.run(seconds=60) # 15s stone pit, 30s stonemason
	assert stonemason.get_component(StorageComponent).inventory[RES.BRICKS]
def test_winery_production_chain(s, p):
	"""
	Grapes are grown in a vineyard processed into liquor at a winery
	"""
	settlement, island = settle(s)

	assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
	assert Build(BUILDINGS.VINEYARD, 26, 30, island, settlement=settlement)(p)

	winery = Build(BUILDINGS.WINERY, 30, 26, island, settlement=settlement)(p)

	assert winery

	assert winery.get_component(StorageComponent).inventory[RES.GRAPES] == 0
	assert winery.get_component(StorageComponent).inventory[RES.LIQUOR] == 0
	s.run(seconds=120) # 2x 30s vineyard, 15s winery
	assert winery.get_component(StorageComponent).inventory[RES.LIQUOR]
def test_winery_production_chain(s, p):
    """
	Grapes are grown in a vineyard processed into liquor at a winery
	"""
    settlement, island = settle(s)

    assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
    assert Build(BUILDINGS.VINEYARD, 26, 30, island, settlement=settlement)(p)

    winery = Build(BUILDINGS.WINERY, 30, 26, island, settlement=settlement)(p)

    assert winery

    assert winery.get_component(StorageComponent).inventory[RES.GRAPES] == 0
    assert winery.get_component(StorageComponent).inventory[RES.LIQUOR] == 0
    s.run(seconds=120)  # 2x 30s vineyard, 15s winery
    assert winery.get_component(StorageComponent).inventory[RES.LIQUOR]
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
示例#36
0
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 xrange(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_worldid = settler.worldid

        # make it happy
        inv = settler.get_component(StorageComponent).inventory
        to_give = inv.get_free_space_for(RES.HAPPINESS)
        inv.alter(RES.HAPPINESS, to_give)
        level = settler.level

        # wait for it to realize it's supposed to upgrade
        s.run(seconds=GAME.INGAME_TICK_INTERVAL)

        session = saveload(session)
        settler = WorldObject.get_object_by_id(settler_worldid)
        inv = settler.get_component(StorageComponent).inventory

        # continue
        s.run(seconds=GAME.INGAME_TICK_INTERVAL)

        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
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
def test_bakery_production_chain(s, p):
	"""
	Corn is grown in cornfields, milled into flour in a windmill and finally turned into food by a bakery
	"""
	settlement, island = settle(s)

	assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
	assert Build(BUILDINGS.CORN_FIELD, 26, 30, island, settlement=settlement)(p)
	assert Build(BUILDINGS.WINDMILL, 30, 34, island, settlement=settlement)(p)

	bakery = Build(BUILDINGS.BAKERY, 30, 26, island, settlement=settlement)(p)

	assert bakery

	assert bakery.get_component(StorageComponent).inventory[RES.FLOUR] == 0
	assert bakery.get_component(StorageComponent).inventory[RES.FOOD] == 0
	s.run(seconds=120) # 26s cornfield, 15s windmill, 15s bakery
	assert bakery.get_component(StorageComponent).inventory[RES.FOOD]
def test_distillery_production_chain(s, p):
	"""
	Raw sugar is generated by sugarcane fields and transferred to the distillery
	for liquor production
	"""
	settlement, island = settle(s)

	assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
	assert Build(BUILDINGS.SUGARCANE_FIELD, 26, 30, island, settlement=settlement)(p)

	distillery = Build(BUILDINGS.DISTILLERY, 30, 26, island, settlement=settlement)(p)

	assert distillery

	assert distillery.get_component(StorageComponent).inventory[RES.SUGAR] == 0
	assert distillery.get_component(StorageComponent).inventory[RES.LIQUOR] == 0
	s.run(seconds=60) # 30s sugarcane field, 12s distillery
	assert distillery.get_component(StorageComponent).inventory[RES.LIQUOR]
def test_tobbaconist_production_chain(s, p):
	"""
	Tobacco is generated by tobacco fields and transferred to the tobacconist for tobacco
	products making
	"""
	settlement, island = settle(s)

	assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
	assert Build(BUILDINGS.TOBACCO_FIELD, 26, 30, island, settlement=settlement)(p)

	tobacconist = Build(BUILDINGS.TOBACCONIST, 30, 26, island, settlement=settlement)(p)

	assert tobacconist

	assert tobacconist.get_component(StorageComponent).inventory[RES.TOBACCO_LEAVES] == 0
	assert tobacconist.get_component(StorageComponent).inventory[RES.TOBACCO_PRODUCTS] == 0
	s.run(seconds=120) # 30s tobacco field, 15s tobacconist
	assert tobacconist.get_component(StorageComponent).inventory[RES.TOBACCO_PRODUCTS]
def test_weaver_production_chain(s, p):
	"""
	Lamb wool is generated by sheep at a pasture to be later transferred to a weaver
	for textile production
	"""
	settlement, island = settle(s)

	assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
	assert Build(BUILDINGS.PASTURE, 26, 30, island, settlement=settlement)(p)

	weaver = Build(BUILDINGS.WEAVER, 30, 26, island, settlement=settlement)(p)

	assert weaver

	assert weaver.get_component(StorageComponent).inventory[RES.WOOL] == 0
	assert weaver.get_component(StorageComponent).inventory[RES.TEXTILE] == 0
	s.run(seconds=60) # 30s pasture, 30s weaver
	assert weaver.get_component(StorageComponent).inventory[RES.TEXTILE]
def test_brewery_production_chain(s, p):
    """
	Hops are generated by hop fields and transferred to the brewery for beer production
	"""
    settlement, island = settle(s)

    assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
    assert Build(BUILDINGS.HOP_FIELD, 26, 30, island, settlement=settlement)(p)

    brewery = Build(BUILDINGS.BREWERY, 30, 26, island,
                    settlement=settlement)(p)

    assert brewery

    assert brewery.get_component(StorageComponent).inventory[RES.HOPS] == 0
    assert brewery.get_component(StorageComponent).inventory[RES.BEER] == 0
    s.run(seconds=60)  # 26s hop field, 12s brewery
    assert brewery.get_component(StorageComponent).inventory[RES.BEER]
def test_weaver_production_chain(s, p):
    """
	Lamb wool is generated by sheep at a pasture to be later transferred to a weaver
	for textile production
	"""
    settlement, island = settle(s)

    assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
    assert Build(BUILDINGS.PASTURE, 26, 30, island, settlement=settlement)(p)

    weaver = Build(BUILDINGS.WEAVER, 30, 26, island, settlement=settlement)(p)

    assert weaver

    assert weaver.get_component(StorageComponent).inventory[RES.WOOL] == 0
    assert weaver.get_component(StorageComponent).inventory[RES.TEXTILE] == 0
    s.run(seconds=60)  # 30s pasture, 30s weaver
    assert weaver.get_component(StorageComponent).inventory[RES.TEXTILE]
def test_butchery_production_chain(s, p):
	"""
	Pigs and cattle are herded at a farm and processed into meat at the butchery
	"""
	settlement, island = settle(s)

	assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
	assert Build(BUILDINGS.CATTLE_RUN, 26, 30, island, settlement=settlement)(p)
	assert Build(BUILDINGS.PIGSTY, 30, 34, island, settlement=settlement)(p)

	butchery = Build(BUILDINGS.BUTCHERY, 30, 26, island, settlement=settlement)(p)

	assert butchery

	assert butchery.get_component(StorageComponent).inventory[RES.PIGS_SLAUGHTER] == 0
	assert butchery.get_component(StorageComponent).inventory[RES.CATTLE_SLAUGHTER] == 0
	assert butchery.get_component(StorageComponent).inventory[RES.FOOD] == 0
	s.run(seconds=200) # 40s cattlerun, 60s pigsty, 2x 15s butchery
	assert butchery.get_component(StorageComponent).inventory[RES.FOOD] >= 4 # each meat gives 2 units of food
def test_bakery_production_chain(s, p):
    """
	Corn is grown in cornfields, milled into flour in a windmill and finally turned into food by a bakery
	"""
    settlement, island = settle(s)

    assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
    assert Build(BUILDINGS.CORN_FIELD, 26, 30, island,
                 settlement=settlement)(p)
    assert Build(BUILDINGS.WINDMILL, 30, 34, island, settlement=settlement)(p)

    bakery = Build(BUILDINGS.BAKERY, 30, 26, island, settlement=settlement)(p)

    assert bakery

    assert bakery.get_component(StorageComponent).inventory[RES.FLOUR] == 0
    assert bakery.get_component(StorageComponent).inventory[RES.FOOD] == 0
    s.run(seconds=120)  # 26s cornfield, 15s windmill, 15s bakery
    assert bakery.get_component(StorageComponent).inventory[RES.FOOD]
def test_blender_production_chain(s, p):
    """
	Spices are grown in spice fields and processed by the blender into condiments
	"""
    settlement, island = settle(s)

    assert Build(BUILDINGS.FARM, 30, 30, island, settlement=settlement)(p)
    assert Build(BUILDINGS.SPICE_FIELD, 26, 30, island,
                 settlement=settlement)(p)

    blender = Build(BUILDINGS.BLENDER, 30, 26, island,
                    settlement=settlement)(p)

    assert blender

    assert blender.get_component(StorageComponent).inventory[
        RES.CONDIMENTS] == 0
    assert blender.get_component(StorageComponent).inventory[RES.SPICES] == 0
    s.run(seconds=120)  # 2x 30s spicefield, 15s blender
    assert blender.get_component(StorageComponent).inventory[RES.CONDIMENTS]
示例#47
0
def test_fisherman(s, p):
	"""
	A fisherman produces food out of fish, collecting in nearby fish deposits.
	"""
	settlement, island = settle(s)

	for x in (25, 30, 35):
		school = Build(BUILDINGS.FISH_DEPOSIT, x, 18, s.world, ownerless=True)(None)
		assert school
		school.get_component(Producer).finish_production_now()

	fisherman = Build(BUILDINGS.FISHER, 25, 20, island, settlement=settlement)(p)
	assert fisherman

	assert fisherman.get_component(StorageComponent).inventory[RES.FOOD] == 0
	assert fisherman.get_component(StorageComponent).inventory[RES.FISH] == 0

	s.run(seconds=20)

	assert fisherman.get_component(StorageComponent).inventory[RES.FOOD]
def test_fisherman(s, p):
	"""
	A fisherman produces food out of fish, collecting in nearby fish deposits.
	"""
	settlement, island = settle(s)

	for x in (25, 30, 35):
		school = Build(BUILDINGS.FISH_DEPOSIT, x, 18, s.world, ownerless=True)(None)
		assert school
		school.get_component(Producer).finish_production_now()

	fisherman = Build(BUILDINGS.FISHER, 25, 20, island, settlement=settlement)(p)
	assert fisherman

	assert fisherman.get_component(StorageComponent).inventory[RES.FOOD] == 0
	assert fisherman.get_component(StorageComponent).inventory[RES.FISH] == 0

	s.run(seconds=20)

	assert fisherman.get_component(StorageComponent).inventory[RES.FOOD]
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]
示例#50
0
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.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]
示例#51
0
def test_settler_level_save_load(s, p):
	"""
	Verify that settler level up with save/load works
	"""
	for test_level in xrange(3): # test upgrade 0->1, 1->2 and 2->3
		session, player = new_session()
		settlement, island = settle(s)

		settler = Build(BUILDINGS.RESIDENTIAL, 22, 22, island, settlement=settlement)(p)
		settler.level += test_level
		settler_worldid = settler.worldid

		# make it happy
		inv = settler.get_component(StorageComponent).inventory
		to_give = inv.get_free_space_for(RES.HAPPINESS)
		inv.alter(RES.HAPPINESS, to_give)
		level = settler.level

		# wait for it to realize it's supposed to upgrade
		s.run(seconds=GAME.INGAME_TICK_INTERVAL)

		session = saveload(session)
		settler = WorldObject.get_object_by_id(settler_worldid)
		inv = settler.get_component(StorageComponent).inventory

		# continue
		s.run(seconds=GAME.INGAME_TICK_INTERVAL)

		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
def test_cannonfoundry_production_chain(s, p):
    """
	The mine generates iron ore. The charcoal burner produces charcoal out of wooden boards.
	Later the smeltery produces iron ingots out of iron ore and charcoal. Finally, the cannon
	foundry makes cannons out of charcoal, iron ingots and wooden boards.
	"""
    settlement, island = settle(s)

    assert Build(BUILDINGS.MOUNTAIN, 30, 35, island, ownerless=True)(None)
    assert Build(BUILDINGS.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)

    cannonfoundry = Build(BUILDINGS.CANNON_FOUNDRY,
                          22,
                          32,
                          island,
                          settlement=settlement)(p)
    assert cannonfoundry
    cannonfoundry.get_component(StorageComponent).inventory.alter(
        RES.BOARDS, 10)  # give him boards directly

    assert cannonfoundry.get_component(StorageComponent).inventory[
        RES.CANNON] == 0
    s.run(seconds=150)
    assert cannonfoundry.get_component(StorageComponent).inventory[RES.CANNON]
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)
def test_lumberjack(s, p):
	"""
	Lumberjack will produce boards out of wood, collected from nearby trees.
	"""
	settlement, island = settle(s)

	jack = Build(BUILDINGS.LUMBERJACK, 30, 30, island, settlement=settlement)(p)
	assert jack

	assert jack.get_component(StorageComponent).inventory[RES.BOARDS] == 0
	assert jack.get_component(StorageComponent).inventory[RES.TREES] == 0

	for (x_off, y_off) in product([-2, 2], repeat=2):
		x = 30 + x_off
		y = 30 + y_off
		tree = Build(BUILDINGS.TREE, x, y, island, settlement=settlement)(p)
		assert tree
		tree.get_component(Producer).finish_production_now()

	s.run(seconds=20)

	assert jack.get_component(StorageComponent).inventory[RES.BOARDS]
示例#55
0
def test_lumberjack(s, p):
	"""
	Lumberjack will produce boards out of wood, collected from nearby trees.
	"""
	settlement, island = settle(s)

	jack = Build(BUILDINGS.LUMBERJACK, 30, 30, island, settlement=settlement)(p)
	assert jack

	assert jack.get_component(StorageComponent).inventory[RES.BOARDS] == 0
	assert jack.get_component(StorageComponent).inventory[RES.TREES] == 0

	for (x_off, y_off) in product([-2, 2], repeat=2):
		x = 30 + x_off
		y = 30 + y_off
		tree = Build(BUILDINGS.TREE, x, y, island, settlement=settlement)(p)
		assert tree
		tree.get_component(Producer).finish_production_now()

	s.run(seconds=30)

	assert jack.get_component(StorageComponent).inventory[RES.BOARDS]
示例#56
0
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)
def test_settler_unhappy(session, player):
	settlement, island = settle(session)
	assert isinstance(session, SPSession)

	called = [False]

	def add_icon(message):
		isinstance(message, AddStatusIcon)
		if message.icon.__class__ == SettlerUnhappyStatus:
			called.__setitem__(0, True)

	session.message_bus.subscribe_globally(AddStatusIcon, add_icon)

	settler = Build(BUILDINGS.RESIDENTIAL_CLASS, 30, 30, island, settlement=settlement)(player)

	# certainly not unhappy
	assert settler.happiness > 0.45
	assert not called[0]

	# make it unhappy
	settler.get_component(StorageComponent).inventory.alter(RES.HAPPINESS_ID, -settler.happiness)
	assert settler.happiness < 0.1
	assert called[0]
def test_stonemason_production_chain(s, p):
    """
	Stone tops are collected at a stone pit from a stone deposit and processed into bricks by a stonemason
	"""
    settlement, island = settle(s)

    assert Build(BUILDINGS.STONE_DEPOSIT, 30, 30, island, ownerless=True)(None)
    assert Build(BUILDINGS.STONE_PIT, 30, 30, island, settlement=settlement)(p)

    stonemason = Build(BUILDINGS.STONEMASON,
                       30,
                       25,
                       island,
                       settlement=settlement)(p)

    assert stonemason

    assert stonemason.get_component(StorageComponent).inventory[
        RES.STONE_TOPS] == 0
    assert stonemason.get_component(StorageComponent).inventory[
        RES.BRICKS] == 0
    s.run(seconds=60)  # 15s stone pit, 30s stonemason
    assert stonemason.get_component(StorageComponent).inventory[RES.BRICKS]
示例#59
0
def test_hunter(s, p):
    """
	Hunter will produce food from dear meat. No animals were harmed in this test.
	"""
    settlement, island = settle(s)

    hunter = Build(BUILDINGS.HUNTER, 30, 30, island, settlement=settlement)(p)
    assert hunter

    assert hunter.get_component(StorageComponent).inventory[RES.FOOD] == 0
    assert hunter.get_component(StorageComponent).inventory[RES.DEER_MEAT] == 0

    for (x_off, y_off) in product([-5, -4, 4, 5], repeat=2):
        x = 30 + x_off
        y = 30 + y_off
        animal = CreateUnit(island.worldid, UNITS.WILD_ANIMAL, x, y)(None)
        # wild animals are slow eaters, we feed them directly
        animal.get_component(StorageComponent).inventory.alter(12, 10)
        animal.get_component(Producer).finish_production_now()
        assert animal

    s.run(seconds=30)

    assert hunter.get_component(StorageComponent).inventory[RES.FOOD]