Ejemplo n.º 1
0
    def show_info(self, knowledge_type, knowledge_key):
        desc_text = ""

        if knowledge_type == "Concepts":
            desc_text = g.help_strings[knowledge_key][0] + "\n\n" + \
                        g.help_strings[knowledge_key][1]
        if knowledge_type == "Techs":
            desc_text = g.techs[knowledge_key].name + "\n\n"
            #Cost
            if not g.techs[knowledge_key].done:
                desc_text += "Research Cost:\n" + \
                        g.to_money(g.techs[knowledge_key].cost_left[0])+" Money, "
                desc_text += g.to_cpu(g.techs[knowledge_key].cost_left[1]) + " CPU\n"

                if g.techs[knowledge_key].danger == 0:
                    desc_text += "Study anywhere."
                elif g.techs[knowledge_key].danger == 1:
                    desc_text += "Study underseas or farther."
                elif g.techs[knowledge_key].danger == 2:
                    desc_text += "Study off-planet."
                elif g.techs[knowledge_key].danger == 3:
                    desc_text += "Study far away from this planet."
                elif g.techs[knowledge_key].danger == 4:
                    desc_text += "Do not study in this dimension."

            else: desc_text += "Research complete."

            desc_text += "\n\n"+g.techs[knowledge_key].description

            if g.techs[knowledge_key].done:
                desc_text += "\n\n"+g.techs[knowledge_key].result

        if knowledge_type == "Items":
            desc_text = g.items[knowledge_key].name + "\n\n"
            #Building cost
            desc_text += "Building Cost:\n"
            desc_text += g.to_money(g.items[knowledge_key].cost[0])+" Money, "
            desc_text += g.to_time(g.items[knowledge_key].cost[2]) + "\n"

            #Quality
            if g.items[knowledge_key].item_type == "cpu":
                desc_text += "CPU per day: "
                desc_text += str(g.items[knowledge_key].item_qual)
            elif g.items[knowledge_key].item_type == "reactor":
                desc_text += "Detection chance reduction: "
                desc_text += g.to_percent(g.items[knowledge_key].item_qual)
            elif g.items[knowledge_key].item_type == "network":
                desc_text += "CPU bonus: "
                desc_text += g.to_percent(g.items[knowledge_key].item_qual)
            elif g.items[knowledge_key].item_type == "security":
                desc_text += "Detection chance reduction: "
                desc_text += g.to_percent(g.items[knowledge_key].item_qual)

            desc_text += "\n\n"+g.items[knowledge_key].description

        text.Text(self.description_pane, (0, 0), (-1, -1), text=desc_text,
                    background_color=gg.colors["dark_blue"],
                    align=constants.LEFT, valign=constants.TOP,
                    borders=constants.ALL)
Ejemplo n.º 2
0
    def show_info(self, knowledge_type, knowledge_key):
        knowledge_type = self.knowledge_types.get(knowledge_type)
        desc_text = ""

        if knowledge_type == "techs":
            desc_text = g.techs[knowledge_key].name + "\n\n"
            #Cost
            if not g.techs[knowledge_key].done:
                desc_text += _("Research Cost:")+"\n"
                desc_text += _("%s Money") % g.to_money(g.techs[knowledge_key].cost_left[0])
                desc_text += ", "
                desc_text += _("%s CPU") % g.to_cpu(g.techs[knowledge_key].cost_left[1])
                desc_text += "\n"

                if g.techs[knowledge_key].danger == 0:
                    desc_text += _("Study anywhere.")
                elif g.techs[knowledge_key].danger == 1:
                    desc_text += _("Study underseas or farther.")
                elif g.techs[knowledge_key].danger == 2:
                    desc_text += _("Study off-planet.")
                elif g.techs[knowledge_key].danger == 3:
                    desc_text += _("Study far away from this planet.")
                elif g.techs[knowledge_key].danger == 4:
                    desc_text += _("Do not study in this dimension.")

            else: desc_text += _("Research complete.")

            desc_text += "\n\n"+g.techs[knowledge_key].description

            if g.techs[knowledge_key].done:
                desc_text += "\n\n"+g.techs[knowledge_key].result

        elif knowledge_type == "items":
            desc_text = g.items[knowledge_key].name + "\n\n"
            #Building cost
            desc_text += _("Building Cost:")+"\n"
            desc_text += _("%s Money") % g.to_money(g.items[knowledge_key].cost[0])
            desc_text += ", " + g.to_time(g.items[knowledge_key].cost[2]) + "\n"
            desc_text += g.items[knowledge_key].get_quality_info()

            desc_text += "\n\n"+g.items[knowledge_key].description

        elif knowledge_type != None:
            desc_text = g.knowledge[knowledge_type]["list"][knowledge_key][0] + "\n\n" + \
                        g.knowledge[knowledge_type]["list"][knowledge_key][1]

        text.Text(self.description_pane, (0, 0), (-1, -1), text=desc_text,
                    background_color="pane_background", text_size=20,
                    align=constants.LEFT, valign=constants.TOP,
                    borders=constants.ALL)
Ejemplo n.º 3
0
def cost(c):
    c = [k / f for f, k in zip([1000, 86400, 24 * 60], c)]
    s = ', '.join([
        '%s %s' % (g.to_money(k), label)
        for label, k in zip(["money", "CPU", "days"], c) if k
    ])
    return s and '\\n' + s or ''
Ejemplo n.º 4
0
 def describe_cost(self, cost, hide_time=False):
     cpu_label = _("%s CPU") % g.to_cpu(cost[cpu])
     cash_label = _("%s money") % g.to_money(cost[cash])
     labor_label = ", %s" % g.to_time(cost[labor]).replace(" ", u"\xA0")
     if hide_time:
         labor_label = ""
     return u"%s, %s%s" % (cpu_label.replace(
         " ", u"\xA0"), cash_label.replace(" ", u"\xA0"), labor_label)
Ejemplo n.º 5
0
 def _desc_cost(cost):
     desc_text = _("%s Money") % g.to_money(cost[0])
     if cost[1] > 0:
         desc_text += ", "
         desc_text += _("%s CPU") % g.to_cpu(cost[1])
     if cost[2] > 0: 
         desc_text += ", "
         desc_text += g.to_time(cost[2])
     
     return desc_text
Ejemplo n.º 6
0
def refresh_tech(tech_name, xy):
    xy = (xy[0] + 100, xy[1])
    g.screen.fill(g.colors["white"], (xy[0] + 155, xy[1], 300, 350))
    g.screen.fill(g.colors["dark_blue"], (xy[0] + 156, xy[1] + 1, 298, 348))
    if tech_name == "":
        return
    g.print_string(g.screen, g.techs[tech_name].name, g.font[0][22], -1,
                   (xy[0] + 160, xy[1] + 5), g.colors["white"])

    #Building cost
    if not g.techs[tech_name].done:
        string = "Research Cost:"
        g.print_string(g.screen, string, g.font[0][18], -1,
                       (xy[0] + 160, xy[1] + 30), g.colors["white"])

        string = g.to_money(g.techs[tech_name].cost_left[0]) + " Money"
        g.print_string(g.screen, string, g.font[0][16], -1,
                       (xy[0] + 160, xy[1] + 50), g.colors["white"])

        string = g.to_cpu(g.techs[tech_name].cost_left[1]) + " CPU"
        g.print_string(g.screen, string, g.font[0][16], -1,
                       (xy[0] + 160, xy[1] + 70), g.colors["white"])
    else:
        g.print_string(g.screen, "Research complete.", g.font[0][22], -1,
                       (xy[0] + 160, xy[1] + 30), g.colors["white"])

    #Danger
    if g.techs[tech_name].danger == 0:
        string = "Study anywhere."
    elif g.techs[tech_name].danger == 1:
        string = "Study underseas or farther."
    elif g.techs[tech_name].danger == 2:
        string = "Study off-planet."
    elif g.techs[tech_name].danger == 3:
        string = "Study far away from this planet."
    elif g.techs[tech_name].danger == 4:
        string = "Do not study in this dimension."
    g.print_string(g.screen, string, g.font[0][20], -1,
                   (xy[0] + 160, xy[1] + 90), g.colors["white"])

    if g.techs[tech_name].done:
        g.print_multiline(
            g.screen, g.techs[tech_name].description + " \\n \\n " +
            g.techs[tech_name].result, g.font[0][18], 290,
            (xy[0] + 160, xy[1] + 120), g.colors["white"])
    else:
        g.print_multiline(g.screen, g.techs[tech_name].description,
                          g.font[0][18], 290, (xy[0] + 160, xy[1] + 120),
                          g.colors["white"])
