예제 #1
0
def test_ticket_1369(gui):
	"""
	Ship tab closed when moving away from another player's warehouse after trading.
	"""

	ship = get_player_ship(gui.session)
	gui.select([ship])

	# ally players so they can trade
	world = gui.session.world
	for player in world.players:
		if player is not ship.owner:
			world.diplomacy.add_ally_pair( ship.owner, player )

	# move ship near foreign warehouse and wait for it to arrive
	move_ship(gui, ship, (68, 23))

	# click trade button
	gui.trigger('overview_trade_ship', 'trade')

	# trade widget visible
	assert gui.find(name='buy_sell_goods')

	# move ship away from warehouse
	move_ship(gui, ship, (77, 17))

	# trade widget should not be visible anymore
# For now, the trade widget will stay visible.
#	assert gui.find(name='buy_sell_goods') is None

	# but the ship overview should be
	assert gui.find(name='buy_sell_goods')
예제 #2
0
def test_mission1(gui):
	"""Sample mission which requires multiple buildings to win."""

	# Move ship to coast
	ship = get_player_ship(gui.session)
	gui.select([ship])
	move_ship(gui, ship, (7, 3))

	# Build warehouse
	gui.select([ship])
	gui.trigger('overview_trade_ship', 'found_settlement')
	gui.cursor_click(10, 5, 'left')
	assert_goal_reached(gui, 'warehouse')

	# Build main square
	gui.trigger('mainhud', 'build')
	gui.trigger('tab', 'button_02')
	gui.cursor_click(9, 11, 'left')
	assert_goal_reached(gui, 'mainsquare')

	# Build fisher
	gui.trigger('tab', 'button_33')
	gui.cursor_click(7, 7, 'left')

	assert_win(gui)
예제 #3
0
def test_ticket_1369(gui):
    """
	Ship tab closed when moving away from another player's warehouse after trading.
	"""

    ship = get_player_ship(gui.session)
    gui.select([ship])

    # ally players so they can trade
    world = gui.session.world
    for player in world.players:
        if player is not ship.owner:
            world.diplomacy.add_ally_pair(ship.owner, player)

    # move ship near foreign warehouse and wait for it to arrive
    move_ship(gui, ship, (68, 23))

    # click trade button
    gui.trigger('overview_trade_ship/trade')

    # trade widget visible
    assert gui.find(name='buy_sell_goods')

    # move ship away from warehouse
    move_ship(gui, ship, (77, 17))

    # trade widget should not be visible anymore
    # For now, the trade widget will stay visible.
    #	assert gui.find(name='buy_sell_goods') is None

    # but the ship overview should be
    assert gui.find(name='buy_sell_goods')
def test_mission1(gui):
    """Sample mission which requires multiple buildings to win."""

    # Move ship to coast
    ship = get_player_ship(gui.session)
    gui.select([ship])
    move_ship(gui, ship, (7, 3))

    # Build warehouse
    gui.select([ship])
    gui.trigger("overview_trade_ship/found_settlement")
    gui.cursor_click(10, 5, "left")
    assert_goal_reached(gui, "warehouse")

    # Build main square
    gui.trigger("mainhud/build")
    gui.trigger("tab/button_02")
    gui.cursor_click(9, 11, "left")
    assert_goal_reached(gui, "mainsquare")

    # Build fisher
    gui.trigger("tab/button_23")
    gui.cursor_click(7, 7, "left")

    assert_win(gui)
예제 #5
0
def test_mission1(gui):
	"""Sample mission which requires multiple buildings to win."""

	# Move ship to coast
	ship = get_player_ship(gui.session)
	gui.select([ship])
	move_ship(gui, ship, (7, 3))

	# Build warehouse
	gui.select([ship])
	gui.trigger('overview_trade_ship', 'found_settlement')
	gui.cursor_click(10, 5, 'left')
	assert_goal_reached(gui, 'warehouse')

	# Build main square
	gui.trigger('mainhud', 'build')
	gui.trigger('tab', 'button_02')
	gui.cursor_click(9, 11, 'left')
	assert_goal_reached(gui, 'mainsquare')

	# Build fisher
	gui.trigger('tab', 'button_33')
	gui.cursor_click(7, 7, 'left')

	assert_win(gui)
