Example #1
0
    def popup_caravan_dialog(self, unit, home, dest):
        can_establish, can_trade, can_wonder = self.get_caravan_options(
            unit, home, dest)

        def establish_trade_route():
            unit.perform_activity(
                client.actions.ACTIVITY_ESTABLISH_TRADE_ROUTE)

        def help_wonder():
            unit.perform_activity(client.actions.ACTIVITY_HELP_BUILD_WONDER)

        items = []

        if not can_establish and not can_wonder:
            return

        if can_establish:
            items.append(('Establish trade route', establish_trade_route))

        if can_wonder:
            items.append(('Help building wonder', help_wonder))

        items.append(('Do nothing', lambda: None))

        ui.show_list_dialog(
            items,
            title='Your %s from %s has arrived to city %s' %
            (unit.get_name(), home.get_name(), dest.get_name()),
            titlefont=ui.consolefont)
Example #2
0
    def popup_caravan_dialog(self, unit, home, dest):
        can_establish, can_trade, can_wonder = self.get_caravan_options(unit, home, dest)

        def establish_trade_route():
            unit.perform_activity(client.actions.ACTIVITY_ESTABLISH_TRADE_ROUTE)

        def help_wonder():
            unit.perform_activity(client.actions.ACTIVITY_HELP_BUILD_WONDER)

        items = []

        if not can_establish and not can_wonder:
            return

        if can_establish:
            items.append(("Establish trade route", establish_trade_route))

        if can_wonder:
            items.append(("Help building wonder", help_wonder))

        items.append(("Do nothing", lambda: None))

        ui.show_list_dialog(
            items,
            title="Your %s from %s has arrived to city %s" % (unit.get_name(), home.get_name(), dest.get_name()),
            titlefont=ui.consolefont,
        )
Example #3
0
    def set_difficulty(self):
        def set_do(name):
            self.difficulty = name
            self.set_difficulty_settings()

        ui.show_list_dialog(['novice', 'easy', 'normal', 'hard'],
                            callback=set_do)
Example #4
0
 def popup_pillage_dialog(self, unit, act_list):
     items = []
     def callback(act):
         freeciv.func.pillage_callback(unit.handle, act)
     for act in act_list:
         items.append((freeciv.func.pillage_label(act), functools.partial(callback, act)))
     ui.show_list_dialog(items, title='Select what to pillage:', titlefont=ui.consolefont)
Example #5
0
    def popup_caravan_dialog(self, unit, home, target_city, target_unit,
                             target_tile, act_list):
        target = target_city
        items = []
        for act_id in act_list:
            py_action = client.actions.freeciv_action_target_city_to_py_action(
                act_id)
            label = 'action ' + str(act_id)
            if py_action == client.actions.ACTION_ESTABLISH_EMBASSY:
                label = 'Establish Embassy'
            elif py_action == client.actions.ACTION_SPY_INVESTIGATE_CITY:
                label = 'Investigate City'
            elif py_action == client.actions.ACTION_SPY_POISON:
                label = 'Poison City'
            elif py_action == client.actions.ACTION_SPY_STEAL_GOLD:
                label = 'Steal Gold'
            elif py_action == client.actions.ACTION_SPY_SABOTAGE_CITY:
                label = 'Sabotage City'
            elif py_action == client.actions.ACTION_SPY_TARGETED_SABOTAGE_CITY:
                label = 'Targeted Sabotage City'
            elif py_action == client.actions.ACTION_SPY_STEAL_TECH:
                label = 'Steal Technology'
            elif py_action == client.actions.ACTION_SPY_TARGETED_STEAL_TECH:
                label = 'Targeted Steal Tech'
            elif py_action == client.actions.ACTION_SPY_INCITE_CITY:
                label = 'Incite Revolt'
            elif py_action == client.actions.ACTIVITY_ESTABLISH_TRADE_ROUTE:
                label = 'Establish trade route'
            elif py_action == client.actions.ACTION_MARKETPLACE:
                label = 'Enter Marketplace'
            elif py_action == client.actions.ACTIVITY_HELP_BUILD_WONDER:
                label = 'Help building wonder'
            elif py_action == client.actions.ACTION_SPY_BRIBE_UNIT:
                label = 'Bribe unit'
                target = target_unit
            elif py_action == client.actions.ACTION_SPY_SABOTAGE_UNIT:
                label = 'Sabotage unit'
                target = target_unit

            def callback(act):
                unit.perform_activity(act, target.handle)
                freeciv.func.py_action_selection_no_longer_in_progress(
                    unit.handle)

            items.append((label, functools.partial(callback, py_action)))

        def no_move():
            freeciv.func.request_unit_non_action_move(unit.handle, target_tile)
            freeciv.func.py_action_selection_no_longer_in_progress(unit.handle)

        items.append(('Do nothing', no_move))

        ui.show_list_dialog(
            items,
            title='Your %s from %s has arrived to city %s' %
            (unit.get_name(), home.get_name(), target.get_name()),
            titlefont=ui.consolefont)