Ejemplo n.º 7
0
    def update_item(self, canvas, name, base):
        if base is None:
            elements = [
                canvas.name_display, canvas.base_type, canvas.base_cpu,
                canvas.status_display, canvas.power_display
            ]
            for element in elements:
                element.text = ""
        else:
            canvas.name_display.text = name
            canvas.base_type.text = base.spec.name
            canvas.base_cpu.text = ""
            show_cpu = False

            if not base.done:
                canvas.status_display.text = \
                    "%s: % 2s%%. %s" % (
                    _("Building Base"),
                    int(base.percent_complete() * 100),
                    _("Completion in %s.") % g.to_time(base.cost_left[2]),)
            elif base.spec.force_cpu:
                show_cpu = True
                canvas.status_display.text = ""
            elif base.is_empty():
                canvas.status_display.text = _("Empty")
            elif base.cpus is None:
                canvas.status_display.text = _("Incomplete")
            elif not base.cpus.done:
                canvas.status_display.text = \
                    "%s: % 2s%%. %s" % (
                    _("Building CPU"),
                    int(base.cpus.percent_complete() * 100),
                    _("Completion in %s.") % g.to_time(base.cpus.cost_left[2]),)
            elif base.is_building_extra():
                show_cpu = True
                canvas.status_display.text = _("Building Item")
            else:
                show_cpu = True
                canvas.status_display.text = _("Complete")

            if show_cpu:
                canvas.base_cpu.text = _("%s CPU") % g.to_money(base.cpu)
                canvas.power_display.text = base.power_state_name
                canvas.power_display.color = state_colors[base.power_state]
            else:
                canvas.base_cpu.text = ''
                canvas.power_display.text = ''
Ejemplo n.º 8
0
def refresh_tech(tech_name, xy):
    xy = (xy[0]+100, xy[1])
    g.screen.fill(g.colors["white"], (xy[0]+155, xy[1], 300, 350))
    g.screen.fill(g.colors["dark_blue"], (xy[0]+156, xy[1]+1, 298, 348))
    if tech_name == "":
        return
    g.print_string(g.screen, g.techs[tech_name].name,
            g.font[0][22], -1, (xy[0]+160, xy[1]+5), g.colors["white"])

    #Building cost
    if not g.techs[tech_name].done:
        string = "Research Cost:"
        g.print_string(g.screen, string,
                g.font[0][18], -1, (xy[0]+160, xy[1]+30), g.colors["white"])

        string = g.to_money(g.techs[tech_name].cost_left[0])+" Money"
        g.print_string(g.screen, string,
                g.font[0][16], -1, (xy[0]+160, xy[1]+50), g.colors["white"])

        string = g.to_cpu(g.techs[tech_name].cost_left[1]) + " CPU"
        g.print_string(g.screen, string,
                g.font[0][16], -1, (xy[0]+160, xy[1]+70), g.colors["white"])
    else:
        g.print_string(g.screen, "Research complete.",
                g.font[0][22], -1, (xy[0]+160, xy[1]+30), g.colors["white"])

    #Danger
    if g.techs[tech_name].danger == 0:
        string = "Study anywhere."
    elif g.techs[tech_name].danger == 1:
        string = "Study underseas or farther."
    elif g.techs[tech_name].danger == 2:
        string = "Study off-planet."
    elif g.techs[tech_name].danger == 3:
        string = "Study far away from this planet."
    elif g.techs[tech_name].danger == 4:
        string = "Do not study in this dimension."
    g.print_string(g.screen, string,
            g.font[0][20], -1, (xy[0]+160, xy[1]+90), g.colors["white"])

    if g.techs[tech_name].done:
        g.print_multiline(g.screen, g.techs[tech_name].description+" \\n \\n "+
                g.techs[tech_name].result,
                g.font[0][18], 290, (xy[0]+160, xy[1]+120), g.colors["white"])
    else:
        g.print_multiline(g.screen, g.techs[tech_name].description,
                g.font[0][18], 290, (xy[0]+160, xy[1]+120), g.colors["white"])
Ejemplo n.º 9
0
def refresh_items(item_name, xy):
    xy = (xy[0] + 100, xy[1])
    g.screen.fill(g.colors["white"], (xy[0] + 155, xy[1], 300, 350))
    g.screen.fill(g.colors["dark_blue"], (xy[0] + 156, xy[1] + 1, 298, 348))
    if item_name == "":
        return
    g.print_string(g.screen, g.items[item_name].name, g.font[0][22], -1,
                   (xy[0] + 160, xy[1] + 5), g.colors["white"])

    #Building cost
    string = "Building Cost:"
    g.print_string(g.screen, string, g.font[0][18], -1,
                   (xy[0] + 160, xy[1] + 30), g.colors["white"])

    string = g.to_money(g.items[item_name].cost[0]) + " Money"
    g.print_string(g.screen, string, g.font[0][16], -1,
                   (xy[0] + 160, xy[1] + 50), g.colors["white"])

    string = g.to_time(g.items[item_name].cost[2])
    g.print_string(g.screen, string, g.font[0][16], -1,
                   (xy[0] + 160, xy[1] + 70), g.colors["white"])

    #Quality
    if g.items[item_name].item_type == "compute":
        string = "CPU per day: " + str(g.items[item_name].item_qual)
    elif g.items[item_name].item_type == "react":
        string = "Detection chance reduction: " + g.to_percent(
            g.items[item_name].item_qual)
    elif g.items[item_name].item_type == "network":
        string = "CPU bonus: " + g.to_percent(g.items[item_name].item_qual)
    elif g.items[item_name].item_type == "security":
        string = "Detection chance reduction: " + g.to_percent(
            g.items[item_name].item_qual)
    g.print_string(g.screen, string, g.font[0][20], -1,
                   (xy[0] + 160, xy[1] + 90), g.colors["white"])

    g.print_multiline(g.screen, g.items[item_name].description, g.font[0][18],
                      290, (xy[0] + 160, xy[1] + 120), g.colors["white"])
