Пример #1
0
    def __init__(self, mech, art4, art5, apollo, equip, clan_case):
        self.equip = equip
        self.c_case = clan_case  # Clan CASE

        # We need to create local lists for avoid trouble with Omni-mechs
        self.weaponlist = Weaponlist(art4, art5, apollo)
        self.equiplist = Equiplist()
        self.physicallist = Physicallist(mech.weight)
        self.ammolist = Ammolist()
        self.supercharger = Supercharger(mech.engine.erating,
                                         mech.engine.get_weight())
        # Keep track of tarcomp
        self.tarcomp = 0
        # Gear weight
        self.a_weight = 0.0
        self.e_weight = 0.0
        self.tc_weight = 0.0
        self.mod_weight = 0.0
        self.tur_weight = 0.0
        # Track explosive ammo by locations
        self.exp_ammo = {}
        # Save reference to explosive weapon count
        self.exp_weapon = self.weaponlist.exp_weapon
        self.case = {}
        # Track coolant pods
        self.coolant = 0
        # Track modular armor
        self.mod_armor = {}
        self.has_mod_armor = False
        # Track CASE rules level
        self.case_rule = 0

        ### Count gear ###
        for name in self.equip:
            ### Weapons ###
            # Go through weapon list
            ident = False
            # A weapon
            if (name.typ == 'ballistic' or name.typ == 'energy' or
                name.typ == 'missile' or name.typ == 'artillery' or
                name.typ == 'mgarray'):
                found = self.weaponlist.add(name.name, name.loc, name.rear,
                                            name.turret)
                if found:
                    ident = True

            # Handle non-weapon equipment
            elif (name.typ == 'equipment'):
                for equip in self.equiplist.list:
                    if (name.name == equip.name):
                        equip.addone(name.wgt, name.turret)
                        self.e_weight += equip.get_weight()
                        ident = True
                        # Hack, coolant pods
                        if name.name == "Coolant Pod":
                            self.coolant += 1
                        # Add explosive equipment to location
                        if equip.expl > 0:
                            self.exp_weapon.add_weapon(name.loc, equip.expl)
            # Hack, CASE
            elif (name.typ == 'CASE' or name.typ == 'CASEII'):
                for cas in CASE.keys():
                    if (name.name == cas):
                        # Hack SSW store fixed CASE on omnis twice
                        if not name.loc in self.case:
                            self.e_weight += CASE[cas][1]
                        ident = True
                        # Save CASE status
                        self.case[name.loc] = name.typ
                        # Hack CASE rules level
                        if self.case_rule < CASE[cas][0]:
                            self.case_rule = CASE[cas][0]

            # Hack, handle targeting computer
            elif (name.name == "(IS) Targeting Computer" and
                name.typ == 'TargetingComputer'):
                self.tarcomp = 1
                ident = True
            elif (name.name == "(CL) Targeting Computer" and
                name.typ == 'TargetingComputer'):
                self.tarcomp = 2
                ident = True

            # Hack, supercharger
            elif (name.name == "Supercharger" and name.typ == "Supercharger"):
                self.supercharger.add()
                ident = True

            # A possible physical weapon
            elif (name.typ == 'physical'):
                found = self.physicallist.add(name.name, name.loc, name.turret)
                if found:
                    ident = True

            # Modular armor
            elif (name.typ == 'miscellaneous'):
                if name.name == "Modular Armor":
                    ident = True
                    mod = self.mod_armor.get(name.loc, 0)
                    mod += 10
                    self.mod_armor[name.loc] = mod
                    self.mod_weight = 1.0
                    self.has_mod_armor = True
                # Ignore Hitches for now
                if name.name == "Hitch":
                    ident = True

            # Ammunition
            elif (name.typ == 'ammunition'):
                for ammo in self.ammolist.list:
                    if (name.name == ammo.name):
                        ammo.addone()
                        self.a_weight += ammo.get_weight()
                        ident = True
                        # Add explosive ammo to location
                        if ammo.explosive == "X":
                            expl = self.exp_ammo.get(name.loc, 0)
                            expl += 1
                            self.exp_ammo[name.loc] = expl

            # Not found
            if not ident:
                print "Unidentified:", name.name, ":", name.typ
                error_exit("gear")

        # Calculate tarcomp weight
        if self.tarcomp == 1:  # IS
            self.tc_weight = ceil(self.weaponlist.tcw_weight / 4.0)
        if self.tarcomp == 2:  # Clan
            self.tc_weight = ceil(self.weaponlist.tcw_weight / 5.0)

        # Calculate turret weight
        self.tur_weight = ceil_05((self.weaponlist.tur_weight +
                                   self.equiplist.get_turret_weight() +
                                   self.physicallist.get_turret_weight()) /
                                  10.0)

        # Add ammo to weapon
        for ammo in self.ammolist.list:
            if ammo.count > 0:
                ident = False
                for weap in self.weaponlist.list.itervalues():
                    for i in ammo.wname:
                        if weap.name == i:
                            weap.add_ammo(ammo.count * ammo.weight,
                                          ammo.count * ammo.amount)
                            ident = True
                # We need to do defensive equipment also due to AMS
                for equip in self.equiplist.list:
                    for i in ammo.wname:
                        if equip.name == i:
                            equip.add_ammo(ammo.count * ammo.weight,
                                           ammo.count * ammo.amount)
                            ident = True
                if (not ident):
                    print "ERROR: Unknown weapon:", ammo.wname
                    error_exit("weapon")
