def action_insert_node(self, parent, child_index, node):
     previous_sibling = get_child(parent, child_index - 1)
     next_sibling = get_child(parent, child_index)
     insert_or_append(parent, node, next_sibling)
     # add node to ins_nodes
     assert node.parentNode is not None
     node.orig_parent = parent
     node.orig_next_sibling = next_sibling
     self.ins_nodes.append(node)
 def action_insert_node(self, parent, child_index, node):
     previous_sibling = get_child(parent, child_index - 1)
     next_sibling = get_child(parent, child_index)
     insert_or_append(parent, node, next_sibling)
     # add node to ins_nodes
     assert node.parentNode is not None
     node.orig_parent = parent
     node.orig_next_sibling = next_sibling
     self.ins_nodes.append(node)
Esempio n. 3
0
    def __init__(self, load, mech, batt_val, prod_era, cost):

        # Save year
        self.year = mech.year

        # Get equipment
        self.equip = []

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

        Load.__init__(self, load, mech, batt_val, prod_era, self.equip, cost)

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

        # Get heat sinks
        self.heatsinks = Heatsinks(get_child(load, "heatsinks"), self)

        # Get partial wing
        partw = False
        tech = 2
        for paw in load.getElementsByTagName("partialwing"):
            partw = True
            tech = int(paw.attributes["tech"].value)

        self.partw = PartialWing(mech.weight, partw, tech)
Esempio n. 4
0
 def insert(self, location, node):
     # write insertion to the edit script
     self.edit_script.append((
         'insert',
         location,
         node_properties(node),
     ))
     # actually insert the node
     node_copy = node.cloneNode(deep=False)
     parent = get_location(self.old_dom, location[:-1])
     next_sibling = get_child(parent, location[-1])
     insert_or_append(parent, node_copy, next_sibling)
     # insert from the top down, parent before children, left to right
     for child_index, child in enumerate(node.childNodes):
         self.insert(location + [child_index], child)
Esempio n. 5
0
 def insert(self, location, node):
     # write insertion to the edit script
     self.edit_script.append((
         'insert',
         location,
         node_properties(node),
     ))
     # actually insert the node
     node_copy = node.cloneNode(deep=False)
     parent = get_location(self.old_dom, location[:-1])
     next_sibling = get_child(parent, location[-1])
     insert_or_append(parent, node_copy, next_sibling)
     # insert from the top down, parent before children, left to right
     for child_index, child in enumerate(node.childNodes):
         self.insert(location + [child_index], child)
Esempio n. 6
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)
Esempio n. 7
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)