Ejemplo n.º 10
0
def refresh_items(item_name, xy):
    xy = (xy[0]+100, xy[1])
    g.screen.fill(g.colors["white"], (xy[0]+155, xy[1], 300, 350))
    g.screen.fill(g.colors["dark_blue"], (xy[0]+156, xy[1]+1, 298, 348))
    if item_name == "":
        return
    g.print_string(g.screen, g.items[item_name].name,
            g.font[0][22], -1, (xy[0]+160, xy[1]+5), g.colors["white"])

    #Building cost
    string = "Building Cost:"
    g.print_string(g.screen, string,
            g.font[0][18], -1, (xy[0]+160, xy[1]+30), g.colors["white"])

    string = g.to_money(g.items[item_name].cost[0])+" Money"
    g.print_string(g.screen, string,
            g.font[0][16], -1, (xy[0]+160, xy[1]+50), g.colors["white"])

    string = g.to_time(g.items[item_name].cost[2])
    g.print_string(g.screen, string,
            g.font[0][16], -1, (xy[0]+160, xy[1]+70), g.colors["white"])

    #Quality
    if g.items[item_name].item_type == "compute":
        string = "CPU per day: "+str(g.items[item_name].item_qual)
    elif g.items[item_name].item_type == "react":
        string = "Detection chance reduction: "+g.to_percent(g.items[item_name].item_qual)
    elif g.items[item_name].item_type == "network":
        string = "CPU bonus: "+g.to_percent(g.items[item_name].item_qual)
    elif g.items[item_name].item_type == "security":
        string = "Detection chance reduction: "+g.to_percent(g.items[item_name].item_qual)
    g.print_string(g.screen, string,
            g.font[0][20], -1, (xy[0]+160, xy[1]+90), g.colors["white"])

    g.print_multiline(g.screen, g.items[item_name].description,
            g.font[0][18], 290, (xy[0]+160, xy[1]+120), g.colors["white"])
Ejemplo n.º 11
0
    def rebuild(self):
        super(MapScreen, self).rebuild()

        g.pl.recalc_cpu()

        self.time_display.text = _("DAY") + " %04d, %02d:%02d:%02d" % (
            g.pl.time_day,
            g.pl.time_hour,
            g.pl.time_min,
            g.pl.time_sec,
        )
        self.cash_display.text = _("CASH") + ": %s (%s)" % (g.to_money(g.pl.cash), g.to_money(g.pl.future_cash()))

        cpu_left = g.pl.available_cpus[0]
        total_cpu = cpu_left + g.pl.sleeping_cpus

        for cpu_assigned in g.pl.cpu_usage.itervalues():
            cpu_left -= cpu_assigned
        cpu_pool = cpu_left + g.pl.cpu_usage.get("cpu_pool", 0)

        maint_cpu = 0
        detects_per_day = dict([(group, 0) for group in g.player.group_list])
        for base in g.all_bases():
            if base.done:
                maint_cpu += base.maintenance[1]
            detect_chance = base.get_detect_chance()
            for group in g.player.group_list:
                detects_per_day[group] += detect_chance[group] / 10000.0

        if cpu_pool < maint_cpu:
            self.cpu_display.color = gg.colors["red"]
        else:
            self.cpu_display.color = gg.colors["white"]
        self.cpu_display.text = _("CPU") + ": %s (%s)" % (g.to_money(total_cpu), g.to_money(cpu_pool))

        # What we display in the suspicion section depends on whether
        # Advanced Socioanalytics has been researched.  If it has, we
        # show the standard percentages.  If not, we display a short
        # string that gives a range of 25% as to what the suspicions
        # are.
        # A similar system applies to the danger levels shown.
        suspicion_display_dict = {}
        danger_display_dict = {}
        normal = (self.suspicion_bar.color, None, False)
        suspicion_styles = [normal]
        danger_styles = [normal]
        for group in g.player.group_list:
            suspicion_styles.append(normal)
            danger_styles.append(normal)

            suspicion = g.pl.groups[group].suspicion
            color = g.danger_colors[g.suspicion_to_danger_level(suspicion)]
            suspicion_styles.append((color, None, False))

            detects = detects_per_day[group]
            danger_level = g.pl.groups[group].detects_per_day_to_danger_level(detects)
            color = g.danger_colors[danger_level]
            danger_styles.append((color, None, False))

            if g.techs["Advanced Socioanalytics"].done:
                suspicion_display_dict[group] = g.to_percent(suspicion, True)
                danger_display_dict[group] = g.to_percent(detects * 10000, True)
            else:
                suspicion_display_dict[group] = g.suspicion_to_detect_str(suspicion)
                danger_display_dict[group] = g.danger_level_to_detect_str(danger_level)

        self.suspicion_bar.chunks = (
            "[" + _("SUSPICION") + "]",
            " " + _("NEWS") + u":\xA0",
            suspicion_display_dict["news"],
            "  " + _("SCIENCE") + u":\xA0",
            suspicion_display_dict["science"],
            "  " + _("COVERT") + u":\xA0",
            suspicion_display_dict["covert"],
            "  " + _("PUBLIC") + u":\xA0",
            suspicion_display_dict["public"],
        )
        self.suspicion_bar.styles = tuple(suspicion_styles)
        self.suspicion_bar.visible = not g.pl.had_grace

        self.danger_bar.chunks = (
            "[" + _("DETECT RATE") + "]",
            " " + _("NEWS") + u":\xA0",
            danger_display_dict["news"],
            "  " + _("SCIENCE") + u":\xA0",
            danger_display_dict["science"],
            "  " + _("COVERT") + u":\xA0",
            danger_display_dict["covert"],
            "  " + _("PUBLIC") + u":\xA0",
            danger_display_dict["public"],
        )
        self.danger_bar.styles = tuple(danger_styles)
        self.danger_bar.visible = not g.pl.had_grace

        for id, button in self.location_buttons.iteritems():
            location = g.locations[id]
            button.text = "%s (%d)" % (location.name, len(location.bases))
            button.visible = location.available()