Example #6
0
 def popup_airlift_dialog(self, unit):
     items = []
     cities = freeciv.func.get_airlift_dest_cities(unit.handle)
     def callback(target_city):
         freeciv.func.request_unit_airlift(unit.handle, target_city.handle)
     for handle in cities:
         target_city = city.City(handle)
         items.append((target_city.get_name(), functools.partial(callback, target_city)))
     ui.show_list_dialog(items, title='Airlift to', titlefont=ui.consolefont, scroll=True)
Example #7
0
    def popup_pillage_dialog(self, unit, act_list):
        items = []

        def callback(act):
            freeciv.func.pillage_callback(unit.handle, act)

        for act in act_list:
            items.append((freeciv.func.pillage_label(act),
                          functools.partial(callback, act)))
        ui.show_list_dialog(items,
                            title='Select what to pillage:',
                            titlefont=ui.consolefont)
Example #8
0
    def popup_caravan_dialog(self, unit, home, target_city, target_unit, target_tile, act_list):
        target = target_city
        items = []
        for act_id in act_list:
            py_action = client.actions.freeciv_action_target_city_to_py_action(act_id)
            label = 'action ' + str(act_id)
            if py_action == client.actions.ACTION_ESTABLISH_EMBASSY:
                label = 'Establish Embassy'
            elif py_action == client.actions.ACTION_SPY_INVESTIGATE_CITY:
                label = 'Investigate City'
            elif py_action == client.actions.ACTION_SPY_POISON:
                label = 'Poison City'
            elif py_action == client.actions.ACTION_SPY_STEAL_GOLD:
                label = 'Steal Gold'
            elif py_action == client.actions.ACTION_SPY_SABOTAGE_CITY:
                label = 'Sabotage City'
            elif py_action == client.actions.ACTION_SPY_TARGETED_SABOTAGE_CITY:
                label = 'Targeted Sabotage City'
            elif py_action == client.actions.ACTION_SPY_STEAL_TECH:
                label = 'Steal Technology'
            elif py_action == client.actions.ACTION_SPY_TARGETED_STEAL_TECH:
                label = 'Targeted Steal Tech'
            elif py_action == client.actions.ACTION_SPY_INCITE_CITY:
                label = 'Incite Revolt'
            elif py_action == client.actions.ACTIVITY_ESTABLISH_TRADE_ROUTE:
                label = 'Establish trade route'
            elif py_action == client.actions.ACTION_MARKETPLACE:
                label = 'Enter Marketplace'
            elif py_action == client.actions.ACTIVITY_HELP_BUILD_WONDER:
                label = 'Help building wonder'
            elif py_action == client.actions.ACTION_SPY_BRIBE_UNIT:
                label = 'Bribe unit'
                target = target_unit
            elif py_action == client.actions.ACTION_SPY_SABOTAGE_UNIT:
                label = 'Sabotage unit'
                target = target_unit
            def callback(act):
                unit.perform_activity(act, target.handle)
                freeciv.func.py_action_selection_no_longer_in_progress(unit.handle)
            items.append((label, functools.partial(callback, py_action)))

        def no_move():
            freeciv.func.request_unit_non_action_move(unit.handle, target_tile)
            freeciv.func.py_action_selection_no_longer_in_progress(unit.handle)
        items.append(('Do nothing', no_move))

        ui.show_list_dialog(items, title='Your %s from %s has arrived to city %s'
                            % (unit.get_name(), home.get_name(), target.get_name()),
                            titlefont=ui.consolefont)
Example #9
0
    def popup_airlift_dialog(self, unit):
        items = []
        cities = freeciv.func.get_airlift_dest_cities(unit.handle)

        def callback(target_city):
            freeciv.func.request_unit_airlift(unit.handle, target_city.handle)

        for handle in cities:
            target_city = city.City(handle)
            items.append((target_city.get_name(),
                          functools.partial(callback, target_city)))
        ui.show_list_dialog(items,
                            title='Airlift to',
                            titlefont=ui.consolefont,
                            scroll=True)
