示例#1
0
    def __init__(self, gyr, etype, erating):
        Item.__init__(self)
        # We need engine info for calculations
        self.gtype = gettext(gyr.childNodes)
        self.g_base = int(gyr.attributes["techbase"].value)

        # Check for legal gyro type, save data
        ident = False
        for i in GYRO:
            if (i[0] == self.gtype and i[1] == self.g_base):
                ident = True
                self.gyro_bv = i[2]
                gweightm = i[3]
                self.r_level = i[4]
                self.cost = i[5]
        if not ident:
            error_exit((self.gtype, self.g_base))

        # Calculate weight
        rating = erating
        # Hack: Make sure Primitive Engines get right gyro weight
        if etype == "Primitive Fusion Engine":
            rating *= 1.2
            rating = ceil_5(rating)
        base_weight = ceil(float(rating) / 100.0)
        self.weight = gweightm * base_weight
示例#2
0
    def __init__(self, eng, unit):
        Item.__init__(self)
        self.erating = int(eng.attributes["rating"].value)
        self.e_base = int(eng.attributes["techbase"].value)
        self.etype = gettext(eng.childNodes)
        self.speed = self.erating / unit.weight
        self.unit = unit  # Reference to parent unit
        # A note on primitive engines:
        # It seems like using engine rating directly does give
        # the right speed, even if rules says otherwise
        # This looks like an internal SSW issue, so
        # assume that the weight of these engines are incorrect

        # Check for legal engine type, save data
        ident = False
        for i in ENGINE:
            if (i[0] == self.etype and i[1] == self.e_base):
                ident = True
                self.eng_bv = i[2]
                if self.unit.type == "CV":
                    self.eweight = i[3](ceil_5(self.erating -
                                               self.get_suspension_factor()))
                else:
                    self.eweight = i[3](ceil_5(self.erating))
                self.r_level = i[4]
                self.cost = i[5]
                self.short = i[6]
        if not ident:
            error_exit((self.etype, self.e_base))
示例#3
0
    def get_slots(self):
        """
        Return a list of equipment slots occupied by the cockpit.
        """
        if (self.type == "Standard Cockpit" or
            self.type == "Primitive Cockpit"):
            s_list = [("HD", 0), ("HD", 1), ("HD", 2), ("HD", 4), ("HD", 5)]
            if self.console == "TRUE":
                s_list.append(("HD", 3))
        elif (self.type == "Small Cockpit"):
            s_list = [("HD", 0), ("HD", 1), ("HD", 2), ("HD", 3)]
            if self.console == "TRUE":
                s_list.append(("HD", 4))
        elif (self.type == "Torso-Mounted Cockpit"):
            c_slot = self.unit.gyro.get_engine_continue()
            s_slot = self.unit.engine.get_side_continue()
            if self.unit.engine.etype == "Compact Fusion Engine":
                s_list = [("HD", 0), ("HD", 1), ("CT", c_slot),
                          ("CT", c_slot + 1), ("LT", s_slot), ("RT", s_slot)]
            else:
                s_list = [("HD", 0), ("HD", 1), ("CT", c_slot + 3),
                          ("CT", c_slot + 4), ("LT", s_slot), ("RT", s_slot)]
        else:
            error_exit((self.type))

        return s_list
示例#4
0
    def __init__(self, cpt, unit):
        Item.__init__(self)
        cnode = cpt.getElementsByTagName("type")[0]
        self.type = gettext(cnode.childNodes)
        if self.type != "Torso-Mounted Cockpit":
            self.console = cnode.attributes["commandconsole"].value
        else:
            self.console = "FALSE"
        self.c_weight = 0
        self.unit = unit  # Reference to parent unit

        # Check for legal cockpit type, save data
        ident = False
        for i in COCKPIT:
            if (i[0] == self.type):
                ident = True
                self.wgt = i[1]
                self.r_level = i[2]
                self.cost = i[3]
        if not ident:
            error_exit((self.type))

        # Hack: Add console weight
        if self.console == "TRUE":
            self.c_weight = 3
