Example #1
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)
Example #2
0
    def __init__(self, load, base, mech):
        self.name = load.attributes["name"].value

        # Get production era
        prod_era = int(get_child_data(load, "loadout_productionera"))

        # Get year
        self.year = int(get_child_data(load, "loadout_year"))

        # Get BV.
        batt_val = int(get_child_data(load, "battle_value"))

        # Get cost
        cost = float(get_child_data(load, "cost"))

        # Sanity check for year
        year_era_test(self.year, prod_era, mech.name + " " + mech.model + self.name)

        # Get equipment
        self.equip = list(base.equip)

        for node in load.getElementsByTagName("equipment"):
            self.equip.append(Equip(node))

        Load.__init__(self, load, mech, batt_val, prod_era, self.equip, cost)
        # These needs to be set after call to Load

        # Use base config heatsinks if not overriden
        self.heatsinks = base.heatsinks
        # Use base config jump-jets if not overriden
        self.jjets = base.jjets
        # Use base config partial wing (no over-ride cannot be pod-mounted)
        self.partw = base.partw

        # Get jumpjets
        for jets in load.getElementsByTagName("jumpjets"):
            self.jjets = JumpJets(jets, self.weight)

        # Get heat sinks
        for heat in load.getElementsByTagName("heatsinks"):
            self.heatsinks = Heatsinks(heat, self)
Example #3
0
    def __init__(self, node):
        self.name = get_child_data(node, "name")
        self.typ = get_child_data(node, "type")
        self.rear = False
        self.turret = False

        # Extract tonnage for variable weight gear
        tons = node.getElementsByTagName("tons")
        if (tons):
            self.wgt = float(gettext(tons[0].childNodes))
        # Handle no info, we use 0.0 to indicate we get the weight from tables
        else:
            self.wgt = 0.0

        # Handle location info
        lnd = node.getElementsByTagName("location")
        # Normal case, no split
        if (lnd):
            lnode = lnd[0]
            self.loc = gettext(lnode.childNodes)
            if self.loc == "Turret":
                self.turret = True
        # Split location
        else:
            self.loc = []
        lnd = node.getElementsByTagName("splitlocation")
        for lnode in lnd:
            lnr = int(lnode.attributes["number"].value)
            loc_temp = gettext(lnode.childNodes)
            self.loc.append((loc_temp, lnr))
        # Check for rear-mounted stuff
        if self.name[0:4] == "(R) ":
            self.rear = True
            self.name = self.name[4:]
        # Also check if turret-mounted
        elif self.name[0:4] == "(T) ":
            self.turret = True
            self.name = self.name[4:]
Example #4
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
Example #5
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))
Example #6
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
Example #7
0
    def __init__(self, xmldoc):
        Unit.__init__(self)

        # This is a combat vehicle
        self.type = "CV"

        # Get top-level structure data
        for cveh in xmldoc.getElementsByTagName('combatvehicle'):
            self.model = cveh.attributes["model"].value
            self.name = cveh.attributes["name"].value
            self.motive = cveh.attributes["motive"].value
            self.omni = cveh.attributes["omni"].value
            self.weight = int(cveh.attributes["tons"].value)

            # Get BV. Should give prime variant BV for Omni-vehicles
            # get first instance only to avoid problems with Omni-vehicles
            self.batt_val = int(get_child_data(cveh, 'battle_value'))

            # Motive
            for mot in cveh.getElementsByTagName('motive'):
                self.mot_type = mot.attributes["type"].value
                self.cruise = int(mot.attributes["cruise"].value)
                self.turret = mot.attributes["turret"].value

            # Get Cost.
            cost = float(get_child_data(cveh, 'cost'))

            # Get production era
            self.prod_era = int(get_child_data(cveh, 'productionera'))

            # Get techbase (IS, Clan)
            # get first instance only to avoid problems with Omni-vehicles
            self.techbase = get_child_data(cveh, 'techbase')

            # Get year
            self.year = int(get_child_data(cveh, 'year'))

            # Sanity check for year
            year_era_test(self.year, self.prod_era,
                          self.name + " " + self.model)

            if (self.year < 2470):
                print self.name, self.model
                print "Combat Vehicles not available before 2470!"
                sys.exit(1)

            if (self.year < 2854 and self.omni == "TRUE"):
                print self.name, self.model
                print "OmniVehicles not available before 2854!"
                sys.exit(1)

            ### Components starts here ###

            self.structure = VehicleStructure(get_child(cveh, 'structure'),
                                              self.weight,
                                              self.mot_type, self.turret)

            self.engine = Engine(get_child(cveh, 'engine'), self)

            self.lift = LiftEquipment(self.weight, self.mot_type)

            if self.engine.etype == "No Engine":
                self.control = ControlSystems(0.0)
            else:
                self.control = ControlSystems(self.weight)

            self.armor = VehicleArmor(get_child(cveh, 'armor'),
                                      self.weight)

            ### Loadout stuff starts here ###

            # Get baseloadout
            blo = cveh.getElementsByTagName('baseloadout')[0]

            # Construct current loadout, empty name for base loadout
            self.load = Baseloadout(blo, self, self.batt_val,
                                    self.prod_era, cost)

            # Get omni loadouts
            self.loads = []
            for load in cveh.getElementsByTagName('loadout'):

                # Construct current loadout
                current = Loadout(load, self.load, self)

                self.loads.append(current)