Example #10
0
    def popup_city_diplomat_dialog(self, diplomat_action):
        if diplomat_action.spy:
            message = 'Choose Your spy\'s strategy'
        else:
            message = 'Choose Your diplomat\'s strategy'

        action_titles = {
            freeciv.const.DIPLOMAT_MOVE: "Keep moving",
            freeciv.const.DIPLOMAT_EMBASSY: "Establish Embassy",
            freeciv.const.DIPLOMAT_INVESTIGATE: "Investigate City",
            freeciv.const.DIPLOMAT_SABOTAGE: "Sabotage City",
            freeciv.const.DIPLOMAT_INCITE: "Incite Revolt",
            freeciv.const.DIPLOMAT_STEAL: "Steal Technology",
            freeciv.const.SPY_POISON: "Poison City",
        }

        simple_actions = [
            freeciv.const.DIPLOMAT_EMBASSY, freeciv.const.DIPLOMAT_INVESTIGATE,
            freeciv.const.DIPLOMAT_SABOTAGE, freeciv.const.DIPLOMAT_MOVE,
            freeciv.const.SPY_POISON
        ]

        def do_action(action):
            if action in simple_actions:
                diplomat_action.perform_simple_action(action)
            elif action == freeciv.const.DIPLOMAT_SABOTAGE:
                # TODO: spy can choose building
                diplomat_action.perform_simple_action(
                    action, value=freeciv.const.B_LAST + 1)
            elif action == freeciv.const.DIPLOMAT_STEAL:
                # TODO: spy can choose technology
                diplomat_action.perform_simple_action(
                    action, value=freeciv.const.A_UNSET)
            elif action == freeciv.const.DIPLOMAT_INCITE:
                diplomat_action.request_answer(action)
            else:
                ui.not_implemented()

        items = []
        for action in diplomat_action.get_actions():
            if action in action_titles:
                title = action_titles[action]
                items.append((title, functools.partial(do_action, action)))

        ui.show_list_dialog(items, title=message, titlefont=ui.consolefont)
Example #11
0
    def popup_city_diplomat_dialog(self, diplomat_action):
        if diplomat_action.spy:
            message = "Choose Your spy's strategy"
        else:
            message = "Choose Your diplomat's strategy"

        action_titles = {
            freeciv.const.DIPLOMAT_MOVE: "Keep moving",
            freeciv.const.DIPLOMAT_EMBASSY: "Establish Embassy",
            freeciv.const.DIPLOMAT_INVESTIGATE: "Investigate City",
            freeciv.const.DIPLOMAT_SABOTAGE: "Sabotage City",
            freeciv.const.DIPLOMAT_INCITE: "Incite Revolt",
            freeciv.const.DIPLOMAT_STEAL: "Steal Technology",
            freeciv.const.SPY_POISON: "Poison City",
        }

        simple_actions = [
            freeciv.const.DIPLOMAT_EMBASSY,
            freeciv.const.DIPLOMAT_INVESTIGATE,
            freeciv.const.DIPLOMAT_SABOTAGE,
            freeciv.const.DIPLOMAT_MOVE,
            freeciv.const.SPY_POISON,
        ]

        def do_action(action):
            if action in simple_actions:
                diplomat_action.perform_simple_action(action)
            elif action == freeciv.const.DIPLOMAT_SABOTAGE:
                # TODO: spy can choose building
                diplomat_action.perform_simple_action(action, value=freeciv.const.B_LAST + 1)
            elif action == freeciv.const.DIPLOMAT_STEAL:
                # TODO: spy can choose technology
                diplomat_action.perform_simple_action(action, value=freeciv.const.A_UNSET)
            elif action == freeciv.const.DIPLOMAT_INCITE:
                diplomat_action.request_answer(action)
            else:
                ui.not_implemented()

        items = []
        for action in diplomat_action.get_actions():
            if action in action_titles:
                title = action_titles[action]
                items.append((title, functools.partial(do_action, action)))

        ui.show_list_dialog(items, title=message, titlefont=ui.consolefont)
Example #12
0
    def set_difficulty(self):
        def set_do(name):
            self.difficulty = name
            self.set_difficulty_settings()

        ui.show_list_dialog(['handicapped', 'novice', 'easy', 'normal', 'hard', 'cheating'], callback=set_do)