예제 #6
0
def test_trade(gui):
	"""
	"""

	ship = get_player_ship(gui.session)
	gui.select([ship])

	# ally players so they can trade
	world = gui.session.world
	for player in world.players:
		if player is not ship.owner:
			world.diplomacy.add_ally_pair( ship.owner, player )

	# move ship near foreign warehouse and wait for it to arrive
	move_ship(gui, ship, (68, 23))

	# click trade button
	gui.trigger('overview_trade_ship', 'trade')

	# trade widget visible
	assert gui.find(name='buy_sell_goods')

	ship_inv = ship.get_component(StorageComponent).inventory
	settlement = gui.session.world.islands[0].settlements[0]
	settlement_inv = settlement.get_component(StorageComponent).inventory

	# transfer 1 t
	gui.trigger('buy_sell_goods', 'size_1')

	old_ship_value = ship_inv[RES.BOARDS]
	old_settlement_value = settlement_inv[RES.BOARDS]

	# of boards (will be bought)
	gui.trigger('buy_sell_goods', 'inventory_entry_0')

	assert old_settlement_value + 1 == settlement_inv[RES.BOARDS]
	assert old_ship_value - 1 == ship_inv[RES.BOARDS]

	old_ship_value = ship_inv[RES.CANNON]
	old_settlement_value = settlement_inv[RES.CANNON]

	# now cannons (won't be bought)
	gui.trigger('buy_sell_goods', 'inventory_entry_3')

	assert old_settlement_value == settlement_inv[RES.CANNON]
	assert old_ship_value == ship_inv[RES.CANNON]

	# the ai has to want more boards
	trade_post = settlement.get_component(TradePostComponent)
	assert settlement_inv[RES.BOARDS] < trade_post.slots[trade_post.buy_list[RES.BOARDS]].limit

	# transfer 50 t of boards
	gui.trigger('buy_sell_goods', 'size_5')
	gui.trigger('buy_sell_goods', 'inventory_entry_0')

	# now it has enough
	assert settlement_inv[RES.BOARDS] == trade_post.slots[trade_post.buy_list[RES.BOARDS]].limit

	old_ship_value = ship_inv[RES.BOARDS]

	# so another click won't do anything
	gui.trigger('buy_sell_goods', 'inventory_entry_0')

	assert old_ship_value == ship_inv[RES.BOARDS]

	# no matter how small the amount
	gui.trigger('buy_sell_goods', 'size_1')
	gui.trigger('buy_sell_goods', 'inventory_entry_0')

	assert old_ship_value == ship_inv[RES.BOARDS]

	# make room on ship inventory
	ship_inv.alter(RES.BOARDS, - ship_inv[RES.BOARDS])

	# test sell now, give settlement something to sell
	SetTradeSlot(trade_post, 2, RES.ALVEARIES, True, 5)(settlement.owner)
	settlement.get_component(StorageComponent).inventory.alter(RES.ALVEARIES, 10)

	# this gives us 5 alevaries
	assert ship_inv[RES.ALVEARIES] == 0
	# first transfer one
	gui.trigger('buy_sell_goods', 'size_1')
	gui.trigger('buy_sell_goods', 'buy_sell_inventory_True_entry_1')

	print ship_inv[RES.ALVEARIES]
	assert ship_inv[RES.ALVEARIES] == 1
	assert settlement_inv[RES.ALVEARIES] == 9

	# now transfer 5, should actually transfer 4
	gui.trigger('buy_sell_goods', 'size_2')
	gui.trigger('buy_sell_goods', 'buy_sell_inventory_True_entry_1')
	assert ship_inv[RES.ALVEARIES] == 5
	assert settlement_inv[RES.ALVEARIES] == 5
