Exemplo n.º 1
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]
Exemplo n.º 2
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)
Exemplo n.º 3
0
def test_ticket_1561(s, p):
    settlement, island = settle(s)

    residence = Build(BUILDINGS.RESIDENTIAL,
                      30,
                      30,
                      island,
                      settlement=settlement)(p)
    s.run(ticks=1)
    assert residence.level == 0

    residence.level_up()
    s.run(ticks=1)
    assert residence.level == 1

    residence2 = Build(BUILDINGS.RESIDENTIAL,
                       30,
                       32,
                       island,
                       settlement=settlement)(p)
    s.run(ticks=1)
    assert residence2.level == 0
Exemplo n.º 4
0
def test_example(s, p):
	"""
	Build a farm and 2 pastures. Confirm raw wool is produced at the
	pastures and used by the farm to produce wool.
	"""
	settlement, island = settle(s)

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

	# Pause the production, we want to start it explicitly later.
	production = farm.get_component(Producer)._get_production(PRODUCTIONLINES.WOOL)
	production.pause()

	# Farm has no raw wool or wool.
	assert farm.get_component(StorageComponent).inventory[RES.LAMB_WOOL] == 0
	assert farm.get_component(StorageComponent).inventory[RES.WOOL] == 0

	# Build pastures, let the game run for 31 seconds. Pastures currently need
	# 30s to produce wool.
	p1 = Build(BUILDINGS.PASTURE, 27, 30, island, settlement=settlement)(p)
	p2 = Build(BUILDINGS.PASTURE, 33, 30, island, settlement=settlement)(p)
	assert p1 and p2

	s.run(seconds=31)

	assert p1.get_component(StorageComponent).inventory[RES.LAMB_WOOL]
	assert p2.get_component(StorageComponent).inventory[RES.LAMB_WOOL]

	# Give farm collectors a chance to get the wool from the pastures.
	s.run(seconds=5)

	assert farm.get_component(StorageComponent).inventory[RES.LAMB_WOOL]

	# Resume the production, let the game run for a second. The farm should have
	# produced wool now.
	production.pause(pause=False)
	s.run(seconds=1)
	assert farm.get_component(StorageComponent).inventory[RES.WOOL]
Exemplo n.º 5
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]
Exemplo n.º 6
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]
Exemplo n.º 7
0
    def make_ruin(self):
        """ Replaces itself with a ruin.
		"""
        command = Build(BUILDINGS.SETTLER_RUIN,
                        self.position.origin.x,
                        self.position.origin.y,
                        island=self.island,
                        settlement=self.settlement)

        # Remove the building and then place the Ruin
        Scheduler().add_new_object(Callback.ChainedCallbacks(
            self.remove, Callback(command, self.owner)),
                                   self,
                                   run_in=0)
Exemplo n.º 8
0
def test_ticket_1693(s, p):
	settlement, island = settle(s)

	residence = Build(BUILDINGS.RESIDENTIAL, 30, 30, island, settlement=settlement)(p)
	assert residence.level == 0

	# Run and wait until the settler levels down
	s.run(seconds=250)

	# get settler ruin
	tile = island.get_tile(Point(30, 30))
	ruin = tile.object

	assert ruin is not None
	assert isinstance(ruin, SettlerRuin)

	assert ruin.owner is not None
	assert ruin.tearable
	assert ruin.buildable_upon

	# Build another one on top of the ruin
	residence2 = Build(BUILDINGS.RESIDENTIAL, 30, 30, island, settlement=settlement)(p)
	assert residence2
Exemplo n.º 9
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)

	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
Exemplo n.º 10
0
def test_doctor_curing_chain(s, p):
    """
	Medical herbs are grown in herbaries and later used for curing the Black Death by the doctor
	"""
    settlement, island = settle(s)

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

    doctor = Build(BUILDINGS.DOCTOR, 30, 26, island, settlement=settlement)(p)

    assert doctor

    assert doctor.get_component(StorageComponent).inventory[
        RES.MEDICAL_HERBS] == 0
    assert doctor.get_component(StorageComponent).inventory[
        RES.BLACKDEATH] == 0

    # simulate a Black Death occurence
    doctor.get_component(StorageComponent).inventory.alter(RES.BLACKDEATH, 1)
    s.run(seconds=120)  # 2x 30s herbary, 60s doctor
    assert doctor.get_component(StorageComponent).inventory[RES.MEDICAL_HERBS]
    assert doctor.get_component(StorageComponent).inventory[
        RES.BLACKDEATH] == 0  # Black Death eliminated
