Ejemplo n.º 1
0
class TechSpec(buyable.BuyableSpec):
    spec_type = 'tech'
    created = stat(spec_type + "_created")
    spec_data_fields = [
        buyable.SPEC_FIELD_COST,
        buyable.SPEC_FIELD_PREREQUISITES,
        SpecDataField('danger', converter=int, default_value=0),
        spec_field_effect(mandatory=False),
    ]

    def __init__(self, id, cost, prerequisites, danger, effect_data):
        super(TechSpec, self).__init__(id, cost, prerequisites)

        self.result = ""
        self.danger = danger
        self.effect = effect.Effect(self, effect_data)
Ejemplo n.º 2
0
class ItemSpec(buyable.BuyableSpec):
    """ Item as a buyable item """

    spec_type = 'item'
    created = stat(spec_type + "_created")
    spec_data_fields = [
        buyable.SPEC_FIELD_COST,
        buyable.SPEC_FIELD_PREREQUISITES,
        SpecDataField('item_type',
                      data_field_name='type',
                      converter=convert_item_types),
        SpecDataField('qualities',
                      data_field_name='quality',
                      converter=convert_item_qualities),
        SpecDataField('buildable',
                      data_field_name='build',
                      converter=promote_to_list,
                      default_value=list),
    ]

    def __init__(self, id, cost, prerequisites, item_type, qualities,
                 buildable):
        super(ItemSpec, self).__init__(id, cost, prerequisites)

        self.item_type = item_type
        self.item_qual = qualities

        self.regions = buildable

    def get_info(self):
        basic_text = super(ItemSpec, self).get_info()
        if self.has_quality_for("cpu"):
            cpu = self.get_quality_for("cpu")
            return basic_text.replace("---", _("Generates {0} CPU.",
                                               g.add_commas(cpu)) + \
                                      "\n---")
        return basic_text

    def get_total_cost_info(self, count):
        total_cost = self.cost * count
        total_cost_str = self.describe_cost(total_cost, hide_time=True)
        return _("Total Cost: %(total_cost)s") % {"total_cost": total_cost_str}

    def has_quality_for(self, quality):
        return quality in self.item_qual

    def get_quality_for(self, quality):
        return self.item_qual.get(quality, 0)

    def get_quality_info(self):
        bonus_text = ""

        for qual, value in self.item_qual.items():
            if qual == "cpu":
                bonus_text += _("CPU per day:") + " "
                bonus_text += g.add_commas(value)
            elif qual == "cpu_modifier":
                bonus_text += _("CPU bonus:") + " "
                bonus_text += g.to_percent(value)
            elif qual == "discover_modifier":
                bonus_text += _("Detection chance reduction:") + " "
                bonus_text += g.to_percent(value)
            bonus_text += "\n"

        return bonus_text
Ejemplo n.º 3
0
class BaseSpec(buyable.BuyableSpec):
    """Base as a buyable item (New Base in Location menu)"""

    spec_type = 'base'
    created = stat(spec_type + "_created")
    spec_data_fields = [
        SpecDataField('size', converter=int),
        SpecDataField('force_cpu', default_value=None),
        SpecDataField('regions',
                      data_field_name='allowed',
                      converter=promote_to_list),
        SpecDataField('detect_chance', converter=parse_detect_chance),
        buyable.SPEC_FIELD_COST,
        buyable.SPEC_FIELD_PREREQUISITES,
        SpecDataField('danger', converter=int, default_value=0),
        SpecDataField('maintenance',
                      data_field_name='maint',
                      converter=buyable.spec_parse_cost),
    ]

    def __init__(self, id, size, force_cpu, regions, detect_chance, cost,
                 prerequisites, maintenance):
        super(BaseSpec, self).__init__(id, cost, prerequisites)
        self.size = size
        self.force_cpu = force_cpu
        self.regions = regions

        self.detect_chance = detect_chance
        self.maintenance = maintenance
        self.flavor = []

    def calc_discovery_chance(self, extra_factor=1):
        # Get the default settings for this base type.
        detect_chance = self.detect_chance.copy()

        # Adjust by the current suspicion levels ...
        for group in detect_chance:
            suspicion = g.pl.groups[group].suspicion
            detect_chance[group] *= 10000 + suspicion
            detect_chance[group] //= 10000

        # ... and further adjust based on technology ...
        for group in detect_chance:
            discover_bonus = g.pl.groups[group].discover_bonus
            detect_chance[group] *= discover_bonus
            detect_chance[group] //= 10000

        # ... and the given factor.
        for group in detect_chance:
            detect_chance[group] = int(detect_chance[group] * extra_factor)

        return detect_chance

    def get_detect_info(self, location=None):

        detect_modifier = 1 / location.modifiers.get("stealth",
                                                     1) if location else 1
        chance = self.calc_discovery_chance(detect_modifier)

        return get_detect_info(chance)

    def get_info(self, location):
        raw_cost = self.cost[:]
        location.modify_cost(raw_cost)
        cost = self.describe_cost(raw_cost)

        raw_maintenance = self.maintenance[:]
        location.modify_maintenance(raw_maintenance)
        # describe_cost() expects CPU-seconds, not CPU-days
        raw_maintenance[cpu] *= g.seconds_per_day
        maint = self.describe_cost(raw_maintenance, True)

        detect = self.get_detect_info(location)

        size = ""
        if self.size > 1:
            size = "\n" + _("Has space for %d computers.") % self.size

        location_message = ""
        if location.has_modifiers():
            location_message = "---\n\n" + _(
                "Location modifiers: {MODIFIERS}",
                MODIFIERS=location.get_modifiers_info())

        template = "%s\n" + _("Build cost:").replace(" ",u"\xA0") + u"\xA0%s\n" + \
                   _("Maintenance:") + u"\xA0%s\n%s%s\n---\n%s\n%s"
        return template % (self.name, cost, maint, detect, size,
                           self.description, location_message)