예제 #7
0
def test_tutorial(gui):
    """Test the tutorial scenario."""

    # FIXME disable disasters (this should be an option for a scenario)
    gui.session.world.disaster_manager.disabled = True

    def assert_progress(progress):
        wait_and_close_logbook(gui)
        assert var_eq(gui.session, 'tutorial_progress', progress)

    # Tutorial start
    assert_progress(16)

    # Goal: Build warehouse
    ship = get_player_ship(gui.session)
    gui.select([ship])
    move_ship(gui, ship, (11, 1))

    # Save and reload scenario (1/3)
    saveload(gui)

    gui.trigger('overview_trade_ship/found_settlement')
    gui.cursor_click(11, 6, 'left')

    # Goal: Build a lumberjack
    assert_progress(19)

    # lumberjack (2)
    gui.trigger('mainhud/build')
    gui.trigger('tab/button_03')
    gui.cursor_click(8, 10, 'left', shift=True)
    gui.cursor_click(13, 10, 'left')
    gui.cursor_click(13, 10, 'right')

    # plant some extra trees around the lumberjacks
    gui.trigger('tab/button_13')
    gui.cursor_drag((6, 13), (15, 8), 'left')

    # roads (no dragging to trigger the 'you can drag roads' hint)
    gui.trigger('tab/button_21')
    gui.cursor_multi_click((10, 8), (10, 9), (10, 10), (11, 10))

    # Goal: Build hunter and fisher
    assert_progress(22)

    # fisher
    gui.trigger('tab/button_23')
    gui.cursor_click(13, 6, 'left')

    # hunter
    gui.trigger('tab/button_13')
    gui.cursor_click(8, 8, 'left')

    # Goal: Mainsquare
    assert_progress(25)

    gui.trigger('tab/button_02')
    gui.cursor_click(15, 18, 'left')

    # Goal: first tent
    assert_progress(28)

    # roads
    gui.trigger('tab/button_21')
    gui.cursor_drag((13, 15), (20, 15), 'left')
    gui.cursor_click(20, 15, 'right')

    # tent
    gui.trigger('tab/button_01')
    gui.cursor_click(13, 13, 'left')

    # Goal: 4 tents
    assert_progress(31)

    gui.trigger('tab/button_01')
    gui.cursor_multi_click((15, 13), (17, 13), (19, 13))

    # Goal: Build a signal fire
    assert_progress(34)

    # Save and reload scenario (2/3)
    saveload(gui)

    # Open build menu again (it is not reloaded, unlike selected instances)
    gui.trigger('mainhud/build')
    gui.trigger('tab_base/0')

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 5):
        gui.run()

    gui.trigger('tab/button_22')
    gui.cursor_click(9, 5, 'left')

    # Goal: Trading
    assert_progress(37)

    # Buy tools from the trader (put the resource on the buy list)
    gui.cursor_click(11, 6, 'left')
    gui.trigger('tab_base/2')
    gui.trigger('slot_0/button', mouse='left')
    gui.trigger('select_trade_resource/resource_%d' % RES.TOOLS)
    gui.find('slot_0/slider').slide(30)

    # Goal: Pavilion
    assert_progress(40)

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 5):
        gui.run()

    gui.trigger('mainhud/build')
    gui.trigger('tab/button_12')
    gui.cursor_click(19, 16, 'left')

    # Goal: Next tier
    assert_progress(43)

    # Adjust settler taxes (using mainsquare)
    gui.cursor_click(16, 18, 'left')
    gui.trigger('tab_base/1')
    gui.find('tax_slider').slide(0)
    gui.trigger('mainhud/build')

    # wait until settlers upgraded
    while not settler_level_greater(gui.session, TIER.SAILORS):
        gui.run()

    # Goal: Farm
    assert_progress(46)

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 10):
        gui.run()

    gui.trigger('tab_base/1')  # FIXME this sometimes fails
    gui.trigger('tab/button_02')
    gui.cursor_click(25, 12, 'left')

    # Goal: Fields
    assert_progress(49)

    gui.trigger('tab_base/1')

    # potato
    gui.trigger('tab/button_12')
    gui.cursor_click(23, 11, 'left')

    # Save and reload scenario (3/3)
    saveload(gui)

    # Open build menu again
    gui.trigger('mainhud/build')
    gui.trigger('tab_base/1')

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 3):
        gui.run()

    # pasture
    gui.trigger('tab/button_22')
    gui.cursor_click(24, 8, 'left')

    # Goal: Storage
    assert_progress(52)

    # remove a tree to connect to farm
    gui.trigger('mainhud/destroy_tool')
    gui.cursor_click(21, 15, 'left')

    # roads
    gui.trigger('mainhud/build')
    gui.trigger('tab_base/0')
    gui.trigger('tab/button_21')
    gui.cursor_drag((21, 15), (24, 14), 'left')
    gui.cursor_click(24, 14, 'right')
    # back of mainsquare
    gui.trigger('tab/button_21')
    gui.cursor_drag((13, 22), (20, 22), 'left')
    gui.cursor_click(20, 22, 'right')

    # storage tent
    gui.trigger('tab/button_11')
    gui.cursor_click(21, 16, 'left')

    # Goal: Weaver
    assert_progress(55)

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 10):
        gui.run()

    gui.trigger('tab_base/1')
    gui.trigger('tab/button_21')
    gui.cursor_click(25, 14, 'left')

    # Goal: 50 inhabitants, positive balance
    assert_progress(58)

    # more potato fields
    gui.trigger('tab_base/1')
    gui.trigger('tab/button_12')
    gui.cursor_multi_click((24, 9), (27, 8), (27, 11))

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 39):
        gui.run()

    # tents
    gui.trigger('tab_base/0')
    gui.trigger('tab/button_01')
    gui.cursor_multi_click((11, 14), (11, 15), (12, 17), (11, 20), (11, 22),
                           (13, 23), (15, 23), (17, 23), (19, 23), (19, 20),
                           (22, 15), (19, 18), (20, 21))

    # Goal: Won
    assert_progress(61)

    assert_win(gui)