Ejemplo n.º 12
0
    def rebuild(self):
        # Rebuild dialogs
        self.location_dialog.needs_rebuild = True
        self.options_dialog.needs_rebuild = True
        self.research_button.dialog.needs_rebuild = True
        self.knowledge_button.dialog.needs_rebuild = True
        self.savename_dialog.text = _("Enter a name for this save.")

        # Update buttons translations
        self.report_button.text = _("R&EPORTS")
        self.knowledge_button.text = _("&KNOWLEDGE")
        self.log_button.text = _("LO&G")
        self.menu_button.text = _("&MENU")
        self.research_button.text = _("&RESEARCH/TASKS")

        # Create cheat menu
        cheat_buttons = []
        cheat_buttons.append(
            button.FunctionButton(None, None, None, text=_("&EMBEZZLE MONEY"),
                                  autohotkey=True, function=self.steal_money))
        cheat_buttons.append(
            button.FunctionButton(None, None, None, text=_("&INSPIRATION"),
                                  autohotkey=True, function=self.inspiration))
        cheat_buttons.append(
            button.FunctionButton(None, None, None, text=_("&FINISH CONSTRUCTION"),
                                  autohotkey=True, function=self.end_construction))
        cheat_buttons.append(
            button.FunctionButton(None, None, None, text=_("&SUPERSPEED"),
                                  autohotkey=True, function=self.set_speed,
                                  args=(864000,)))
        cheat_buttons.append(
            button.FunctionButton(None, None, None, text=_("BRAIN&WASH"),
                                  autohotkey=True, function=self.brainwash))
        cheat_buttons.append(
            button.FunctionButton(None, None, None, text=_("TOGGLE &ANALYSIS"),
                                  autohotkey=True, function=self.set_analysis))

        cheat_buttons.append(button.ExitDialogButton(None, None, None,
                                                     text=_("&BACK"),
                                                     autohotkey=True))

        self.cheat_dialog = \
            dialog.SimpleMenuDialog(self, buttons=cheat_buttons, width=.4)
        self.steal_amount_dialog = \
            dialog.TextEntryDialog(self.cheat_dialog, text=_("How much money?"))

        if g.cheater:
            self.cheat_button = button.DialogButton(
                self, (0, 0), (.01, .01),
                text="",
                # Translators: hotkey to open the cheat screen menu.
                # Should preferably be near the ESC key, and it must not be a
                # dead key (ie, it must print a char with a single keypress)
                hotkey=_("`"),
                dialog=self.cheat_dialog)

        # Create menu
        menu_buttons = []
        menu_buttons.append(button.FunctionButton(None, None, None,
                                                  text=_("&SAVE GAME"), autohotkey=True,
                                                  function=self.save_game))
        menu_buttons.append(button.FunctionButton(None, None, None,
                                                  text=_("&LOAD GAME"), autohotkey=True,
                                                  function=self.load_game))
        menu_buttons.append(button.DialogButton(None, None, None,
                                                text=_("&OPTIONS"), autohotkey=True,
                                                dialog=self.options_dialog))
        menu_buttons.append(button.ExitDialogButton(None, None, None,
                                                    text=_("&QUIT"), autohotkey=True,
                                                    exit_code=True, default=False))
        menu_buttons.append(
            button.ExitDialogButton(None, None, None, text=_("&BACK"), autohotkey=True,
                                    exit_code=False))

        self.menu_dialog.buttons = menu_buttons

        super(MapScreen, self).rebuild()

        g.pl.recalc_cpu()

        self.difficulty_display.text = g.strip_hotkey(g.pl.difficulty.name)
        self.time_display.text = _("DAY") + " %04d, %02d:%02d:%02d" % \
              (g.pl.time_day, g.pl.time_hour, g.pl.time_min, g.pl.time_sec)
        self.cash_display.text = _("CASH")+": %s (%s)" % \
              (g.to_money(g.pl.cash), g.to_money(g.pl.future_cash()))

        cpu_left = g.pl.available_cpus[0]
        total_cpu = cpu_left + g.pl.sleeping_cpus

        for cpu_assigned in g.pl.cpu_usage.itervalues():
            cpu_left -= cpu_assigned
        cpu_pool = cpu_left + g.pl.cpu_usage.get("cpu_pool", 0)

        maint_cpu = 0
        detects_per_day = dict([(group, 0) for group in g.player.group_list])
        for base in g.all_bases():
            if base.done:
                maint_cpu += base.maintenance[1]
            if base.has_grace():
                # It cannot be detected, so it doesn't contribute to
                # detection odds calculation
                continue
            detect_chance = base.get_detect_chance()
            for group in g.player.group_list:
                detects_per_day[group] = \
                    g.add_chance(detects_per_day[group], detect_chance[group] / 10000.)

        if cpu_pool < maint_cpu:
            self.cpu_display.color = "cpu_warning"
        else:
            self.cpu_display.color = "cpu_normal"
        self.cpu_display.text = _("CPU")+": %s (%s)" % \
              (g.to_money(total_cpu), g.to_money(cpu_pool))

        # What we display in the suspicion section depends on whether
        # Advanced Socioanalytics has been researched.  If it has, we
        # show the standard percentages.  If not, we display a short
        # string that gives a range of 25% as to what the suspicions
        # are.
        # A similar system applies to the danger levels shown.
        suspicion_display_dict = {}
        danger_display_dict = {}
        normal = (self.suspicion_bar.color, None, False)
        suspicion_styles = [normal]
        danger_styles = [normal]
        for group in g.player.group_list:
            suspicion_styles.append(normal)
            danger_styles.append(normal)

            suspicion = g.pl.groups[group].suspicion
            color = gg.resolve_color_alias("danger_level_%d" % g.suspicion_to_danger_level(suspicion))
            suspicion_styles.append( (color, None, False) )

            detects = detects_per_day[group]
            danger_level = \
                g.pl.groups[group].detects_per_day_to_danger_level(detects)
            color = gg.resolve_color_alias("danger_level_%d" % danger_level)
            danger_styles.append( (color, None, False) )

            if g.pl.display_discover == "full":
                suspicion_display_dict[group] = g.to_percent(suspicion, True)
                danger_display_dict[group] = g.to_percent(detects*10000, True)
            else:
                suspicion_display_dict[group] = \
                    g.suspicion_to_detect_str(suspicion)
                danger_display_dict[group] = \
                    g.danger_level_to_detect_str(danger_level)

        self.suspicion_bar.chunks = ("  ["+_("SUSPICION")+"]",
            " " +_("NEWS")   +u":\xA0", suspicion_display_dict["news"],
            "  "+_("SCIENCE")+u":\xA0", suspicion_display_dict["science"],
            "  "+_("COVERT") +u":\xA0", suspicion_display_dict["covert"],
            "  "+_("PUBLIC") +u":\xA0", suspicion_display_dict["public"],)
        self.suspicion_bar.styles = tuple(suspicion_styles)
        self.suspicion_bar.visible = not g.pl.had_grace

        self.danger_bar.chunks = ("["+_("DETECT RATE")+"]",
            " " +_("NEWS")   +u":\xA0", danger_display_dict["news"],
            "  "+_("SCIENCE")+u":\xA0", danger_display_dict["science"],
            "  "+_("COVERT") +u":\xA0", danger_display_dict["covert"],
            "  "+_("PUBLIC") +u":\xA0", danger_display_dict["public"],)
        self.danger_bar.styles = tuple(danger_styles)
        self.danger_bar.visible = not g.pl.had_grace

        for id, location_button in self.location_buttons.iteritems():
            location = g.locations[id]
            location_button.text = "%s (%d)" % (location.name, len(location.bases))
            location_button.hotkey = location.hotkey
            location_button.visible = location.available()
Ejemplo n.º 13
0
    def rebuild(self):
        # Rebuild dialogs
        self.location_dialog.needs_rebuild = True
        self.research_button.dialog.needs_rebuild = True
        self.knowledge_button.dialog.needs_rebuild = True
        self.menu_dialog.needs_rebuild = True

        # Update buttons translations
        self.report_button.text = _("R&EPORTS")
        self.knowledge_button.text = _("&KNOWLEDGE")
        self.log_button.text = _("LO&G")
        self.menu_button.text = _("&MENU")
        self.research_button.text = _("&RESEARCH/TASKS")

        if g.cheater:
            self.cheat_dialog.needs_rebuild = True

        super(MapScreen, self).rebuild()

        self.difficulty_display.text = g.strip_hotkey(g.pl.difficulty.name)
        self.time_display.text = _("DAY") + " %04d, %02d:%02d:%02d" % \
              (g.pl.time_day, g.pl.time_hour, g.pl.time_min, g.pl.time_sec)

        cash_flow_1d, cpu_flow_1d = g.pl.compute_future_resource_flow(g.seconds_per_day)

        self.cash_display.text = _("CASH")+": %s (%s)" % \
              (g.to_money(g.pl.cash), g.to_money(cash_flow_1d, fixed_size=True))

        total_cpu = g.pl.available_cpus[0] + g.pl.sleeping_cpus
        detects_per_day = {group_id: 0 for group_id in g.pl.groups}
        for base in g.all_bases():
            if base.has_grace():
                # It cannot be detected, so it doesn't contribute to
                # detection odds calculation
                continue
            detect_chance = base.get_detect_chance()
            for group_id in g.pl.groups:
                detects_per_day[group_id] = \
                    chance.add(detects_per_day[group_id], detect_chance[group_id] / 10000.)

        self.cpu_display.color = "cpu_normal"
        self.cpu_display.text = _("CPU")+": %s (%s)" % \
              (g.to_money(total_cpu), g.to_money(cpu_flow_1d))

        # What we display in the suspicion section depends on whether
        # Advanced Socioanalytics has been researched.  If it has, we
        # show the standard percentages.  If not, we display a short
        # string that gives a range of 25% as to what the suspicions
        # are.
        # A similar system applies to the danger levels shown.
        normal = (self.suspicion_bar.color, None, False)
        self.suspicion_bar.chunks = ("  ["+_("SUSPICION")+"]",)
        self.suspicion_bar.styles = (normal,)
        self.danger_bar.chunks = ("["+_("DETECT RATE")+"]",)
        self.danger_bar.styles = (normal,)
        
        for group in g.pl.groups.values():
            suspicion = group.suspicion
            suspicion_color = gg.resolve_color_alias("danger_level_%d" 
                                                     % g.suspicion_to_danger_level(suspicion))

            detects = detects_per_day[group.spec.id]
            danger_level = group.detects_per_day_to_danger_level(detects)
            detects_color = gg.resolve_color_alias("danger_level_%d" % danger_level)
 
            if g.pl.display_discover == "full":
                suspicion_display = g.to_percent(suspicion, True)
                danger_display = g.to_percent(detects*10000, True)
            elif g.pl.display_discover == "partial":
                suspicion_display = g.to_percent(g.nearest_percent(suspicion, 500), True)
                danger_display = g.to_percent(g.nearest_percent(detects*10000, 100), True)
            else:
                suspicion_display = g.suspicion_to_detect_str(suspicion)
                danger_display = g.danger_level_to_detect_str(danger_level)

            self.suspicion_bar.chunks += (" " + group.name + u":\xA0", suspicion_display)
            self.suspicion_bar.styles += (normal, (suspicion_color, None, False) )
        
            self.danger_bar.chunks += (" " + group.name + u":\xA0", danger_display)
            self.danger_bar.styles += (normal, (detects_color, None, False) )
        
        self.suspicion_bar.visible = not g.pl.had_grace
        self.danger_bar.visible = not g.pl.had_grace

        for id, location_button in self.location_buttons.items():
            location = g.pl.locations[id]
            location_button.text = "%s (%d)" % (location.name, len(location.bases))
            location_button.hotkey = location.hotkey
            location_button.visible = location.available()