示例#5
0
    def __init__(self, arm, weight):
        Item.__init__(self)
        self.tech_base = int(arm.attributes["techbase"].value)
        self.atype = get_child_data(arm, "type")
        self.front = int(get_child_data(arm, "front"))
        self.left = int(get_child_data(arm, "left"))
        self.right = int(get_child_data(arm, "right"))
        self.rear = int(get_child_data(arm, "rear"))
        self.p_turret = int(get_child_data(arm, "primaryturret"))
        self.s_turret = int(get_child_data(arm, "secondaryturret"))
        self.rotor = int(get_child_data(arm, "rotor"))

        # Check for legal armor type, save data
        ident = False
        for i in ARMOR:
            if (i[0] == self.atype and i[1] == self.tech_base):
                ident = True
                self.armor_bv = i[2]
                self.armor_multipler = i[3]
                self.r_level = i[4]
                self.cost = i[5]
                self.short = i[6]
        if not ident:
            error_exit((self.atype, self.tech_base))

        # Last sum up total
        armortotal = (self.front + self.left + self.right + self.rear +
                      self.p_turret + self.s_turret + self.rotor)
        maxtotal = floor(3.5 * weight + 40)

        self.total = ArmorLoc("Total", armortotal, (maxtotal - 9) / 2 + 3,
                              maxtotal)
示例#6
0
    def get_weight(self):
        """
        Get weight of AES
        """
        if self.type == "None":
            return 0.0

        if self.motive == "Quad":
            return ceil_05(self.weight / 50.0)
        elif self.motive == "Biped":
            return ceil_05(self.weight / 35.0)
        else:
            error_exit(self.motive)
示例#7
0
 def get_engine_continue(self):
     """
     Get CT slot where the engine continues
     """
     if (self.gtype == "Standard Gyro" or
         self.gtype == "Heavy-Duty Gyro"):
         return 7
     elif (self.gtype == "Compact Gyro"):
         return 5
     elif (self.gtype == "Extra-Light Gyro"):
         return 9
     else:
         error_exit((self.gtype, self.g_base))
示例#8
0
 def get_slots(self):
     """
     Return a list of equipment slots occupied by the gyro.
     """
     if (self.gtype == "Standard Gyro" or
         self.gtype == "Heavy-Duty Gyro"):
         return [("CT", 3), ("CT", 4), ("CT", 5), ("CT", 6)]
     elif (self.gtype == "Compact Gyro"):
         return [("CT", 3), ("CT", 4)]
     elif (self.gtype == "Extra-Light Gyro"):
         return [("CT", 3), ("CT", 4), ("CT", 5), ("CT", 6), ("CT", 7),
                 ("CT", 8)]
     else:
         error_exit((self.gtype, self.g_base))
示例#9
0
    def __init__(self, stru, weight, motive):
        Item.__init__(self)
        self.tech_base = int(stru.attributes["techbase"].value)
        self.type = get_child_data(stru, "type")
        wgt = weight

        # Check for legal structure type, save data
        ident = False
        for i in STRUCTURE:
            if (i[0] == self.type and i[1] == self.tech_base):
                ident = True
                self.is_bv = i[2]
                wgtf = i[3]
                self.r_level = i[4]
                costf = i[5]
                self.short = i[6]
        if not ident:
            error_exit((self.type, self.tech_base))

        # Calculate IS weight
        wgt *= wgtf
        # hack to get half-ton rounding up
        wgt = ceil_05(wgt)
        self.wgt = wgt

        # Calculate IS points
        self.points = 0

        # Head always have 3 IS
        self.points += 3

        # Otherwise get from table
        self.points += CT_IS[weight]
        self.points += ST_IS[weight] * 2
        self.points += LEG_IS[weight] * 2

        # The arms/front legs need to check if mech is Biped or Quad
        if motive == "Quad":
            self.points += LEG_IS[weight] * 2
        elif motive == "Biped":
            self.points += ARM_IS[weight] * 2
        else:
            error_exit(motive)

        # Calculate cost
        self.cost = weight * costf