예제 #8
0
def test_tutorial(gui):
    """Test the tutorial scenario."""

    # FIXME disable disasters (this should be an option for a scenario)
    gui.session.world.disaster_manager.disabled = True

    def assert_progress(progress):
        wait_and_close_logbook(gui)
        assert var_eq(gui.session, "tutorial_progress", progress)

        # Tutorial start

    assert_progress(16)

    # Goal: Build warehouse
    ship = get_player_ship(gui.session)
    move_ship(ship, (11, 1))

    gui.select([ship])
    gui.trigger("overview_trade_ship", "found_settlement")
    gui.cursor_click(11, 6, "left")

    # Goal: Build a lumberjack
    assert_progress(19)

    # lumberjack
    gui.trigger("mainhud", "build")
    gui.trigger("tab", "button_03")
    gui.cursor_click(8, 10, "left")

    # roads
    gui.trigger("tab", "button_21")
    gui.cursor_multi_click((10, 8), (10, 9), (10, 10))

    # Goal: Build hunter and fisher
    assert_progress(22)

    # fisher
    gui.trigger("tab", "button_33")
    gui.cursor_click(13, 6, "left")

    # hunter
    gui.trigger("tab", "button_23")
    gui.cursor_click(8, 8, "left")

    # Goal: Mainsquare
    assert_progress(25)

    gui.trigger("tab", "button_02")
    gui.cursor_click(15, 18, "left")

    # Goal: first tent
    assert_progress(28)

    # roads
    gui.trigger("tab", "button_21")
    gui.cursor_multi_click((13, 15), (14, 15), (16, 15), (17, 15), (18, 15), (19, 15), (20, 15))

    # tent
    gui.trigger("tab", "button_01")
    gui.cursor_click(13, 13, "left")

    # Goal: 4 tents
    assert_progress(31)

    gui.trigger("tab", "button_01")
    gui.cursor_multi_click((15, 13), (17, 13), (19, 13))

    # Goal: Build a signal fire
    assert_progress(34)

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 5):
        gui.run()

    gui.trigger("tab", "button_22")
    gui.cursor_click(9, 5, "left")

    # Goal: Trading
    assert_progress(37)

    # TODO do this with the gui (needs named buttons and a way to control the slider)
    player = gui.session.world.player
    tradepost = player.settlements[0].get_component(TradePostComponent)
    AddToBuyList(tradepost, RES.TOOLS, 30)(player)

    # Goal: Pavilion
    assert_progress(40)

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 5):
        gui.run()

    gui.trigger("tab", "button_12")
    gui.cursor_click(19, 16, "left")

    # Goal: Next tier
    assert_progress(43)

    # TODO adjust settler taxes

    # wait until settlers upgraded
    while not settler_level_greater(gui.session, TIER.SAILORS):
        gui.run()

        # Goal: Farm
    assert_progress(46)

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 10):
        gui.run()

    gui.trigger("tab_base", "1")  # FIXME this sometimes fails
    gui.trigger("tab", "button_02")
    gui.cursor_click(25, 12, "left")

    # Goal: Fields
    assert_progress(49)

    gui.trigger("tab_base", "1")

    # potato
    gui.trigger("tab", "button_12")
    gui.cursor_click(23, 11, "left")

    # pasture
    gui.trigger("tab", "button_22")
    gui.cursor_click(21, 10, "left")

    # Goal: Storage
    assert_progress(52)

    # remove a tree to connect to farm
    gui.trigger("mainhud", "destroy_tool")
    gui.cursor_click(21, 15, "left")

    # roads
    gui.trigger("mainhud", "build")
    gui.trigger("tab_base", "0")
    gui.trigger("tab", "button_21")
    gui.cursor_multi_click((21, 15), (22, 15), (23, 15), (24, 15), (24, 14))

    # storage tent
    gui.trigger("tab", "button_11")
    gui.cursor_click(21, 16, "left")

    # Goal: Weaver
    assert_progress(55)

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 10):
        gui.run()

    gui.trigger("tab_base", "1")
    gui.trigger("tab", "button_21")
    gui.cursor_click(25, 14, "left")

    # Goal: 50 inhabitants, positive balance
    assert_progress(58)

    # more potatoe fields
    gui.trigger("tab_base", "1")
    gui.trigger("tab", "button_12")
    gui.cursor_multi_click((24, 9), (27, 8), (27, 11))

    # lumberjack (more wood for upgrades)
    gui.trigger("tab_base", "0")
    gui.trigger("tab", "button_03")
    gui.cursor_click(19, 18, "left")

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 39):
        gui.run()

        # tents
    gui.trigger("tab", "button_01")
    gui.cursor_multi_click(
        (11, 14), (11, 15), (12, 17), (11, 20), (12, 22), (14, 22), (16, 22), (18, 22), (19, 20), (22, 15)
    )

    # Goal: Won
    assert_progress(61)

    assert_win(gui)