Exemplo n.º 11
0
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
Exemplo n.º 12
0
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
Exemplo n.º 13
0
def test_productivity_low(session, player):
	settlement, island = settle(session)

	Build(BUILDINGS.CHARCOAL_BURNER, 30, 30, island, settlement=settlement)(player)

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

	# Not yet low
	assert not cb.called

	session.run(seconds=60)

	# Now low
	assert_called_with_icon(cb, ProductivityLowStatus)
Exemplo n.º 14
0
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
Exemplo n.º 15
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)
Exemplo n.º 16
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]
Exemplo n.º 17
0
def test_tree_production(s, p):
    """Check whether trees produce wood"""
    settlement, island = settle(s)
    tree = Build(BUILDINGS.TREE, 30, 35, island, settlement=settlement)(p)

    n = 20

    inv = tree.get_component(StorageComponent).inventory
    for i in xrange(n):  # we want n units

        while not inv[RES.TREES]:
            s.run(seconds=5)

        # take one away to free storage space
        #from tests import set_trace ; set_trace()
        inv.alter(RES.TREES, -1)
Exemplo n.º 18
0
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]
Exemplo n.º 19
0
    def remove(self):
        # build the deposit back here after remove() is finished
        deposit_build_data = {
            'inventory':
            self.get_component(StorageComponent).inventory.get_dump()
        }
        build_cmd = Build(self.__deposit_class,
                          self.position.origin.x,
                          self.position.origin.y,
                          self.island,
                          rotation=self.rotation,
                          ownerless=True,
                          data=deposit_build_data)
        Scheduler().add_new_object(build_cmd, build_cmd, run_in=0)

        super(Mine, self).remove()
Exemplo n.º 20
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]
Exemplo n.º 21
0
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
Exemplo n.º 22
0
def new_settlement(session, pos=Point(30, 20)):
	"""
	Creates a settlement at the given position. It returns the settlement and the island
	where it was created on, to avoid making function-baed tests too verbose.
	"""
	island = session.world.get_island(pos)
	assert island, "No island found at %s" % pos
	player = session.world.player

	ship = CreateUnit(player.worldid, UNITS.PLAYER_SHIP, pos.x, pos.y)(player)
	for res, amount in session.db("SELECT resource, amount FROM start_resources"):
		ship.get_component(StorageComponent).inventory.alter(res, amount)

	building = Build(BUILDINGS.WAREHOUSE, pos.x, pos.y, island, ship=ship)(player)
	assert building, "Could not build warehouse at %s" % pos

	return (building.settlement, island)
Exemplo n.º 23
0
def test_deny_upgrade_permissions_special(s, p):
    """
	Verify that denying upgrade permissions works even though the settler
	leveled down after starting the upgrade process.
	"""
    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)

    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 == TIER.PIONEERS
    assert settler._upgrade_production is None

    # Start leveling up again
    settler._add_upgrade_production_line()
    assert settler._upgrade_production is not None

    s.run(seconds=1)

    # Force the settler to level down, even though it is currently
    # trying to upgrade
    settler.level_down()

    # Make sure this worked!
    assert settler._upgrade_production is None

    # Make sure forbidding upgrades works
    SetSettlementUpgradePermissions(settlement, TIER.SAILORS, False).execute(s)
    assert settler.level == TIER.SAILORS
Exemplo n.º 24
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
Exemplo n.º 25
0
	def execute(self, land_manager, ship=None):
		"""Build the building."""
		building_class = Entities.buildings[self.building_id]
		building_level = building_class.get_initial_level(land_manager.owner)
		action_set_id = building_class.get_random_action_set(level = building_level)

		build_position = Entities.buildings[self.building_id].check_build(land_manager.session,
		    Point(*self.coords), rotation=self.rotations[self.orientation],
		    check_settlement=(ship is None), ship=ship, issuer=land_manager.owner)
		assert build_position.buildable

		cmd = Build(self.building_id, self.coords[0], self.coords[1], land_manager.island,
			self._get_rotation(land_manager.session, build_position.rotation),
			settlement=land_manager.settlement, ship=ship, tearset=build_position.tearset,
			action_set_id=action_set_id)
		result = cmd(land_manager.owner)
		assert result
		return result