示例#10
0
    def __init__(self, enh, weight, eng_rating):
        Item.__init__(self)
        # Save engine weight
        self.eng_rating = eng_rating
        if enh is None:
            self.etb = 2
            self.enhancement = "---"
        else:
            enode = enh.getElementsByTagName("type")[0]
            self.enhancement = gettext(enode.childNodes)
            self.etb = int(enh.attributes["techbase"].value)

        # Check for legal enhancement type, save data
        ident = False
        for i in ENHANCEMENT:
            if (i[0] == self.enhancement and i[1] == self.etb):
                ident = True
                self.enhweight = i[2](weight)
        if not ident:
            error_exit((self.enhancement, self.etb))
示例#11
0
    def get_weight(self):
        """
        Get weight of jumpjets

        :return: the total weight of jump-jets
        :rtype: float
        """
        if self.jump == 0:
            return 0
        if self.weight < 60:
            base = 0.5
        elif self.weight < 90:
            base = 1.0
        else:
            base = 2.0
        if self.jjtype == "Standard Jump Jet" or self.jjtype == "Mech UMU":
            base = base * 1.0
        elif self.jjtype == "Improved Jump Jet":
            base = base * 2.0
        else:
            error_exit(self.jjtype)
        return base * self.jump
示例#12
0
    def __init__(self, heat, load):
        Item.__init__(self)
        self.load = load  # Reference to parent
        # Handle default
        if heat is None:
            self.number = 0
            self.tech_b = 2
            self.type = "Single Heat Sink"
        else:
            self.number = int(heat.attributes["number"].value)
            self.tech_b = int(heat.attributes["techbase"].value)
            self.type = get_child_data(heat, "type")

        # Check for heatsink type, save data
        ident = False
        for i in HEATSINK:
            if (i[0] == self.type and i[1] == self.tech_b):
                ident = True
                self.cap = i[2]
                self.r_level = i[3]
                self.cost = i[4]
        if not ident:
            error_exit((self.type, self.tech_b))
示例#13
0
    def __init__(self, jets, weight):
        Item.__init__(self)
        self.weight = weight  # Mech weight, not JJ weight
        # Handle default
        if jets is None:
            self.jump = 0
            self.jjtype = ""
            self.r_level = 0
        else:
            self.jump = int(jets.attributes["number"].value)
            jnode = jets.getElementsByTagName("type")[0]
            self.jjtype = gettext(jnode.childNodes)

        # Check for legal jump-jet type, if jump-jets are mounted, save data
        if self.jump > 0:
            ident = False
            for i in JUMP_JET:
                if i[0] == self.jjtype:
                    ident = True
                    self.heat = i[1]
                    self.r_level = i[2]
                    self.cost = i[3]
            if not ident:
                error_exit(self.jjtype)
示例#14
0
    def __init__(self, stru, weight, mot_type, turrets):
        Item.__init__(self)
        self.tech_base = int(stru.attributes["techbase"].value)
        self.type = get_child_data(stru, "type")
        wgt = weight

        # Check for legal structure type, save data
        ident = False
        for i in STRUCTURE:
            if (i[0] == self.type and i[1] == self.tech_base):
                ident = True
                self.is_bv = i[2]
                wgtf = i[3]
                self.r_level = i[4]
                self.short = i[6]
        if not ident:
            error_exit((self.type, self.tech_base))

        # Calculate IS weight
        wgt *= wgtf
        # hack to get half-ton rounding up
        wgt = ceil_05(wgt)
        self.wgt = wgt

        # Calculate IS points, start with the four basic sides
        base = ceil(weight * 0.1)
        self.points = base * 4
        # Add rotor, max 3 points
        if mot_type == "VTOL":
            self.points += min(base, 3)
        if turrets == "Single Turret":
            self.points += base
        # TODO: Dual turret

        # Calculate cost
        self.cost = self.wgt * 10000