예제 #9
0
def test_tutorial(gui):
    """Test the tutorial scenario."""

    # FIXME disable disasters (this should be an option for a scenario)
    gui.session.world.disaster_manager.disabled = True

    def assert_progress(progress):
        wait_and_close_logbook(gui)
        assert var_eq(gui.session, 'tutorial_progress', progress)

    # Tutorial start
    assert_progress(16)

    # Goal: Build warehouse
    ship = get_player_ship(gui.session)
    move_ship(ship, (11, 1))

    gui.select([ship])
    gui.trigger('overview_trade_ship', 'found_settlement')
    gui.cursor_click(11, 6, 'left')

    # Goal: Build a lumberjack
    assert_progress(19)

    # lumberjack (2)
    gui.trigger('mainhud', 'build')
    gui.trigger('tab', 'button_03')
    gui.cursor_click(8, 10, 'left', shift=True)
    gui.cursor_click(13, 10, 'left')
    gui.cursor_click(13, 10, 'right')

    # roads
    gui.trigger('tab', 'button_21')
    gui.cursor_multi_click((10, 8), (10, 9), (10, 10), (11, 10))

    # Goal: Build hunter and fisher
    assert_progress(22)

    # fisher
    gui.trigger('tab', 'button_33')
    gui.cursor_click(13, 6, 'left')

    # hunter
    gui.trigger('tab', 'button_23')
    gui.cursor_click(8, 8, 'left')

    # Goal: Mainsquare
    assert_progress(25)

    gui.trigger('tab', 'button_02')
    gui.cursor_click(15, 18, 'left')

    # Goal: first tent
    assert_progress(28)

    # roads
    gui.trigger('tab', 'button_21')
    gui.cursor_multi_click((13, 15), (14, 15), (16, 15), (17, 15), (18, 15),
                           (19, 15), (20, 15))

    # tent
    gui.trigger('tab', 'button_01')
    gui.cursor_click(13, 13, 'left')

    # Goal: 4 tents
    assert_progress(31)

    gui.trigger('tab', 'button_01')
    gui.cursor_multi_click((15, 13), (17, 13), (19, 13))

    # Goal: Build a signal fire
    assert_progress(34)

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 5):
        gui.run()

    gui.trigger('tab', 'button_22')
    gui.cursor_click(9, 5, 'left')

    # Goal: Trading
    assert_progress(37)

    # TODO do this with the gui (needs named buttons and a way to control the slider)
    player = gui.session.world.player
    tradepost = player.settlements[0].get_component(TradePostComponent)
    SetTradeSlot(tradepost, 0, RES.TOOLS, False, 30)(player)

    # Goal: Pavilion
    assert_progress(40)

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 5):
        gui.run()

    gui.trigger('tab', 'button_12')
    gui.cursor_click(19, 16, 'left')

    # Goal: Next tier
    assert_progress(43)

    # TODO adjust settler taxes

    # wait until settlers upgraded
    while not settler_level_greater(gui.session, TIER.SAILORS):
        gui.run()

    # Goal: Farm
    assert_progress(46)

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 10):
        gui.run()

    gui.trigger('tab_base', '1')  # FIXME this sometimes fails
    gui.trigger('tab', 'button_02')
    gui.cursor_click(25, 12, 'left')

    # Goal: Fields
    assert_progress(49)

    gui.trigger('tab_base', '1')

    # potato
    gui.trigger('tab', 'button_12')
    gui.cursor_click(23, 11, 'left')

    # pasture
    gui.trigger('tab', 'button_22')
    gui.cursor_click(21, 10, 'left')

    # Goal: Storage
    assert_progress(52)

    # remove a tree to connect to farm
    gui.trigger('mainhud', 'destroy_tool')
    gui.cursor_click(21, 15, 'left')

    # roads
    gui.trigger('mainhud', 'build')
    gui.trigger('tab_base', '0')
    gui.trigger('tab', 'button_21')
    gui.cursor_multi_click((21, 15), (22, 15), (23, 15), (24, 15), (24, 14))

    # storage tent
    gui.trigger('tab', 'button_11')
    gui.cursor_click(21, 16, 'left')

    # Goal: Weaver
    assert_progress(55)

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 10):
        gui.run()

    gui.trigger('tab_base', '1')
    gui.trigger('tab', 'button_21')
    gui.cursor_click(25, 14, 'left')

    # Goal: 50 inhabitants, positive balance
    assert_progress(58)

    # more potatoe fields
    gui.trigger('tab_base', '1')
    gui.trigger('tab', 'button_12')
    gui.cursor_multi_click((24, 9), (27, 8), (27, 11))

    # lumberjack (more wood for upgrades)
    gui.trigger('tab_base', '0')
    gui.trigger('tab', 'button_03')
    gui.cursor_click(19, 18, 'left')

    # wait until we have enough boards
    while not settlement_res_stored_greater(gui.session, RES.BOARDS, 39):
        gui.run()

    # tents
    gui.trigger('tab', 'button_01')
    gui.cursor_multi_click((11, 14), (11, 15), (12, 17), (11, 20), (12, 22),
                           (14, 22), (16, 22), (18, 22), (19, 20), (22, 15))

    # Goal: Won
    assert_progress(61)

    assert_win(gui)