Пример #2
0
class Gear:
    """
    Store Gear

    Take in lists of front and rear facing gears
    """
    def __init__(self, mech, art4, art5, apollo, equip, clan_case):
        self.equip = equip
        self.c_case = clan_case  # Clan CASE

        # We need to create local lists for avoid trouble with Omni-mechs
        self.weaponlist = Weaponlist(art4, art5, apollo)
        self.equiplist = Equiplist()
        self.physicallist = Physicallist(mech.weight)
        self.ammolist = Ammolist()
        self.supercharger = Supercharger(mech.engine.erating,
                                         mech.engine.get_weight())
        # Keep track of tarcomp
        self.tarcomp = 0
        # Gear weight
        self.a_weight = 0.0
        self.e_weight = 0.0
        self.tc_weight = 0.0
        self.mod_weight = 0.0
        self.tur_weight = 0.0
        # Track explosive ammo by locations
        self.exp_ammo = {}
        # Save reference to explosive weapon count
        self.exp_weapon = self.weaponlist.exp_weapon
        self.case = {}
        # Track coolant pods
        self.coolant = 0
        # Track modular armor
        self.mod_armor = {}
        self.has_mod_armor = False
        # Track CASE rules level
        self.case_rule = 0

        ### Count gear ###
        for name in self.equip:
            ### Weapons ###
            # Go through weapon list
            ident = False
            # A weapon
            if (name.typ == 'ballistic' or name.typ == 'energy' or
                name.typ == 'missile' or name.typ == 'artillery' or
                name.typ == 'mgarray'):
                found = self.weaponlist.add(name.name, name.loc, name.rear,
                                            name.turret)
                if found:
                    ident = True

            # Handle non-weapon equipment
            elif (name.typ == 'equipment'):
                for equip in self.equiplist.list:
                    if (name.name == equip.name):
                        equip.addone(name.wgt, name.turret)
                        self.e_weight += equip.get_weight()
                        ident = True
                        # Hack, coolant pods
                        if name.name == "Coolant Pod":
                            self.coolant += 1
                        # Add explosive equipment to location
                        if equip.expl > 0:
                            self.exp_weapon.add_weapon(name.loc, equip.expl)
            # Hack, CASE
            elif (name.typ == 'CASE' or name.typ == 'CASEII'):
                for cas in CASE.keys():
                    if (name.name == cas):
                        # Hack SSW store fixed CASE on omnis twice
                        if not name.loc in self.case:
                            self.e_weight += CASE[cas][1]
                        ident = True
                        # Save CASE status
                        self.case[name.loc] = name.typ
                        # Hack CASE rules level
                        if self.case_rule < CASE[cas][0]:
                            self.case_rule = CASE[cas][0]

            # Hack, handle targeting computer
            elif (name.name == "(IS) Targeting Computer" and
                name.typ == 'TargetingComputer'):
                self.tarcomp = 1
                ident = True
            elif (name.name == "(CL) Targeting Computer" and
                name.typ == 'TargetingComputer'):
                self.tarcomp = 2
                ident = True

            # Hack, supercharger
            elif (name.name == "Supercharger" and name.typ == "Supercharger"):
                self.supercharger.add()
                ident = True

            # A possible physical weapon
            elif (name.typ == 'physical'):
                found = self.physicallist.add(name.name, name.loc, name.turret)
                if found:
                    ident = True

            # Modular armor
            elif (name.typ == 'miscellaneous'):
                if name.name == "Modular Armor":
                    ident = True
                    mod = self.mod_armor.get(name.loc, 0)
                    mod += 10
                    self.mod_armor[name.loc] = mod
                    self.mod_weight = 1.0
                    self.has_mod_armor = True
                # Ignore Hitches for now
                if name.name == "Hitch":
                    ident = True

            # Ammunition
            elif (name.typ == 'ammunition'):
                for ammo in self.ammolist.list:
                    if (name.name == ammo.name):
                        ammo.addone()
                        self.a_weight += ammo.get_weight()
                        ident = True
                        # Add explosive ammo to location
                        if ammo.explosive == "X":
                            expl = self.exp_ammo.get(name.loc, 0)
                            expl += 1
                            self.exp_ammo[name.loc] = expl

            # Not found
            if not ident:
                print "Unidentified:", name.name, ":", name.typ
                error_exit("gear")

        # Calculate tarcomp weight
        if self.tarcomp == 1:  # IS
            self.tc_weight = ceil(self.weaponlist.tcw_weight / 4.0)
        if self.tarcomp == 2:  # Clan
            self.tc_weight = ceil(self.weaponlist.tcw_weight / 5.0)

        # Calculate turret weight
        self.tur_weight = ceil_05((self.weaponlist.tur_weight +
                                   self.equiplist.get_turret_weight() +
                                   self.physicallist.get_turret_weight()) /
                                  10.0)

        # Add ammo to weapon
        for ammo in self.ammolist.list:
            if ammo.count > 0:
                ident = False
                for weap in self.weaponlist.list.itervalues():
                    for i in ammo.wname:
                        if weap.name == i:
                            weap.add_ammo(ammo.count * ammo.weight,
                                          ammo.count * ammo.amount)
                            ident = True
                # We need to do defensive equipment also due to AMS
                for equip in self.equiplist.list:
                    for i in ammo.wname:
                        if equip.name == i:
                            equip.add_ammo(ammo.count * ammo.weight,
                                           ammo.count * ammo.amount)
                            ident = True
                if (not ident):
                    print "ERROR: Unknown weapon:", ammo.wname
                    error_exit("weapon")

    def get_rules_level(self):
        """
        Get rules level of all gear

        No checking for ammo, since we can assume that there is ammo
        of the same rules level as the corresponding weapon
        and that more advanced ammo can be switched out
        """
        r_level = 0
        r_level = max(r_level, self.weaponlist.get_rules_level())
        r_level = max(r_level, self.physicallist.get_rules_level())
        r_level = max(r_level, self.equiplist.get_rules_level())
        r_level = max(r_level, self.supercharger.get_rules_level())
        # Hack: Targeting computer
        if self.tarcomp > 0 and r_level < 1:
            r_level = 1
        # Hack: CASE
        if self.case_rule > r_level:
            r_level = self.case_rule

        return r_level

    def get_cost(self):
        """
        Get the cost of all equipment

        Ammo cost will not be handled by this fuction, due to the
        difference between dry and loaded costs.
        """
        cost = 0
        # weapons
        cost += self.weaponlist.get_cost()
        # physical
        cost += self.physicallist.get_cost()
        # equipment
        cost += self.equiplist.get_cost()
        # Supercharger
        cost += self.supercharger.get_cost()
        # Hack: Targeting computer
        if self.tarcomp > 0:
            cost += 10000 * self.tc_weight

        # Hack: CASE
        for cas in self.case.itervalues():
            if cas == "CASE":
                cost += 50000
            elif cas == "CASEII":
                cost += 175000
        # Hack: Clan CASE
        if self.c_case == "TRUE":
            case_list = {}
            for i in self.exp_ammo.keys():
                case_list[i] = 1
            for i in self.exp_weapon.get_keys():
                case_list[i] = 1
            cost += len(case_list) * 50000

        return cost

    def get_w_weight(self):
        """
        Get weapons weight
        """
        return self.weaponlist.w_weight

    def get_a_weight(self):
        """
        Get ammo weight
        """
        return self.a_weight

    def get_e_weight(self):
        """
        Get equipment, tarcomp, supercharger, modular armor & CASE weight
        """
        wgt = self.e_weight + self.tc_weight + self.supercharger.get_weight()
        wgt += self.mod_weight
        return wgt

    def get_p_weight(self):
        """
        Get physical weapon weight
        """
        return self.physicallist.p_weight

    def get_weight(self):
        """
        Get weight of all gear
        """
        wgt = (self.get_w_weight() + self.get_a_weight() +
               self.get_e_weight() + self.get_p_weight())
        return wgt

    def get_speed_adj(self):
        """
        Get speed reduction from certain items, like shields and modular armor.
        """
        red = 0
        red += self.physicallist.get_speed_adj()
        if self.has_mod_armor:
            red -= 1
        return red

    def get_def_bv(self):
        """
        Get defensive gear BV
        """
        batt_val = 0.0
        # From gear
        batt_val += self.equiplist.get_def_bv()
        # Defensive physical weapons
        batt_val += self.physicallist.get_def_bv()
        return batt_val

    def get_ammo_exp_bv(self, engine):
        """
        Return how much BV is reduced by explosive ammo
        """
        neg_bv = 0.0
        # Check each ammo location
        for i in self.exp_ammo.keys():
            cas = self.case.get(i, "")
            # Head and center torso always
            if (i == "HD" or i == "CT"):
                neg_bv -= 15.0 * self.exp_ammo[i]
            # So are legs
            elif (i == "LL" or i == "RL" or i == "RLL" or i == "RRL"):
                neg_bv -= 15.0 * self.exp_ammo[i]
            # Side torsos depends on several factors
            elif (i == "LT" or i == "RT"):
                # Inner Sphere XL Engines means that side torsos are vulnerable
                if engine.vulnerable():
                    if (cas != "CASEII"):
                        neg_bv -= 15.0 * self.exp_ammo[i]
                # Otherwise we check for CASE
                elif (self.c_case == "FALSE"):
                    # No CASE
                    if (cas != "CASE" and cas != "CASEII"):
                        neg_bv -= 15.0 * self.exp_ammo[i]
            # Arms are complicated
            elif (i == "LA" or i == "FLL"):
                # we can use torso CASE
                cas2 = self.case.get("LT", "")
                # Inner Sphere XL Engines means that side torsos are vulnerable
                if engine.vulnerable():
                    if (cas != "CASEII" and cas2 != "CASEII"
                        and self.c_case == "FALSE"):
                        neg_bv -= 15.0 * self.exp_ammo[i]
                # Otherwise we check for CASE
                elif (self.c_case == "FALSE"):
                    # No CASE
                    if ((cas != "CASE" and cas != "CASEII") and
                        (cas2 != "CASE" and cas2 != "CASEII")):
                        neg_bv -= 15.0 * self.exp_ammo[i]
            elif (i == "RA" or i == "FRL"):
                # we can use torso CASE
                cas2 = self.case.get("RT", "")
                # Inner Sphere XL Engines means that side torsos are vulnerable
                if engine.vulnerable():
                    if (cas != "CASEII" and cas2 != "CASEII"
                        and self.c_case == "FALSE"):
                        neg_bv -= 15.0 * self.exp_ammo[i]
                # Otherwise we check for CASE
                elif (self.c_case == "FALSE"):
                    # No CASE
                    if ((cas != "CASE" and cas != "CASEII") and
                        (cas2 != "CASE" and cas2 != "CASEII")):
                        neg_bv -= 15.0 * self.exp_ammo[i]

        return neg_bv

    def get_weapon_exp_bv(self, engine):
        """
        Return how much BV is reduced by explosive weapons
        """
        neg_bv = 0.0
        # Check each ammo location
        for i in self.exp_weapon.get_keys():
            cas = self.case.get(i, "")
            # Head and center torso always
            if (i == "HD" or i == "CT"):
                neg_bv -= self.exp_weapon.get_slots(i)
            # So are legs
            elif (i == "LL" or i == "RL" or i == "RLL" or i == "RRL"):
                neg_bv -= self.exp_weapon.get_slots(i)
            # Side torsos depends on several factors
            elif (i == "LT" or i == "RT"):
                # Inner Sphere XL Engines means that side torsos are vulnerable
                if engine.vulnerable():
                    if (cas != "CASEII"):
                        neg_bv -= self.exp_weapon.get_slots(i)
                # Otherwise we check for CASE
                elif (self.c_case == "FALSE"):
                    # No CASE
                    if (cas != "CASE" and cas != "CASEII"):
                        neg_bv -= self.exp_weapon.get_slots(i)
            # Arms are complicated
            elif (i == "LA" or i == "FLL"):
                # we can use torso CASE
                cas2 = self.case.get("LT", "")
                # Inner Sphere XL Engines means that side torsos are vulnerable
                if engine.vulnerable():
                    if (cas != "CASEII" and cas2 != "CASEII"
                        and self.c_case == "FALSE"):
                        neg_bv -= self.exp_weapon.get_slots(i)
                # Otherwise we check for CASE
                elif (self.c_case == "FALSE"):
                    # No CASE
                    if ((cas != "CASE" and cas != "CASEII") and
                        (cas2 != "CASE" and cas2 != "CASEII")):
                        neg_bv -= self.exp_weapon.get_slots(i)
            elif (i == "RA" or i == "FRL"):
                # we can use torso CASE
                cas2 = self.case.get("RT", "")
                # Inner Sphere XL Engines means that side torsos are vulnerable
                if engine.vulnerable():
                    if (cas != "CASEII" and cas2 != "CASEII"
                        and self.c_case == "FALSE"):
                        neg_bv -= self.exp_weapon.get_slots(i)
                # Otherwise we check for CASE
                elif (self.c_case == "FALSE"):
                    # No CASE
                    if ((cas != "CASE" and cas != "CASEII") and
                        (cas2 != "CASE" and cas2 != "CASEII")):
                        neg_bv -= self.exp_weapon.get_slots(i)
        return neg_bv

    def check_weapon_bv_flip(self):
        """
        Check if front and rear weapons needs to be flipped for BV calculations
        """
        bv_front = 0.0
        bv_rear = 0.0
        # Weapons
        for weap in self.weaponlist.list.itervalues():
            fr_count = (weap.count - weap.count_la - weap.count_ra -
                        weap.count_tur)
            if (fr_count) > 0:
                bv_front += weap.get_bv(self.tarcomp) * (fr_count)

            if weap.countrear > 0:
                bv_rear += weap.get_bv(self.tarcomp) * weap.countrear

        if (bv_rear > bv_front):
            return True
        else:
            return False