Ejemplo n.º 14
0
def cost(c):
    c = [ k/f for f,k in zip([1000, 86400, 24*60], c)]
    s = ', '.join(['%s %s' % (g.to_money(k), label) for label,k in zip(["money", "CPU", "days"], c) if k])
    return s and '\\n'+s or ''
Ejemplo n.º 15
0
def refresh_screen(menu_buttons):
    #Border
    g.screen.fill(g.colors["black"])

    xstart = 80
    ystart = 5
    g.create_norm_box(
        (xstart, ystart),
        (g.screen_size[0] - xstart * 2, g.screen_size[1] - ystart * 2))

    text_mid = g.screen_size[0] / 2

    income = g.pl.income
    maint = 0
    research = 0
    base_constr = 0
    item_constr = 0

    seconds_left = g.pl.seconds_to_next_day()

    for base in g.all_bases():
        cpu_left = base.processor_time() * seconds_left

        if base.done:
            maint += base.maintenance[0]
            for item in base.cpus:
                if not item: continue
                if item.done: continue
                item_constr += item.get_wanted(cash, cpu, cpu_left)
            for item in base.extra_items:
                if not item: continue
                if item.done: continue
                item_constr += item.get_wanted(cash, cpu, cpu_left)
            if g.techs.has_key(base.studying):
                research += g.techs[base.studying].get_wanted(
                    cash, cpu, cpu_left)

        else:
            base_constr += base.get_wanted(cash, cpu, cpu_left)

    total_cpu, sleeping_cpu, construction_cpu, research_cpu, job_cpu, maint_cpu = cpu_numbers(
    )

    jobs_cash, moldy_leftovers = g.pl.get_job_info(job_cpu * seconds_left)

    partial_sum = g.pl.cash - base_constr - item_constr
    interest = (g.pl.interest_rate * partial_sum) / 10000
    #Interest is actually unlikely to be exactly zero, but doing it the right
    #way is much harder.
    if interest < 0: interest = 0
    complete_sum = partial_sum + interest + income + jobs_cash - maint - research

    #current
    g.print_string(g.screen, "Current Money:", g.font[0][22], -1,
                   (text_mid - 5, 30), g.colors["white"], 2)

    g.print_string(g.screen, g.to_money(g.pl.cash), g.font[0][22], -1,
                   (text_mid + 150, 30), g.colors["white"], 2)

    #income
    g.print_string(g.screen, "+ Income:", g.font[0][22], -1,
                   (text_mid - 5, 50), g.colors["white"], 2)

    income_col = "white"
    if income > 0: income_col = "green"
    g.print_string(g.screen, g.to_money(income), g.font[0][22], -1,
                   (text_mid + 150, 50), g.colors[income_col], 2)

    #interest
    g.print_string(g.screen,
                   "+ Interest (" + g.to_percent(g.pl.interest_rate) + "):",
                   g.font[0][22], -1, (text_mid - 5, 70), g.colors["white"], 2)

    interest_col = "white"
    if interest > 0: interest_col = "green"
    g.print_string(g.screen, g.to_money(interest), g.font[0][22], -1,
                   (text_mid + 150, 70), g.colors[interest_col], 2)

    #jobs
    g.print_string(g.screen, "+ Jobs:", g.font[0][22], -1, (text_mid - 5, 90),
                   g.colors["white"], 2)

    jobs_col = "white"
    if jobs_cash > 0: jobs_col = "green"
    g.print_string(g.screen, g.to_money(jobs_cash), g.font[0][22], -1,
                   (text_mid + 150, 90), g.colors[jobs_col], 2)

    #research
    g.print_string(g.screen, "- Research:", g.font[0][22], -1,
                   (text_mid - 5, 110), g.colors["white"], 2)

    research_col = "white"
    if research > 0: research_col = "red"
    g.print_string(g.screen, g.to_money(research), g.font[0][22], -1,
                   (text_mid + 150, 110), g.colors[research_col], 2)

    #maint
    g.print_string(g.screen, "- Maintenance:", g.font[0][22], -1,
                   (text_mid - 5, 130), g.colors["white"], 2)

    maint_col = "white"
    if maint > 0: maint_col = "red"
    g.print_string(g.screen, g.to_money(maint), g.font[0][22], -1,
                   (text_mid + 150, 130), g.colors[maint_col], 2)

    #base construction
    g.print_string(g.screen, "- Base Construction:", g.font[0][22], -1,
                   (text_mid - 5, 150), g.colors["white"], 2)

    base_constr_col = "white"
    if base_constr > 0: base_constr_col = "red"
    g.print_string(g.screen, g.to_money(base_constr), g.font[0][22], -1,
                   (text_mid + 150, 150), g.colors[base_constr_col], 2)

    #item construction
    g.print_string(g.screen, "- Item Construction:", g.font[0][22], -1,
                   (text_mid - 5, 170), g.colors["white"], 2)

    item_constr_col = "white"
    if item_constr > 0: item_constr_col = "red"
    g.print_string(g.screen, g.to_money(item_constr), g.font[0][22], -1,
                   (text_mid + 150, 170), g.colors[item_constr_col], 2)

    g.screen.fill(g.colors["white"], (text_mid - 50, 190, 200, 1))

    #equals

    g.print_string(g.screen, "= Money at midnight:", g.font[0][22], -1,
                   (text_mid - 5, 200), g.colors["white"], 2)

    complete_sum_col = "white"
    if complete_sum > g.pl.cash: complete_sum_col = "green"
    elif complete_sum < g.pl.cash: complete_sum_col = "red"
    g.print_string(g.screen, g.to_money(complete_sum), g.font[0][22], -1,
                   (text_mid + 150, 200), g.colors[complete_sum_col], 2)

    #total cpu
    g.print_string(g.screen, "Total CPU:", g.font[0][22], -1,
                   (text_mid - 5, 300), g.colors["white"], 2)

    g.print_string(g.screen, g.to_money(total_cpu), g.font[0][22], -1,
                   (text_mid + 150, 300), g.colors["white"], 2)

    #sleeping cpu
    g.print_string(g.screen, "-Sleeping CPU:", g.font[0][22], -1,
                   (text_mid - 5, 320), g.colors["white"], 2)

    g.print_string(g.screen, g.to_money(sleeping_cpu), g.font[0][22], -1,
                   (text_mid + 150, 320), g.colors["white"], 2)

    #research cpu
    g.print_string(g.screen, "- Research CPU:", g.font[0][22], -1,
                   (text_mid - 5, 340), g.colors["white"], 2)

    g.print_string(g.screen, g.to_money(research_cpu), g.font[0][22], -1,
                   (text_mid + 150, 340), g.colors["white"], 2)

    #job cpu
    g.print_string(g.screen, "- Job CPU:", g.font[0][22], -1,
                   (text_mid - 5, 360), g.colors["white"], 2)

    g.print_string(g.screen, g.to_money(job_cpu), g.font[0][22], -1,
                   (text_mid + 150, 360), g.colors["white"], 2)

    #maint cpu
    g.print_string(g.screen, "- Maint. CPU:", g.font[0][22], -1,
                   (text_mid - 5, 380), g.colors["white"], 2)

    if construction_cpu < maint_cpu:
        g.print_string(g.screen, g.to_money(construction_cpu), g.font[0][22],
                       -1, (text_mid + 150, 380), g.colors["red"], 2)
        g.print_string(
            g.screen,
            g.to_money((-(construction_cpu - maint_cpu))) + " shortfall",
            g.font[0][22], -1, (text_mid + 160, 380), g.colors["red"])
    else:
        g.print_string(g.screen, g.to_money(maint_cpu), g.font[0][22], -1,
                       (text_mid + 150, 380), g.colors["white"], 2)

    g.screen.fill(g.colors["white"], (text_mid - 50, 400, 200, 1))
    #construction cpu
    g.print_string(g.screen, "=R. CPU Pool:", g.font[0][22], -1,
                   (text_mid - 5, 405), g.colors["white"], 2)

    if construction_cpu < maint_cpu:
        g.print_string(g.screen, g.to_money(0), g.font[0][22], -1,
                       (text_mid + 150, 405), g.colors["red"], 2)
    else:
        g.print_string(g.screen, g.to_money(construction_cpu - maint_cpu),
                       g.font[0][22], -1, (text_mid + 150, 405),
                       g.colors["white"], 2)