示例#15
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")
示例#16
0
    def __init__(self, arm, weight, motive):
        Item.__init__(self)
        self.tech_base = int(arm.attributes["techbase"].value)
        self.atype = get_child_data(arm, "type")
        head = int(get_child_data(arm, "hd"))
        c_torso = int(get_child_data(arm, "ct"))
        ctr = int(get_child_data(arm, "ctr"))
        l_torso = int(get_child_data(arm, "lt"))
        ltr = int(get_child_data(arm, "ltr"))
        r_torso = int(get_child_data(arm, "rt"))
        rtr = int(get_child_data(arm, "rtr"))
        l_arm = int(get_child_data(arm, "la"))
        r_arm = int(get_child_data(arm, "ra"))
        l_leg = int(get_child_data(arm, "ll"))
        r_leg = int(get_child_data(arm, "rl"))

        # Check for legal armor type, save data
        ident = False
        for i in ARMOR:
            if (i[0] == self.atype and i[1] == self.tech_base):
                ident = True
                self.armor_bv = i[2]
                self.armor_multipler = i[3]
                self.r_level = i[4]
                self.cost = i[5]
                self.short = i[6]
        if not ident:
            error_exit((self.atype, self.tech_base))

        # Head always have max 9 armor
        self.head = ArmorLoc("Head", head, 3, 9)

        # Otherwise 2 times Internal Structure
        self.c_torso = TorsoArmor("Center Torso", c_torso, ctr, CT_IS[weight])
        self.l_torso = TorsoArmor("Left Torso", l_torso, ltr, ST_IS[weight])
        self.r_torso = TorsoArmor("Right Torso", r_torso, rtr, ST_IS[weight])

        # The arms/front legs need to check if mech is Biped or Quad
        if motive == "Quad":
            self.l_arm = ArmorLoc("Front Left Leg", l_arm, LEG_IS[weight],
                                  LEG_IS[weight] * 2)
            self.r_arm = ArmorLoc("Front Right Leg", r_arm, LEG_IS[weight],
                                  LEG_IS[weight] * 2)
            self.l_leg = ArmorLoc("Rear Left Leg", l_leg, LEG_IS[weight],
                                  LEG_IS[weight] * 2)
            self.r_leg = ArmorLoc("Rear Right Leg", r_leg, LEG_IS[weight],
                                  LEG_IS[weight] * 2)
        elif motive == "Biped":
            self.l_arm = ArmorLoc("Left Arm", l_arm, ARM_IS[weight],
                                  ARM_IS[weight] * 2)
            self.r_arm = ArmorLoc("Right Arm", r_arm, ARM_IS[weight],
                                  ARM_IS[weight] * 2)
            self.l_leg = ArmorLoc("Left Leg", l_leg, LEG_IS[weight],
                                  LEG_IS[weight] * 2)
            self.r_leg = ArmorLoc("Right Leg", r_leg, LEG_IS[weight],
                                  LEG_IS[weight] * 2)
        else:
            error_exit(motive)

        # Last sum up total
        armortotal = (self.head.arm + self.c_torso.get_total() +
                      self.l_torso.get_total() +
                      self.r_torso.get_total() + self.l_arm.arm +
                      self.r_arm.arm +
                      self.l_leg.arm + self.r_leg.arm)
        maxtotal = (self.head.max + self.c_torso.get_max() +
                    self.l_torso.get_max() +
                    self.r_torso.get_max() + self.l_arm.max + self.r_arm.max +
                    self.l_leg.max + self.r_leg.max)
        self.total = ArmorLoc("Total", armortotal, (maxtotal - 9) / 2 + 3,
                              maxtotal)