Example #8
0
    def __init__(self, load, mech, batt_val, prod_era, equip, cost):
        self.weight = mech.weight  # Save weight just in case
        self.artemis4 = load.attributes["fcsa4"].value
        self.artemis5 = load.attributes["fcsa5"].value
        self.apollo = load.attributes["fcsapollo"].value
        self.cost = cost
        self.unit = mech  # Reference to parent

        # Create a container for special abilities
        # ES, SEAL, SOA, SRCH is always available for mechs
        # Combat Vehicles gets SRCH
        if mech.type == "BM":
            self.specials = {"ES": 1, "SEAL": 1, "SOA": 1, "SRCH": 1}
        elif mech.type == "CV":
            self.specials = {"SRCH": 1}

        # Get source
        self.source = get_child_data(load, "source")

        # Get Clan CASE
        # Note that there is currently a bug in combat vehicles regarding
        # Clan CASE.
        if mech.type == "BM":
            clanc = get_child_data(load, "clancase")
        else:
            clanc = "FALSE"

        # Get actuator status
        for act in load.getElementsByTagName("actuators"):
            self.left_hand = act.attributes["lh"].value
            self.left_arm = act.attributes["lla"].value
            self.right_hand = act.attributes["rh"].value
            self.right_arm = act.attributes["rla"].value

        self.batt_val = batt_val
        # Set to zero things that might not get defined otherwise
        self.heatsinks = Heatsinks(None, self)
        self.jjets = JumpJets(None, mech.weight)
        self.partw = PartialWing(mech.weight, False, 2)

        # Assume not mixed tech
        self.mixed = False
        for rll in load.getElementsByTagName("techbase"):
            if gettext(rll.childNodes) == "Mixed":
                self.mixed = True

        # Get Actuator Enhancement System
        self.aes_ra = AES(mech.weight, mech.motive, "None")
        self.aes_la = AES(mech.weight, mech.motive, "None")
        for aes in load.getElementsByTagName("arm_aes"):
            if aes.attributes["location"].value == "LA":
                self.aes_la = AES(mech.weight, mech.motive, "Arm")
            elif aes.attributes["location"].value == "RA":
                self.aes_ra = AES(mech.weight, mech.motive, "Arm")

        # Get jump booster
        jumpb = 0
        for jbo in load.getElementsByTagName("jumpbooster"):
            jumpb = int(jbo.attributes["mp"].value)

        self.jumpb = JumpBoosters(mech.weight, jumpb)

        # Get Armored locations
        self.arm_loc = []
        self.arm_gyro = False
        self.armored = False
        for arm in load.getElementsByTagName("armored_locations"):
            for loc in arm.getElementsByTagName("location"):
                index = int(loc.attributes["index"].value)
                location = gettext(loc.childNodes)
                self.arm_loc.append((location, index))
                self.armored = True
                # Armored Gyro
                if location == "CT" and index == 3:
                    self.arm_gyro = True

        self.prod_era = prod_era

        # Get booby trap
        booby = False
        for bob in load.getElementsByTagName("boobytrap"):
            booby = True
        self.btrap = BoobyTrap(mech.weight, booby)

        # Hack: Get turret
        self.turret = False
        for tur in load.getElementsByTagName("turret"):
            self.turret = True

        self.gear = Gear(mech, self.artemis4, self.artemis5, self.apollo, equip, clanc)

        # Add Power Amplifiers
        if self.unit.engine.etype == "I.C.E. Engine" or self.unit.engine.etype == "No Engine":
            self.power_amp = PowerAmp(self, self.gear.weaponlist.ene_weight)
        else:
            self.power_amp = PowerAmp(self, 0.0)

        self.build_special()
