Example #1
0
 def update_comp_args(self, **kwargs):
     """Update self.component.args, i.e. overwrite argument specified vi command line.
     This can help pass the previous task's results to the parameters 
     of the current task.
     """
     ## change the Namespace object to dictionary
     args_dict = vars(self.component.args) 
     
     if kwargs is not None:
         kwargs = trim(kwargs, '__pipeline__')
         args_dict.update(kwargs)
Example #2
0
 def update_comp_args(self, **kwargs):
     """Update self.component.args, i.e. overwrite argument specified vi command line.
     This can help pass the previous task's results to the parameters 
     of the current task.
     """
     ## change the Namespace object to dictionary
     args_dict = vars(self.component.args) 
     
     if kwargs is not None:
         kwargs = trim(kwargs, '__pipeline__')
         args_dict.update(kwargs)
Example #3
0
def show_civs(world):
    city_number = 0
    minr, maxr = 0, g.SCREEN_HEIGHT - 6

    view = 'economy'

    key_pressed = None
    event = libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)

    while key_pressed != libtcod.KEY_ESCAPE:
        if key_pressed == libtcod.KEY_PAGEUP or mouse.wheel_up:
            if not minr - 1 < 0:
                minr -= 1
                maxr -= 1
        if key_pressed == libtcod.KEY_PAGEDOWN or mouse.wheel_down:
            if not maxr + 1 > len(all_agents):
                maxr += 1
                minr += 1

        if key_pressed == libtcod.KEY_LEFT:
            city_number -= 1
            minr, maxr = 0, g.SCREEN_HEIGHT - 6
        if key_pressed == libtcod.KEY_RIGHT:
            city_number += 1
            minr, maxr = 0, g.SCREEN_HEIGHT - 6

        if city_number < 0:
            city_number = len(world.cities) - 1
        elif city_number > len(world.cities) - 1:
            city_number = 0

        libtcod.console_clear(0) ## 0 should be variable "con"?

        #### Set current variables ####
        city = world.cities[city_number]
        ################################

        if key_pressed == 'p':
            show_people(world=world)
        elif key_pressed == 'e':
            view = 'economy'
        elif key_pressed == 'd':
            economy_tab(world=world, city=city)
        elif key_pressed == 'b':
            view = 'building'
        elif key_pressed == 'f':
            view = 'figures'
        elif key_pressed == 'c':
            show_cultures(world=world, spec_culture=city.culture)
        elif key_pressed == 'r':
            world.cities[city_number].econ.run_simulation()
        elif key_pressed == 'a':
            city.econ.graph_results(solid=city.econ.get_all_available_commodity_tokens(), dot=[])


        #### General ######
        g.game.interface.root_console.draw_box(0, g.SCREEN_WIDTH - 1, 0, g.SCREEN_HEIGHT - 1, g.PANEL_FRONT) #Box around everything
        g.game.interface.root_console.draw_box(1, g.SCREEN_WIDTH - 2, 1, 7, g.PANEL_FRONT)
        libtcod.console_print(0, 2, 2, 'Civilizations (ESC to exit, LEFT and RIGHT arrows to change city, PGUP PGDOWN to scroll vertically)')
        libtcod.console_print(0, 2, 4, '<p> Show people   <b> Show buildings   <f> Show figures   <e> Show economy   <d> Detailed economy   <c> Culture')

        ## Show government type - left panel
        #g.game.interface.root_console.draw_box(1, 28, 8, g.SCREEN_HEIGHT - 2, g.PANEL_FRONT) # Around relations
        # Check for title holder

        # if city.faction.leader:
        #     title_info = '{0} {1}, age {2}'.format(city.faction.leader_prefix, city.faction.get_leader().fullname(), city.faction.get_leader().creature.get_age())
        # else:
        #     title_info = 'No holder'
        # libtcod.console_print(0, 2, 11, title_info)
        # libtcod.console_print(0, 2, 12, 'Dynastic heirs:')
        #
        # y = 13
        # for heir in city.faction.heirs:
        #     libtcod.console_print(0, 2, y, '{0}, age {1}'.format(heir.fullname(), heir.creature.get_age()))
        #     y += 1

        ######### Cities and governers #############
        g.game.interface.root_console.draw_box(1, g.SCREEN_WIDTH - 2, 8, g.SCREEN_HEIGHT - 2, g.PANEL_FRONT) # Around cities + govs

        y = 14
        libtcod.console_set_default_foreground(0, libtcod.color_lerp(city.color, g.PANEL_FRONT, .5))
        libtcod.console_print(0, 4, y - 4, 'City of {0} (Population: {1}, {2} gold)'.format(city.name, city.get_population(), city.treasury))
        libtcod.console_print(0, 4, y - 3, 'Access to: {0}'.format(join_list(city.native_res.keys())))
        if city.faction.parent is None:
            liege = ' * Independent *  '
        else:
            liege = 'Vassal to ' + city.faction.parent.site.name + '. '
        libtcod.console_print(0, 4, y - 2, liege + 'Vassals: ' + ', '.join([vassal.site.name for vassal in city.faction.subfactions]))
        libtcod.console_set_default_foreground(0, g.PANEL_FRONT)

        if view == 'building':
            ####### Positions of interest in the city ###########
            libtcod.console_print(0, 4, y, '-* Important structures *-')

            y += 1
            for building in city.buildings:
                y += 1
                if y > g.SCREEN_HEIGHT - 12:
                    libtcod.console_print(0, 4, y, '<< More >> ')
                    break

                libtcod.console_print(0, 4, y, '-* ' + building.name + ' *- ')
                for worker in building.current_workers:
                    y += 1
                    libtcod.console_print(0, 4, y, worker.fulltitle())
                y += 1


        elif view == 'economy':

            ####### AGENTS ############
            libtcod.console_set_default_foreground(0, g.PANEL_FRONT * .7)
            libtcod.console_print(0, 4, y, 'Agent name')
            libtcod.console_set_default_foreground(0, libtcod.color_lerp(libtcod.yellow, g.PANEL_FRONT, .7))
            libtcod.console_print(0, 30, y, 'Gold')

            libtcod.console_set_default_foreground(0, libtcod.color_lerp(libtcod.light_yellow, g.PANEL_FRONT, .7))
            libtcod.console_print(0, 40, y, 'g/i')

            #libtcod.console_set_default_foreground(0, libtcod.color_lerp(libtcod.blue, g.PANEL_FRONT, .7))
            #libtcod.console_print_ex(0, 40, y, libtcod.BKGND_NONE, libtcod.RIGHT, 'Buys')
            #libtcod.console_set_default_foreground(0, libtcod.color_lerp(libtcod.cyan, g.PANEL_FRONT, .7))
            #libtcod.console_print(0, 46, y, 'Sells')
            libtcod.console_set_default_foreground(0, libtcod.color_lerp(libtcod.green, g.PANEL_FRONT, .7))
            libtcod.console_print(0, 52, y, 'Alive')

            libtcod.console_set_default_foreground(0, g.PANEL_FRONT)


            all_agents = (city.econ.resource_gatherers + city.econ.good_producers + city.econ.buy_merchants + city.econ.sell_merchants)
            merchants = city.econ.buy_merchants + city.econ.sell_merchants

            for agent in all_agents[minr:maxr]:
                y += 1
                if y > g.SCREEN_HEIGHT - 5:
                    break


                if agent in merchants and agent.current_location == city:
                    agent_name = '{0} {1} (here)'.format(agent.name, agent.id_)
                elif agent in merchants and agent.current_location is not None:
                    agent_name = '{0} {1} ({2})'.format(agent.name, agent.id_, agent.current_location.owner.name)
                elif agent in merchants and agent.current_location is None:
                    agent_name = '{0} {1} (traveling)'.format(agent.name, agent.id_)
                else:
                    agent_name = '{0} {1}'.format(agent.name, agent.id_)

                if agent.attached_to == g.player:
                    agent_name += ' (you)'

                ### (debug) Player can take on role of economy agent at a whim
                if mouse.cy == y and 4 <= mouse.cx <= 85:
                    acolor = libtcod.dark_yellow

                    # Set the g.player to "become" one of these agents
                    if mouse.lbutton_pressed:
                        agent.update_holder(figure=g.player)

                        for panel in g.game.interface.gui_panels:
                            if panel.name == 'Panel4':
                                break

                        panel.render = True
                        pcolor = libtcod.color_lerp(g.PANEL_FRONT, libtcod.light_green, .5)
                        hcolor = pcolor * 2
                        panel.wmap_buttons.append(Button(gui_panel=panel, func=g.WORLD.time_cycle.goto_next_week, args=[],
                                                              text='Advance', topleft=(15, 40), width=12, height=3, color=pcolor, hcolor=hcolor, do_draw_box=True) )

                else:
                    acolor = g.PANEL_FRONT

                libtcod.console_set_default_foreground(0, acolor)
                libtcod.console_print(0, 4, y, agent_name[:26])
                libtcod.console_set_default_foreground(0, libtcod.color_lerp(libtcod.yellow, g.PANEL_FRONT, .7))
                libtcod.console_print(0, 30, y, str(agent.gold))

                libtcod.console_set_default_foreground(0, libtcod.color_lerp(libtcod.light_yellow, g.PANEL_FRONT, .7))
                libtcod.console_print(0, 40, y, '{0:.2f}'.format(agent.gold / agent.represented_population_number))

                #libtcod.console_set_default_foreground(0, libtcod.color_lerp(libtcod.blue, g.PANEL_FRONT, .7))
                #libtcod.console_print(0, 40, y, str(agent.buys))
                #libtcod.console_set_default_foreground(0, libtcod.color_lerp(libtcod.cyan, g.PANEL_FRONT, .7))
                #libtcod.console_print(0, 46, y, str(agent.sells))
                libtcod.console_set_default_foreground(0, libtcod.color_lerp(libtcod.green, g.PANEL_FRONT, .7))
                libtcod.console_print(0, 52, y, str(agent.turns_alive))

            # Set color back
            libtcod.console_set_default_foreground(0, g.PANEL_FRONT)
            ###### End print individual agents ######

            ## Print good info ##
            y = 12
            libtcod.console_print(0, 60, y - 2, 'Most demanded last turn: ' + city.econ.find_most_demanded_commodity(restrict_based_on_available_resource_slots=0))

            libtcod.console_print(0, 60, y, 'Commodity')
            libtcod.console_print(0, 78, y, 'Avg$')
            libtcod.console_print(0, 84, y, 'Last$')
            libtcod.console_print(0, 90, y, 'Sply')
            libtcod.console_print(0, 96, y, 'Dmnd')
            libtcod.console_print(0, 102, y, 'D:S')
            libtcod.console_print(0, 108, y, '#')

            y += 2

            for commodity, auction in city.econ.auctions.iteritems():
                if auction.supply is not None and auction.demand is not None:
                    libtcod.console_print(0, 60, y, commodity)
                    libtcod.console_print(0, 78, y, str(auction.mean_price))

                    # Color trades - green means price last round was > than avg, red means < than avg
                    if auction.mean_price <= auction.get_last_valid_price():
                        color = libtcod.color_lerp(libtcod.green, g.PANEL_FRONT, auction.mean_price / max(1, auction.get_last_valid_price()) ) #prevent division by 0
                    else:
                        color = libtcod.color_lerp(libtcod.red, g.PANEL_FRONT, auction.get_last_valid_price() / max(1, auction.mean_price) ) #prevent division by 0
                    libtcod.console_set_default_foreground(0, color)
                    libtcod.console_print(0, 84, y, str(auction.get_last_valid_price()))
                    ## /color trades
                    libtcod.console_set_default_foreground(0, g.PANEL_FRONT)
                    libtcod.console_print(0, 90, y, str(auction.supply))
                    libtcod.console_print(0, 96, y, str(auction.demand))
                    # Ratio
                    d_s_ratio = auction.demand / max(auction.supply, 1)

                    if auction.supply == 0:
                        color_mod = .5
                        color = libtcod.red
                    elif auction.demand == 0:
                        color_mod = .5
                        color = libtcod.magenta
                    else:
                        color_mod = min(abs(1 - d_s_ratio), .75)
                        color = libtcod.green

                    libtcod.console_set_default_foreground(0, libtcod.color_lerp(color, g.PANEL_FRONT, color_mod))
                    libtcod.console_print(0, 102, y, "{0:.2f}".format(round(d_s_ratio, 2)))
                    libtcod.console_set_default_foreground(0, g.PANEL_FRONT)

                    # Iteration in economy
                    libtcod.console_print(0, 108, y, str(auction.iterations))
                    y += 1


            # Prepare agent counts for a summary table
            agents_condensed = [a.name for a in city.econ.resource_gatherers + city.econ.good_producers]
            for m in city.econ.sell_merchants:
                agents_condensed.append('{0} (sell)'.format(m.name))
            for m in city.econ.buy_merchants:
                agents_condensed.append('{0} (buy)'.format(m.name))

            agent_counts = Counter(agents_condensed)
            agent_counts_sorted = [(k, v) for k, v in agent_counts.iteritems()]
            agent_counts_sorted.sort(key=lambda x: x[1], reverse=True)


            secotion_2_y = y + 3
            y = secotion_2_y

            libtcod.console_print(0, 60, y - 1, '-* {0} agents *-'.format(len(agents_condensed)))


            for agent_name, num in agent_counts_sorted:
                y += 1
                if y < g.SCREEN_HEIGHT - 5:
                    libtcod.console_print(0, 60, y, '{0} {1}'.format(num, trim(agent_name, 26)))



            ### Good info ###
            y = secotion_2_y

            libtcod.console_print(0, 90, y - 1, '-* Imports *-')
            for other_city, commodities in city.imports.iteritems():
                for commodity in commodities:
                    y += 1
                    if y < g.SCREEN_HEIGHT - 5:
                        libtcod.console_print(0, 90, y, '{0} from {1}'.format(commodity, other_city.name))

            y += 3
            libtcod.console_print(0, 90, y - 1, '-* Exports *-')
            for other_city, commodities in city.exports.iteritems():
                for commodity in commodities:
                    y += 1
                    if y < g.SCREEN_HEIGHT - 5:
                        libtcod.console_print(0, 90, y, '{0} to {1}'.format(commodity, other_city.name))
                        ## End print good info ##


        elif view == 'figures':
            selected = False
            ## Figures currently residing here
            y = 16
            ny = y # for opinions

            libtcod.console_print(0, 34, y - 2, '{0} notable characters'.format(len(world.tiles[city.x][city.y].entities)))
            for figure in world.tiles[city.x][city.y].entities:
                if y > g.SCREEN_HEIGHT - 5:
                    break

                ##
                #if 34 <= mouse.cx <= 34+len(figure.fullname()) and mouse.cy == y:
                if 34 <= mouse.cx <= 60 + len(figure.creature.get_profession()) and mouse.cy == y:
                    selected = True

                    if figure.creature.sex:
                        symb = chr(11)
                        color = libtcod.light_blue
                    else:
                        color = libtcod.light_red
                        symb = chr(12)

                    libtcod.console_set_default_foreground(0, color)
                    libtcod.console_print(0, 85, ny, symb)
                    libtcod.console_set_default_foreground(0, g.PANEL_FRONT)

                    libtcod.console_print(0, 87, ny, figure.fullname())
                    libtcod.console_print(0, 85, ny + 1,
                                          figure.creature.get_profession() + ', age ' + str(figure.creature.get_age()))

                    spouseinfo = 'No spouse'
                    if figure.creature.spouse:
                        end = ''
                        if figure.creature.spouse.creature.status == 'dead':
                            end = ' (dead)'
                        spouseinfo = 'Married to ' + figure.creature.spouse.fulltitle() + end

                    libtcod.console_print(0, 85, ny + 2, spouseinfo)

                    if figure.creature.current_citizenship == city:
                        info = 'Currently lives here'
                    else:
                    #    info = 'Staying at ' + random.choice(city.get_building_type('Tavern')).get_name()
                        info = 'Currently visiting'

                    libtcod.console_print(0, 85, ny + 3, info)

                    ny += 4
                    for trait, m in figure.creature.traits.iteritems():
                        libtcod.console_print(0, 85, ny + 1, tdesc(trait, m))
                        ny += 1

                    ny += 1
                    for issue, (opinion, reasons) in figure.creature.opinions.iteritems():
                        ny += 1
                        ##
                        s = issue + ': ' + str(opinion)
                        libtcod.console_print(0, 85, ny, s)
                        for reason, amount in reasons.iteritems():
                            ny += 1
                            libtcod.console_print(0, 86, ny, reason + ': ' + str(amount))

                if selected:
                    libtcod.console_set_default_foreground(0, libtcod.color_lerp(g.PANEL_FRONT, libtcod.yellow, .5))
                    selected = False

                elif libtcod.console_get_default_foreground != g.PANEL_FRONT:
                    libtcod.console_set_default_foreground(0, g.PANEL_FRONT)

                libtcod.console_print(0, 34, y, figure.fullname())

                libtcod.console_print(0, 57, y, str(figure.creature.get_age()))

                libtcod.console_print(0, 60, y, figure.creature.get_profession())

                if figure.creature.dynasty:
                    libtcod.console_put_char_ex(0, 32, y, figure.creature.dynasty.symbol,
                                                figure.creature.dynasty.symbol_color,
                                                figure.creature.dynasty.background_color)

                if figure.creature.sex:
                    symb = chr(11)
                    color = libtcod.light_blue
                else:
                    color = libtcod.light_red
                    symb = chr(12)

                libtcod.console_set_default_foreground(0, color)
                libtcod.console_print(0, 55, y, symb)
                libtcod.console_set_default_foreground(0, g.PANEL_FRONT)


                # Increase so next figure goes onto next line
                y += 1

        libtcod.console_flush()

        event = libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS | libtcod.EVENT_MOUSE, key, mouse)
        key_pressed = g.game.get_key(key)