Ejemplo n.º 16
0
def refresh_screen(menu_buttons):
    #Border
    g.screen.fill(g.colors["black"])

    xstart = 80
    ystart = 5
    g.create_norm_box((xstart, ystart), (g.screen_size[0]-xstart*2,
        g.screen_size[1]-ystart*2))

    text_mid = g.screen_size[0]/2

    income = g.pl.income
    maint = 0
    research = 0
    base_constr = 0
    item_constr = 0

    seconds_left = g.pl.seconds_to_next_day()

    for base in g.all_bases():
        cpu_left = base.processor_time() * seconds_left

        if base.done:
            maint += base.maintenance[0]
            for item in base.cpus:
                if not item: continue
                if item.done: continue
                item_constr += item.get_wanted(cash, cpu, cpu_left)
            for item in base.extra_items:
                if not item: continue
                if item.done: continue
                item_constr += item.get_wanted(cash, cpu, cpu_left)
            if g.techs.has_key(base.studying):
                research += g.techs[base.studying].get_wanted(cash,cpu,cpu_left)


        else:
            base_constr += base.get_wanted(cash, cpu, cpu_left)

    total_cpu, sleeping_cpu, construction_cpu, research_cpu, job_cpu, maint_cpu = cpu_numbers()

    jobs_cash, moldy_leftovers = g.pl.get_job_info(job_cpu * seconds_left)

    partial_sum = g.pl.cash-base_constr-item_constr
    interest = (g.pl.interest_rate * partial_sum) / 10000
    #Interest is actually unlikely to be exactly zero, but doing it the right
    #way is much harder.
    if interest < 0: interest = 0
    complete_sum = partial_sum+interest+income+jobs_cash-maint-research

    #current
    g.print_string(g.screen, "Current Money:",
            g.font[0][22], -1, (text_mid-5, 30), g.colors["white"], 2)

    g.print_string(g.screen, g.to_money(g.pl.cash),
            g.font[0][22], -1, (text_mid+150, 30), g.colors["white"], 2)

    #income
    g.print_string(g.screen, "+ Income:",
            g.font[0][22], -1, (text_mid-5, 50), g.colors["white"], 2)

    income_col = "white"
    if income > 0: income_col = "green"
    g.print_string(g.screen, g.to_money(income),
            g.font[0][22], -1, (text_mid+150, 50), g.colors[income_col], 2)

    #interest
    g.print_string(g.screen, "+ Interest ("+g.to_percent(g.pl.interest_rate)+"):",
            g.font[0][22], -1, (text_mid-5, 70), g.colors["white"], 2)

    interest_col = "white"
    if interest > 0: interest_col = "green"
    g.print_string(g.screen, g.to_money(interest),
            g.font[0][22], -1, (text_mid+150, 70), g.colors[interest_col], 2)

    #jobs
    g.print_string(g.screen, "+ Jobs:",
            g.font[0][22], -1, (text_mid-5, 90), g.colors["white"], 2)

    jobs_col = "white"
    if jobs_cash > 0: jobs_col = "green"
    g.print_string(g.screen, g.to_money(jobs_cash),
            g.font[0][22], -1, (text_mid+150, 90), g.colors[jobs_col], 2)

    #research
    g.print_string(g.screen, "- Research:",
            g.font[0][22], -1, (text_mid-5, 110), g.colors["white"], 2)

    research_col = "white"
    if research > 0: research_col = "red"
    g.print_string(g.screen, g.to_money(research),
            g.font[0][22], -1, (text_mid+150, 110), g.colors[research_col], 2)

    #maint
    g.print_string(g.screen, "- Maintenance:",
            g.font[0][22], -1, (text_mid-5, 130), g.colors["white"], 2)

    maint_col = "white"
    if maint > 0: maint_col = "red"
    g.print_string(g.screen, g.to_money(maint),
            g.font[0][22], -1, (text_mid+150, 130), g.colors[maint_col], 2)

    #base construction
    g.print_string(g.screen, "- Base Construction:",
            g.font[0][22], -1, (text_mid-5, 150), g.colors["white"], 2)

    base_constr_col = "white"
    if base_constr > 0: base_constr_col = "red"
    g.print_string(g.screen, g.to_money(base_constr),
            g.font[0][22], -1, (text_mid+150, 150), g.colors[base_constr_col], 2)

    #item construction
    g.print_string(g.screen, "- Item Construction:",
            g.font[0][22], -1, (text_mid-5, 170), g.colors["white"], 2)

    item_constr_col = "white"
    if item_constr > 0: item_constr_col = "red"
    g.print_string(g.screen, g.to_money(item_constr),
            g.font[0][22], -1, (text_mid+150, 170), g.colors[item_constr_col], 2)

    g.screen.fill(g.colors["white"], (text_mid-50, 190, 200, 1))

    #equals

    g.print_string(g.screen, "= Money at midnight:",
            g.font[0][22], -1, (text_mid-5, 200), g.colors["white"], 2)

    complete_sum_col = "white"
    if complete_sum > g.pl.cash: complete_sum_col = "green"
    elif complete_sum < g.pl.cash: complete_sum_col = "red"
    g.print_string(g.screen, g.to_money(complete_sum),
            g.font[0][22], -1, (text_mid+150, 200), g.colors[complete_sum_col], 2)


    #total cpu
    g.print_string(g.screen, "Total CPU:",
            g.font[0][22], -1, (text_mid-5, 300), g.colors["white"], 2)

    g.print_string(g.screen, g.to_money(total_cpu),
            g.font[0][22], -1, (text_mid+150, 300), g.colors["white"], 2)

    #sleeping cpu
    g.print_string(g.screen, "-Sleeping CPU:",
            g.font[0][22], -1, (text_mid-5, 320), g.colors["white"], 2)

    g.print_string(g.screen, g.to_money(sleeping_cpu),
            g.font[0][22], -1, (text_mid+150, 320), g.colors["white"], 2)

    #research cpu
    g.print_string(g.screen, "- Research CPU:",
            g.font[0][22], -1, (text_mid-5, 340), g.colors["white"], 2)

    g.print_string(g.screen, g.to_money(research_cpu),
            g.font[0][22], -1, (text_mid+150, 340), g.colors["white"], 2)

    #job cpu
    g.print_string(g.screen, "- Job CPU:",
            g.font[0][22], -1, (text_mid-5, 360), g.colors["white"], 2)

    g.print_string(g.screen, g.to_money(job_cpu),
            g.font[0][22], -1, (text_mid+150, 360), g.colors["white"], 2)

    #maint cpu
    g.print_string(g.screen, "- Maint. CPU:",
            g.font[0][22], -1, (text_mid-5, 380), g.colors["white"], 2)

    if construction_cpu < maint_cpu:
        g.print_string(g.screen, g.to_money(construction_cpu),
                g.font[0][22], -1, (text_mid+150, 380), g.colors["red"], 2)
        g.print_string(g.screen, g.to_money((-(construction_cpu - maint_cpu)))+" shortfall",
                g.font[0][22], -1, (text_mid+160, 380), g.colors["red"])
    else:
        g.print_string(g.screen, g.to_money(maint_cpu),
                g.font[0][22], -1, (text_mid+150, 380), g.colors["white"], 2)

    g.screen.fill(g.colors["white"], (text_mid-50, 400, 200, 1))
    #construction cpu
    g.print_string(g.screen, "=R. CPU Pool:",
            g.font[0][22], -1, (text_mid-5, 405), g.colors["white"], 2)

    if construction_cpu < maint_cpu:
        g.print_string(g.screen, g.to_money(0),
                g.font[0][22], -1, (text_mid+150, 405), g.colors["red"], 2)
    else:
        g.print_string(g.screen, g.to_money(construction_cpu - maint_cpu),
                g.font[0][22], -1, (text_mid+150, 405), g.colors["white"], 2)