Example #9
0
    def __init__(self, xmldoc):
        Unit.__init__(self)

        # This is a mech
        self.type = "BM"

        # Set some data to zero that sometimes will not get set otherwise
        self.multi = Multi()

        # Get top-level structure data
        for mmech in xmldoc.getElementsByTagName('mech'):
            self.model = mmech.attributes["model"].value
            self.name = mmech.attributes["name"].value
            self.omni = mmech.attributes["omnimech"].value
            self.weight = int(mmech.attributes["tons"].value)

            # Get BV. Should give prime variant BV for Omni-mechs
            # get first instance only to avoid problems with Omni-mechs
            self.batt_val = int(get_child_data(mmech, 'battle_value'))

            # Get Cost.
            cost = float(get_child_data(mmech, 'cost'))

            # Get production era
            self.prod_era = int(get_child_data(mmech, 'productionera'))

            # Get mech type (battle, industrial)
            self.mechtype = get_child_data(mmech, 'mech_type')

            # Only support battlemechs
            if (self.mechtype != "BattleMech" and
                self.mechtype != "PrimitiveBattleMech"):
                print self.name, self.model
                print "Industrial Mechs not supported!"
                sys.exit(1)

            # Get techbase (IS, Clan)
            # get first instance only to avoid problems with Omni-mechs
            self.techbase = get_child_data(mmech, 'techbase')

            # Get year
            self.year = int(get_child_data(mmech, 'year'))

            # Sanity check for year
            year_era_test(self.year, self.prod_era,
                          self.name + " " + self.model)

            if (self.year < 2439):
                print self.name, self.model
                print "Battlemech older than Mackie!"
                sys.exit(1)

            if (self.year < 2470 and self.mechtype == "BattleMech"):
                print self.name, self.model
                print "Non-primitive BattleMechs not available before 2470!"
                sys.exit(1)

            if (self.year < 2854 and self.omni == "TRUE"):
                print self.name, self.model
                print "OmniMechs not available before 2854!"
                sys.exit(1)

            # Get motive type (biped, quad)
            self.motive = get_child_data(mmech, 'motive_type')

            ### Components starts here ###

            # Get internal structure type
            self.structure = MechStructure(get_child(mmech, 'structure'),
                                           self.weight, self.motive)

            # Get engine data
            self.engine = Engine(get_child(mmech, 'engine'), self)

            # Get gyro
            self.gyro = Gyro(get_child(mmech, 'gyro'),
                             self.engine.etype, self.engine.erating)

            # Get cockpit
            self.cockpit = Cockpit(get_child(mmech, 'cockpit'), self)

            # Get enhancement, needs for loop
            self.enhancement = Enhancement(None, self.weight,
                                           self.engine.erating)
            for enh in mmech.getElementsByTagName('enhancement'):
                self.enhancement = Enhancement(enh, self.weight,
                                               self.engine.erating)

            # Get armor.
            self.armor = MechArmor(get_child(mmech, 'armor'),
                                   self.weight, self.motive)

            ### Loadout stuff starts here ###

            # Get baseloadout
            blo = mmech.getElementsByTagName('baseloadout')[0]

            # Get multi-slot stuff
            for mlts in blo.getElementsByTagName('multislot'):
                slot = mlts.attributes["name"].value
                self.multi.add(slot)

            # Construct current loadout, empty name for base loadout
            self.load = Baseloadout(blo, self, self.batt_val,
                                    self.prod_era, cost)

            # HACK -- Apply modular armor
            if self.load.gear.has_mod_armor:
                self.armor.apply_modular(self.load.gear.mod_armor)

            # Get omni loadouts
            self.loads = []
            for load in mmech.getElementsByTagName('loadout'):

                # Construct current loadout
                current = Loadout(load, self.load, self)

                self.loads.append(current)
Example #10
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)