예제 #10
0
def test_tutorial(gui):
	"""Test the tutorial scenario."""

	# FIXME disable disasters (this should be an option for a scenario)
	gui.session.world.disaster_manager.disabled = True

	def assert_progress(progress):
		wait_and_close_logbook(gui)
		assert var_eq(gui.session, 'tutorial_progress', progress)

	# Tutorial start
	assert_progress(16)

	# Goal: Build warehouse
	ship = get_player_ship(gui.session)
	gui.select([ship])
	move_ship(gui, ship, (11, 1))

	# Save and reload scenario (1/3)
	saveload(gui)

	gui.trigger('overview_trade_ship', 'found_settlement')
	gui.cursor_click(11, 6, 'left')

	# Goal: Build a lumberjack
	assert_progress(19)

	# lumberjack (2)
	gui.trigger('mainhud', 'build')
	gui.trigger('tab', 'button_03')
	gui.cursor_click(8, 10, 'left', shift=True)
	gui.cursor_click(13, 10, 'left')
	gui.cursor_click(13, 10, 'right')

	# plant some extra trees around the lumberjacks
	gui.trigger('tab', 'button_13')
	gui.cursor_drag((6, 13), (15, 8), 'left')

	# roads (no dragging to trigger the 'you can drag roads' hint)
	gui.trigger('tab', 'button_21')
	gui.cursor_multi_click((10, 8), (10, 9), (10, 10), (11, 10))

	# Goal: Build hunter and fisher
	assert_progress(22)

	# fisher
	gui.trigger('tab', 'button_33')
	gui.cursor_click(13, 6, 'left')

	# hunter
	gui.trigger('tab', 'button_23')
	gui.cursor_click(8, 8, 'left')

	# Goal: Mainsquare
	assert_progress(25)

	gui.trigger('tab', 'button_02')
	gui.cursor_click(15, 18, 'left')

	# Goal: first tent
	assert_progress(28)

	# roads
	gui.trigger('tab', 'button_21')
	gui.cursor_drag((13, 15), (20, 15), 'left')
	gui.cursor_click(20, 15, 'right')

	# tent
	gui.trigger('tab', 'button_01')
	gui.cursor_click(13, 13, 'left')

	# Goal: 4 tents
	assert_progress(31)

	gui.trigger('tab', 'button_01')
	gui.cursor_multi_click((15, 13), (17, 13), (19, 13))

	# Goal: Build a signal fire
	assert_progress(34)

	# Save and reload scenario (2/3)
	saveload(gui)

	# Open build menu again (it is not reloaded, unlike selected instances)
	gui.trigger('mainhud', 'build')
	gui.trigger('tab_base', '0')

	# wait until we have enough boards
	while not settlement_res_stored_greater(gui.session, RES.BOARDS, 5):
		gui.run()

	gui.trigger('tab', 'button_22')
	gui.cursor_click(9, 5, 'left')

	# Goal: Trading
	assert_progress(37)

	# Buy tools from the trader (put the resource on the buy list)
	gui.cursor_click(11, 6, 'left')
	gui.trigger('tab_base', '2')
	gui.trigger('buysellmenu/slot_0', 'button', mouse='left')
	gui.trigger('select_trade_resource', 'resource_%d' % RES.TOOLS)
	gui.find('buysellmenu/slot_0/slider').slide(30)

	# Goal: Pavilion
	assert_progress(40)

	# wait until we have enough boards
	while not settlement_res_stored_greater(gui.session, RES.BOARDS, 5):
		gui.run()

	gui.trigger('mainhud', 'build')
	gui.trigger('tab', 'button_12')
	gui.cursor_click(19, 16, 'left')

	# Goal: Next tier
	assert_progress(43)

	# Adjust settler taxes (using mainsquare)
	gui.cursor_click(16, 18, 'left')
	gui.trigger('tab_base', '1')
	gui.find('tax_slider').slide(0)
	gui.trigger('mainhud', 'build')

	# wait until settlers upgraded
	while not settler_level_greater(gui.session, TIER.SAILORS):
		gui.run()

	# Goal: Farm
	assert_progress(46)

	# wait until we have enough boards
	while not settlement_res_stored_greater(gui.session, RES.BOARDS, 10):
		gui.run()

	gui.trigger('tab_base', '1') # FIXME this sometimes fails
	gui.trigger('tab', 'button_02')
	gui.cursor_click(25, 12, 'left')

	# Goal: Fields
	assert_progress(49)

	gui.trigger('tab_base', '1')

	# potato
	gui.trigger('tab', 'button_12')
	gui.cursor_click(23, 11, 'left')

	# Save and reload scenario (3/3)
	saveload(gui)

	# Open build menu again
	gui.trigger('mainhud', 'build')
	gui.trigger('tab_base', '1')

	# pasture
	gui.trigger('tab', 'button_22')
	gui.cursor_click(21, 10, 'left')

	# Goal: Storage
	assert_progress(52)

	# remove a tree to connect to farm
	gui.trigger('mainhud', 'destroy_tool')
	gui.cursor_click(21, 15, 'left')

	# roads
	gui.trigger('mainhud', 'build')
	gui.trigger('tab_base', '0')
	gui.trigger('tab', 'button_21')
	gui.cursor_drag((21, 15), (24, 14), 'left')
	gui.cursor_click(24, 14, 'right')
	# back of mainsquare
	gui.trigger('tab', 'button_21')
	gui.cursor_drag((13, 22), (20, 22), 'left')
	gui.cursor_click(20, 22, 'right')

	# storage tent
	gui.trigger('tab', 'button_11')
	gui.cursor_click(21, 16, 'left')

	# Goal: Weaver
	assert_progress(55)

	# wait until we have enough boards
	while not settlement_res_stored_greater(gui.session, RES.BOARDS, 10):
		gui.run()

	gui.trigger('tab_base', '1')
	gui.trigger('tab', 'button_21')
	gui.cursor_click(25, 14, 'left')

	# Goal: 50 inhabitants, positive balance
	assert_progress(58)

	# more potato fields
	gui.trigger('tab_base', '1')
	gui.trigger('tab', 'button_12')
	gui.cursor_multi_click((24, 9), (27, 8), (27, 11))

	# wait until we have enough boards
	while not settlement_res_stored_greater(gui.session, RES.BOARDS, 39):
		gui.run()

	# tents
	gui.trigger('tab_base', '0')
	gui.trigger('tab', 'button_01')
	gui.cursor_multi_click(
		(11, 14), (11, 15), (12, 17), (11, 20), (11, 22),
		(13, 23), (15, 23), (17, 23), (19, 23),
		(19, 20), (22, 15), (19, 18), (20, 21)
	)

	# Goal: Won
	assert_progress(61)

	assert_win(gui)