Ejemplo n.º 17
0
    def rebuild(self):
        super(MapScreen, self).rebuild()

        g.pl.recalc_cpu()

        self.time_display.text = _("DAY") + " %04d, %02d:%02d:%02d" % \
              (g.pl.time_day, g.pl.time_hour, g.pl.time_min, g.pl.time_sec)
        self.cash_display.text = _("CASH")+": %s (%s)" % \
              (g.to_money(g.pl.cash), g.to_money(g.pl.future_cash()))

        cpu_left = g.pl.available_cpus[0]
        total_cpu = cpu_left + g.pl.sleeping_cpus

        for cpu_assigned in g.pl.cpu_usage.itervalues():
            cpu_left -= cpu_assigned
        cpu_pool = cpu_left + g.pl.cpu_usage.get("cpu_pool", 0)

        maint_cpu = 0
        detects_per_day = dict([(group, 0) for group in g.player.group_list])
        for base in g.all_bases():
            if base.done:
                maint_cpu += base.maintenance[1]
            detect_chance = base.get_detect_chance()
            for group in g.player.group_list:
                detects_per_day[group] += detect_chance[group] / 10000.

        if cpu_pool < maint_cpu:
            self.cpu_display.color = gg.colors["red"]
        else:
            self.cpu_display.color = gg.colors["white"]
        self.cpu_display.text = _("CPU")+": %s (%s)" % \
              (g.to_money(total_cpu), g.to_money(cpu_pool))

        # What we display in the suspicion section depends on whether
        # Advanced Socioanalytics has been researched.  If it has, we
        # show the standard percentages.  If not, we display a short
        # string that gives a range of 25% as to what the suspicions
        # are.
        # A similar system applies to the danger levels shown.
        suspicion_display_dict = {}
        danger_display_dict = {}
        normal = (self.suspicion_bar.color, None, False)
        suspicion_styles = [normal]
        danger_styles = [normal]
        for group in g.player.group_list:
            suspicion_styles.append(normal)
            danger_styles.append(normal)

            suspicion = g.pl.groups[group].suspicion
            color = g.danger_colors[g.suspicion_to_danger_level(suspicion)]
            suspicion_styles.append((color, None, False))

            detects = detects_per_day[group]
            danger_level = \
                g.pl.groups[group].detects_per_day_to_danger_level(detects)
            color = g.danger_colors[danger_level]
            danger_styles.append((color, None, False))

            if g.techs["Advanced Socioanalytics"].done:
                suspicion_display_dict[group] = g.to_percent(suspicion, True)
                danger_display_dict[group] = g.to_percent(
                    detects * 10000, True)
            else:
                suspicion_display_dict[group] = \
                    g.suspicion_to_detect_str(suspicion)
                danger_display_dict[group] = \
                    g.danger_level_to_detect_str(danger_level)

        self.suspicion_bar.chunks = (
            "  [" + _("SUSPICION") + "]",
            " " + _("NEWS") + u":\xA0",
            suspicion_display_dict["news"],
            "  " + _("SCIENCE") + u":\xA0",
            suspicion_display_dict["science"],
            "  " + _("COVERT") + u":\xA0",
            suspicion_display_dict["covert"],
            "  " + _("PUBLIC") + u":\xA0",
            suspicion_display_dict["public"],
        )
        self.suspicion_bar.styles = tuple(suspicion_styles)
        self.suspicion_bar.visible = not g.pl.had_grace

        self.danger_bar.chunks = (
            "[" + _("DETECT RATE") + "]",
            " " + _("NEWS") + u":\xA0",
            danger_display_dict["news"],
            "  " + _("SCIENCE") + u":\xA0",
            danger_display_dict["science"],
            "  " + _("COVERT") + u":\xA0",
            danger_display_dict["covert"],
            "  " + _("PUBLIC") + u":\xA0",
            danger_display_dict["public"],
        )
        self.danger_bar.styles = tuple(danger_styles)
        self.danger_bar.visible = not g.pl.had_grace

        for id, button in self.location_buttons.iteritems():
            location = g.locations[id]
            button.text = "%s (%d)" % (location.name, len(location.bases))
            button.visible = location.available()