Exemplo n.º 26
0
def test_build_tear(s, p):
    """
	Build stuff and tear it later
	"""
    settlement, island = settle(s)
    tree = Build(BUILDINGS.TREE, 30, 35, island, settlement=settlement)(p)

    s.run(seconds=1)

    wid = tree.worldid
    Tear(tree)(p)

    try:
        WorldObject.get_object_by_id(wid)
    except WorldObjectNotFound:
        pass  # should be gone
    else:
        assert False
Exemplo n.º 27
0
def test_inventory_full(session, player):
	settlement, island = settle(session)

	lj = Build(BUILDINGS.LUMBERJACK, 30, 30, island, settlement=settlement)(player)

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

	# Not full
	assert not cb.called

	inv = lj.get_component(StorageComponent).inventory
	res = RES.BOARDS
	inv.alter(res, inv.get_free_space_for( res ) )

	session.run(seconds=1)

	# Full
	assert_called_with_icon(cb, InventoryFullStatus)
Exemplo n.º 28
0
	def level_down(self):
		if self.level == 0: # can't level down any more
			# remove when this function is done
			Scheduler().add_new_object(self.remove, self, run_in=0)
			# replace this building with a ruin
			command = Build(BUILDINGS.SETTLER_RUIN_CLASS, self.position.origin.x, \
			                self.position.origin.y, island=self.island, settlement=self.settlement)
			Scheduler().add_new_object(command, command, run_in=0)

			self.log.debug("%s: Destroyed by lack of happiness", self)
			if self.owner == self.session.world.player:
				self.session.ingame_gui.message_widget.add(self.position.center().x, self.position.center().y, \
			                                           'SETTLERS_MOVED_OUT')
		else:
			self.level -= 1
			self._update_level_data()
			# reset happiness value for new level
			self.inventory.alter(RES.HAPPINESS_ID, self.__get_data("happiness_init_value") - self.happiness)
			self.log.debug("%s: Level down to %s", self, self.level)
			self._changed()
Exemplo n.º 29
0
    def execute(self):
        """Build the building."""
        building_class = Entities.buildings[self.building_id]
        building_level = building_class.get_initial_level(
            self.land_manager.owner)
        action_set_id = building_class.get_random_action_set(
            level=building_level)

        cmd = Build(self.building_id,
                    self.point.x,
                    self.point.y,
                    self.land_manager.island,
                    self._get_rotation(),
                    settlement=self.land_manager.settlement,
                    ship=self.ship,
                    tearset=self.build_position.tearset,
                    action_set_id=action_set_id)
        result = cmd(self.land_manager.owner)
        #self.log.debug('%s.execute(): %s', self.__class__.__name__, result)
        return result
Exemplo n.º 30
0
def test_fire_station(s):
    """
	Check if a fire station stops fires.
	"""
    dis_man = s.world.disaster_manager
    settlement = s.world.player.settlements[0]
    # need this so that fires can break out
    s.world.player.settler_level = 1

    inv = settlement.get_component(StorageComponent).inventory
    # res for fire station
    inv.alter(RES.BOARDS, 10)
    inv.alter(RES.TOOLS, 10)
    inv.alter(RES.BRICKS, 10)

    # second lj is the pos we need
    lj = settlement.buildings_by_id[BUILDINGS.LUMBERJACK][1]
    pos = lj.position.origin
    owner = lj.owner
    island = lj.island

    Tear(lj)(owner)
    assert Build(BUILDINGS.FIRE_STATION,
                 pos.x,
                 pos.y,
                 island,
                 settlement=settlement)(owner)

    assert settlement.buildings_by_id[BUILDINGS.RESIDENTIAL]
    old_num = len(settlement.buildings_by_id[BUILDINGS.RESIDENTIAL])

    for i in xrange(5):  # 5 fires
        while not dis_man._active_disaster:
            dis_man.run()  # try to seed until we have a fire

        # wait until fire is over
        while dis_man._active_disaster:
            s.run()

    # in this simple case, the fire station should be 100% effective
    assert len(settlement.buildings_by_id[BUILDINGS.RESIDENTIAL]) == old_num