예제 #11
0
def test_tutorial(gui):
	"""Test the tutorial scenario."""

	# FIXME disable disasters (this should be an option for a scenario)
	gui.session.world.disaster_manager.disabled = True

	def assert_progress(progress):
		wait_and_close_logbook(gui)
		assert var_eq(gui.session, 'tutorial_progress', progress)

	# Tutorial start
	assert_progress(16)

	# Goal: Build warehouse
	ship = get_player_ship(gui.session)
	move_ship(ship, (11, 1))

	gui.select([ship])
	gui.trigger('overview_trade_ship', 'found_settlement')
	gui.cursor_click(11, 6, 'left')

	# Goal: Build a lumberjack
	assert_progress(19)

	# lumberjack (2)
	gui.trigger('mainhud', 'build')
	gui.trigger('tab', 'button_03')
	gui.cursor_click(8, 10, 'left', shift=True)
	gui.cursor_click(13, 10, 'left')
	gui.cursor_click(13, 10, 'right')

	# add extra trees around the lumberjacks
	gui.trigger('tab', 'button_13')
	settlement = gui.session.world.islands[0].settlements[0]
	for lumberjack_coords in [(8, 10), (13, 10)]:
		building = settlement.ground_map[lumberjack_coords].object
		for coords in building.position.get_radius_coordinates(building.radius):
			if coords not in settlement.ground_map:
				continue
			tile = settlement.ground_map[coords]
			if tile.object is None and 'constructible' in tile.classes:
				gui.cursor_click(coords[0], coords[1], 'left', shift=True)
	gui.cursor_click(13, 10, 'right')

	# roads
	gui.trigger('tab', 'button_21')
	gui.cursor_multi_click((10, 8), (10, 9), (10, 10), (11, 10))

	# Goal: Build hunter and fisher
	assert_progress(22)

	# fisher
	gui.trigger('tab', 'button_33')
	gui.cursor_click(13, 6, 'left')

	# hunter
	gui.trigger('tab', 'button_23')
	gui.cursor_click(8, 8, 'left')
	
	# Goal: Mainsquare
	assert_progress(25)

	gui.trigger('tab', 'button_02')
	gui.cursor_click(15, 18, 'left')

	# Goal: first tent
	assert_progress(28)

	# roads
	gui.trigger('tab', 'button_21')
	gui.cursor_multi_click(
		(13, 15), (14, 15), (16, 15), (17, 15),
		(18, 15), (19, 15), (20, 15)
	)

	# tent
	gui.trigger('tab', 'button_01')
	gui.cursor_click(13, 13, 'left')

	# Goal: 4 tents
	assert_progress(31)

	gui.trigger('tab', 'button_01')
	gui.cursor_multi_click((15, 13), (17, 13), (19, 13))

	# Goal: Build a signal fire
	assert_progress(34)

	# wait until we have enough boards
	while not settlement_res_stored_greater(gui.session, RES.BOARDS, 5):
		gui.run()

	gui.trigger('tab', 'button_22')
	gui.cursor_click(9, 5, 'left')

	# Goal: Trading
	assert_progress(37)

	# TODO do this with the gui (needs named buttons and a way to control the slider)
	player = gui.session.world.player
	tradepost = player.settlements[0].get_component(TradePostComponent)
	SetTradeSlot(tradepost, 0, RES.TOOLS, False, 30)(player)

	# Goal: Pavilion
	assert_progress(40)

	# wait until we have enough boards
	while not settlement_res_stored_greater(gui.session, RES.BOARDS, 5):
		gui.run()

	gui.trigger('tab', 'button_12')
	gui.cursor_click(19, 16, 'left')

	# Goal: Next tier
	assert_progress(43)

	# TODO adjust settler taxes

	# wait until settlers upgraded
	while not settler_level_greater(gui.session, TIER.SAILORS):
		gui.run()

	# Goal: Farm
	assert_progress(46)

	# wait until we have enough boards
	while not settlement_res_stored_greater(gui.session, RES.BOARDS, 10):
		gui.run()

	gui.trigger('tab_base', '1') # FIXME this sometimes fails
	gui.trigger('tab', 'button_02')
	gui.cursor_click(25, 12, 'left')
	
	# Goal: Fields
	assert_progress(49)

	gui.trigger('tab_base', '1')

	# potato
	gui.trigger('tab', 'button_12')
	gui.cursor_click(23, 11, 'left')

	# pasture
	gui.trigger('tab', 'button_22')
	gui.cursor_click(21, 10, 'left')

	# Goal: Storage
	assert_progress(52)

	# remove a tree to connect to farm
	gui.trigger('mainhud', 'destroy_tool')
	gui.cursor_click(21, 15, 'left')

	# roads
	gui.trigger('mainhud', 'build')
	gui.trigger('tab_base', '0')
	gui.trigger('tab', 'button_21')
	gui.cursor_multi_click((21, 15), (22, 15), (23, 15), (24, 15), (24, 14))
	
	# storage tent
	gui.trigger('tab', 'button_11')
	gui.cursor_click(21, 16, 'left')

	# Goal: Weaver
	assert_progress(55)

	# wait until we have enough boards
	while not settlement_res_stored_greater(gui.session, RES.BOARDS, 10):
		gui.run()

	gui.trigger('tab_base', '1')
	gui.trigger('tab', 'button_21')
	gui.cursor_click(25, 14, 'left')

	# Goal: 50 inhabitants, positive balance
	assert_progress(58)
	
	# more potatoe fields
	gui.trigger('tab_base', '1')
	gui.trigger('tab', 'button_12')
	gui.cursor_multi_click((24, 9), (27, 8), (27, 11))

	# lumberjack (more wood for upgrades)
	gui.trigger('tab_base', '0')
	gui.trigger('tab', 'button_03')
	gui.cursor_click(19, 18, 'left')

	# wait until we have enough boards
	while not settlement_res_stored_greater(gui.session, RES.BOARDS, 39):
		gui.run()

	# tents
	gui.trigger('tab', 'button_01')
	gui.cursor_multi_click(
		(11, 14), (11, 15), (12, 17), (11, 20),
		(12, 22), (14, 22), (16, 22), (18, 22),
		(19, 20), (22, 15)
	)

	# Goal: Won
	assert_progress(61)

	assert_win(gui)