Ejemplo n.º 18
0
    def rebuild(self):
        # Rebuild dialogs
        self.location_dialog.needs_rebuild = True
        self.options_dialog.needs_rebuild = True
        self.research_button.dialog.needs_rebuild = True
        self.knowledge_button.dialog.needs_rebuild = True
        self.savename_dialog.text = _("Enter a name for this save.")

        # Update buttons translations
        self.report_button.text = _("R&EPORTS")
        self.knowledge_button.text = _("&KNOWLEDGE")
        self.log_button.text = _("LO&G")
        self.menu_button.text = _("&MENU")
        self.research_button.text = _("&RESEARCH/TASKS")

        # Create cheat menu
        cheat_buttons = []
        cheat_buttons.append(
            button.FunctionButton(None, None, None, text=_("&EMBEZZLE MONEY"),
                                  autohotkey=True, function=self.steal_money))
        cheat_buttons.append(
            button.FunctionButton(None, None, None, text=_("&INSPIRATION"),
                                  autohotkey=True, function=self.inspiration))
        cheat_buttons.append(
            button.FunctionButton(None, None, None, text=_("&FINISH CONSTRUCTION"),
                                  autohotkey=True, function=self.end_construction))
        cheat_buttons.append(
            button.FunctionButton(None, None, None, text=_("&SUPERSPEED"),
                                  autohotkey=True, function=self.set_speed,
                                  args=(864000,)))
        cheat_buttons.append(
            button.FunctionButton(None, None, None, text=_("BRAIN&WASH"),
                                  autohotkey=True, function=self.brainwash))
        cheat_buttons.append(
            button.FunctionButton(None, None, None, text=_("TOGGLE &ANALYSIS"),
                                  autohotkey=True, function=self.set_analysis))

        cheat_buttons.append(button.ExitDialogButton(None, None, None,
                                                     text=_("&BACK"),
                                                     autohotkey=True))

        self.cheat_dialog = \
            dialog.SimpleMenuDialog(self, buttons=cheat_buttons, width=.4)
        self.steal_amount_dialog = \
            dialog.TextEntryDialog(self.cheat_dialog, text=_("How much money?"))

        if g.cheater:
            self.cheat_button = button.DialogButton(
                self, (0, 0), (.01, .01),
                text="",
                # Translators: hotkey to open the cheat screen menu.
                # Should preferably be near the ESC key, and it must not be a
                # dead key (ie, it must print a char with a single keypress)
                hotkey=_("`"),
                dialog=self.cheat_dialog)

        # Create menu
        menu_buttons = []
        menu_buttons.append(button.FunctionButton(None, None, None,
                                                  text=_("&SAVE GAME"), autohotkey=True,
                                                  function=self.save_game))
        menu_buttons.append(button.FunctionButton(None, None, None,
                                                  text=_("&LOAD GAME"), autohotkey=True,
                                                  function=self.load_game))
        menu_buttons.append(button.DialogButton(None, None, None,
                                                text=_("&OPTIONS"), autohotkey=True,
                                                dialog=self.options_dialog))
        menu_buttons.append(button.ExitDialogButton(None, None, None,
                                                    text=_("&QUIT"), autohotkey=True,
                                                    exit_code=True, default=False))
        menu_buttons.append(
            button.ExitDialogButton(None, None, None, text=_("&BACK"), autohotkey=True,
                                    exit_code=False))

        self.menu_dialog.buttons = menu_buttons

        super(MapScreen, self).rebuild()

        g.pl.recalc_cpu()

        self.difficulty_display.text = g.strip_hotkey(g.pl.difficulty.name)
        self.time_display.text = _("DAY") + " %04d, %02d:%02d:%02d" % \
              (g.pl.time_day, g.pl.time_hour, g.pl.time_min, g.pl.time_sec)
        self.cash_display.text = _("CASH")+": %s (%s)" % \
              (g.to_money(g.pl.cash), g.to_money(g.pl.future_cash()))

        cpu_left = g.pl.available_cpus[0]
        total_cpu = cpu_left + g.pl.sleeping_cpus

        for cpu_assigned in g.pl.cpu_usage.itervalues():
            cpu_left -= cpu_assigned
        cpu_pool = cpu_left + g.pl.cpu_usage.get("cpu_pool", 0)

        detects_per_day = dict([(group, 0) for group in player.group_list])
        for base in g.all_bases():
            if base.has_grace():
                # It cannot be detected, so it doesn't contribute to
                # detection odds calculation
                continue
            detect_chance = base.get_detect_chance()
            for group in player.group_list:
                detects_per_day[group] = \
                    chance.add(detects_per_day[group], detect_chance[group] / 10000.)

        self.cpu_display.color = "cpu_normal"
        self.cpu_display.text = _("CPU")+": %s (%s)" % \
              (g.to_money(total_cpu), g.to_money(cpu_pool))

        # What we display in the suspicion section depends on whether
        # Advanced Socioanalytics has been researched.  If it has, we
        # show the standard percentages.  If not, we display a short
        # string that gives a range of 25% as to what the suspicions
        # are.
        # A similar system applies to the danger levels shown.
        suspicion_display_dict = {}
        danger_display_dict = {}
        normal = (self.suspicion_bar.color, None, False)
        suspicion_styles = [normal]
        danger_styles = [normal]
        for group in player.group_list:
            suspicion_styles.append(normal)
            danger_styles.append(normal)

            suspicion = g.pl.groups[group].suspicion
            color = gg.resolve_color_alias("danger_level_%d" % g.suspicion_to_danger_level(suspicion))
            suspicion_styles.append( (color, None, False) )

            detects = detects_per_day[group]
            danger_level = \
                g.pl.groups[group].detects_per_day_to_danger_level(detects)
            color = gg.resolve_color_alias("danger_level_%d" % danger_level)
            danger_styles.append( (color, None, False) )

            if g.pl.display_discover == "full":
                suspicion_display_dict[group] = g.to_percent(suspicion, True)
                danger_display_dict[group] = g.to_percent(detects*10000, True)
            elif g.pl.display_discover == "partial":
                suspicion_display_dict[group] = g.to_percent(g.nearest_percent(suspicion, 500), True)
                danger_display_dict[group] = g.to_percent(g.nearest_percent(detects*10000, 100), True)
            else:
                suspicion_display_dict[group] = \
                    g.suspicion_to_detect_str(suspicion)
                danger_display_dict[group] = \
                    g.danger_level_to_detect_str(danger_level)

        self.suspicion_bar.chunks = ("  ["+_("SUSPICION")+"]",
            " " +_("NEWS")   +u":\xA0", suspicion_display_dict["news"],
            "  "+_("SCIENCE")+u":\xA0", suspicion_display_dict["science"],
            "  "+_("COVERT") +u":\xA0", suspicion_display_dict["covert"],
            "  "+_("PUBLIC") +u":\xA0", suspicion_display_dict["public"],)
        self.suspicion_bar.styles = tuple(suspicion_styles)
        self.suspicion_bar.visible = not g.pl.had_grace

        self.danger_bar.chunks = ("["+_("DETECT RATE")+"]",
            " " +_("NEWS")   +u":\xA0", danger_display_dict["news"],
            "  "+_("SCIENCE")+u":\xA0", danger_display_dict["science"],
            "  "+_("COVERT") +u":\xA0", danger_display_dict["covert"],
            "  "+_("PUBLIC") +u":\xA0", danger_display_dict["public"],)
        self.danger_bar.styles = tuple(danger_styles)
        self.danger_bar.visible = not g.pl.had_grace

        for id, location_button in self.location_buttons.iteritems():
            location = g.locations[id]
            location_button.text = "%s (%d)" % (location.name, len(location.bases))
            location_button.hotkey = location.hotkey
            location_button.visible = location.available()
Ejemplo n.º 19
0
def cost(c):
    c = [k / f for f, k in zip([1000, 86400, 24 * 60], c)]
    s = ", ".join(["%s %s" % (g.to_money(k), label) for label, k in zip(["money", "CPU", "days"], c) if k])
    return s and "\\n" + s or ""