Exemplo n.º 1
0
    def __init__(self, data):
        self.subItems = []
        self.effectSettings = None
        self.affectedParts = []
        self.customSettings = {}
        if IS_AIRPLANE_EDITOR:
            self.__data = data
        if data != None:
            params = (('id', 0), ('usage', ''), ('model', ''),
                      ('animationController', ''), ('stateHelthCfc', 0.0),
                      ('stateFireChance', 0.2), ('stateAction',
                                                 STATE_ACTION_NONE),
                      ('fallingOutModel', ''), ('stateAnimation', ''))
            if IS_AIRPLANE_EDITOR:
                self.__params = params
            readValues(self, data, params)
            if self.id == 0:
                DBLOG_ERROR('state id missed for part')
            if self.stateHelthCfc < 0 and self.stateHelthCfc != ANIMATION_STATE_HEALTH_K:
                DBLOG_ERROR('invalid stateHelthCfc')
            bBoxesData = findSection(data, 'bBoxes')
            self.bboxes = bBoxesData and BBoxes(bBoxesData) or None
            affectedPartsData = findSection(data, 'affectedParts')
            if affectedPartsData:
                for partData in affectedPartsData.values():
                    partID = partData.readInt('partID', -1)
                    if partID != -1:
                        minimalPartState = partData.readInt(
                            'minimalPartState', 1)
                        self.affectedParts.append((partID, minimalPartState))

            usagestr = self.usage.lower()
            self.stateFlag = 0
            if usagestr.find(PART_STATE_HANGAR) != -1:
                self.stateFlag = self.stateFlag | PART_STATE_IDHANGAR
            if usagestr.find(PART_STATE_CRASH) != -1:
                self.stateFlag = self.stateFlag | PART_STATE_IDCRASH
            if usagestr.find(PART_STATE_FALL) != -1:
                self.stateFlag = self.stateFlag | PART_STATE_IDFALL
            subItemsSection = findSection(data, 'subItems')
            if subItemsSection != None:
                for subItemData in subItemsSection.values():
                    subItem = PartTypeStateSubItemSettings(subItemData)
                    self.subItems.append(subItem)

            self.effectSettings = EffectsSettings(data)
            decalSection = findSection(data, 'groundDecal')
            if decalSection:
                self.groundDecal = GroundDecal(decalSection)
            settings = CustomSettingsFactory.readSettings(data)
            if settings:
                self.customSettings[settings.name()] = settings
        return
Exemplo n.º 2
0
 def removeBbox(self, bboxId):
     if IS_AIRPLANE_EDITOR:
         bboxSection = findSection(self.__data, 'bBoxes')
         if bboxSection is None:
             DBLOG_ERROR("Error: removeBbox, XML hasn't section bBoxes")
             return
         if bboxId - 1 < len(bboxSection.values()):
             data = bboxSection.values()[bboxId - 1]
             bboxSection.deleteSection(data)
         else:
             DBLOG_ERROR('Error: removeBbox, bbox xml section is not exist')
         self.bboxes.deleteBox(bboxId - 1)
     return
Exemplo n.º 3
0
    def removeState(self, stateId):
        if IS_AIRPLANE_EDITOR:
            statesSection = findSection(self.__data, 'states')
            if statesSection is None:
                DBLOG_ERROR("Error: removeState, XML hasn't section states")
                return
            data = None
            for stateData in statesSection.values():
                if stateData.readInt('id') == stateId:
                    data = stateData
                    break

            if data is not None:
                statesSection.deleteSection(data)
                del self.states[stateId]
            else:
                DBLOG_ERROR('Error: removeState, state is not exist')
        return
Exemplo n.º 4
0
    def removeSubitem(self, subitemId):
        if IS_AIRPLANE_EDITOR:
            subItemsSection = findSection(self.__data, 'subItems')
            if subItemsSection is None:
                DBLOG_ERROR(
                    "Error: removeSubitem, XML hasn't section subItems")
                return
            data = None
            i = 0
            for subitemData in subItemsSection.values():
                if i == subitemId:
                    data = subitemData
                    break
                i += 1

            if data is not None:
                subItemsSection.deleteSection(data)
                del self.subItems[subitemId]
            else:
                DBLOG_ERROR('Error: removeState, state is not exist')
        return
Exemplo n.º 5
0
    def removeType(self, typeId):
        if IS_AIRPLANE_EDITOR:
            for typeName, typeData in self.__data.items():
                if typeName == 'upgrade' and typeData.readInt('id') == typeId:
                    data = typeData
                    break

            if data is not None:
                self.__data.deleteSection(data)
                del self.upgrades[typeId]
            else:
                DBLOG_ERROR('Error: removeType, type is not exist')
        return
Exemplo n.º 6
0
def gunProfilesPostInit(weaponsDB, gunsProfilesDB):
    """Post postinit for guns"""
    for index, gun in enumerate(weaponsDB.gun):
        for gunProfile in gunsProfilesDB.gunProfile:
            if gunProfile.name == gun.gunProfileName:
                weaponsDB.gun[index] = patchItem(gun, gunProfile)
                DBLOG_NOTE(
                    "Gun '%s' successfully updated with gun profile '%s'" %
                    (gun.name, gunProfile.name))
                break
        else:
            DBLOG_ERROR(
                "No gun profile '%s' found for gun '%s', please fix aircrafts.xml."
                % (gun.gunProfileName, gun.name))
Exemplo n.º 7
0
    def removePart(self, partId):
        if IS_AIRPLANE_EDITOR:
            data = None
            for partData in self.__data.values():
                if partData.readInt('partId') == partId:
                    data = partData
                    break

            if data is not None:
                self.__data.deleteSection(data)
                partName = self.__partsByID[partId].name
                del self.__partsByID[partId]
                del self.__partsByName[partName]
            else:
                DBLOG_ERROR('Error: removePart, part is not exist')
        return
Exemplo n.º 8
0
    def readData(self, data, newDatabase):
        r"""
                Loads tunes and some other data from XML.
                For newDatabase structure please refer to \depot        runc\game\hammer
        es\scripts\common\_aircrafts_db.py
                _aircrafts_db.py is autogenerated from aircrafts.xml
                Please see Confluence docs for more info.
        
                Also please note that flight model params are overloaded from newDatabase, see below at the end of method.
                """
        if data != None:
            airplaneData = findSection(data, 'Airplane')
            if airplaneData is None and newDatabase is not None:
                LOG_ERROR('No Airplane section for last .xml file. Set config_consts.DB_ENABLE_LOG to True for get more information')
                sys.exit()
            if IS_EDITOR:
                self.__data = airplaneData
            if airplaneData is not None:
                params = (('name', ''),
                 ('longName', ''),
                 ('model', ''),
                 ('stealthFactor', 1.0),
                 ('collisionDamageCfc', 0.001),
                 ('autoPilotStartAlt', 60.0),
                 ('autoPilotEndAlt', 100.0),
                 ('hudIcoPath', NOT_AVAILABLE),
                 ('iconPath', NOT_AVAILABLE),
                 ('previewIconPath', NOT_AVAILABLE),
                 ('treeIconPath', NOT_AVAILABLE),
                 ('shakingProfile', ''))
                if IS_EDITOR:
                    self.__params = params
                readValues(self, airplaneData, params)
                visualSettingsData = findSection(airplaneData, 'visualSettings')
                if self.visualSettings:
                    self.visualSettings.readData(visualSettingsData)
                else:
                    self.visualSettings = AirCraftVisualSettings(visualSettingsData)
                partsSettingsData = findSection(airplaneData, 'parts')
                if self.partsSettings:
                    self.partsSettings.readData(partsSettingsData)
                else:
                    self.partsSettings = PartsTunes(partsSettingsData)
                if IS_DEVELOPMENT and IS_CELLAPP:
                    try:
                        requiredCritableStatesSet = set([1,
                         2,
                         3,
                         4])
                        from EntityHelpers import getPartEnum
                        from AvatarCritsSystem import AvatarCritsSystem

                        def checkAffectedPartsMissedStates(upgrade):
                            for state in upgrade.states.itervalues():
                                for aPartID, aPartMinState in state.affectedParts:
                                    aPart = self.partsSettings.getPartByID(aPartID)
                                    if aPart:
                                        for aUpgrade in aPart.upgrades.itervalues():
                                            if aPartMinState not in set(aUpgrade.states):
                                                yield (upgrade.id,
                                                 aPartID,
                                                 aUpgrade.id,
                                                 aPartMinState)

                                    else:
                                        yield (upgrade.id, aPartID)

                        for part in self.partsSettings.getPartsOnlyList():
                            for upgrade in part.upgrades.itervalues():
                                if getPartEnum(upgrade) in AvatarCritsSystem.CRITABLE_PARTS:
                                    absentStates = requiredCritableStatesSet.difference(set(upgrade.states))
                                    if absentStates:
                                        DBLOG_CRITICAL(part.partId, part.name, 'PARTS_VALIDATION_ERROR critable part has no all required states:', upgrade.id, absentStates)
                                missedStates = list(checkAffectedPartsMissedStates(upgrade))
                                if missedStates:
                                    LOG_ERROR(part.partId, part.name, upgrade.id, 'PARTS_VALIDATION_ERROR part has no such affected states:', missedStates)

                    except Exception as e:
                        import sys
                        LOG_DEBUG_DEV(sys.exc_info())

                self.bboxes = BBoxes(findSection(airplaneData, 'bBoxes'))

                def magnetPoints(section):
                    section = findSection(section, 'magnetPoints')
                    if section:
                        for id, data in section.items():
                            yield {'position': data.readVector3('position', Math.Vector3()) * WORLD_SCALING,
                             'weight': data.readFloat('staticMass', 1.0)}

                self.magnetPoints = tuple(magnetPoints(data))
                descriptionData = findSection(airplaneData, 'description')
                if self.description:
                    self.description.readData(descriptionData)
                else:
                    self.description = AirCraftDescription(descriptionData)
                if newDatabase:
                    for aircraft in newDatabase.aircraft:
                        if aircraft.name == self.name.lower():
                            aircraftData = aircraft
                            break
                    else:
                        aircraftData = None

                    if aircraftData == None:
                        DBLOG_ERROR("No new style database data found for aircraft '" + self.name + ' (' + self.longName + ')' + "', Please check aircrafts.xml and _aircrafts_db.py.")
                    else:
                        DBLOG_NOTE("New style database data available for aircraft '" + self.name + "', Ok.")
                        self.patch(aircraftData)
        return
Exemplo n.º 9
0
 def getDecal(self, id):
     if id in self.decals:
         return self.decals[id]
     else:
         DBLOG_ERROR("Can't find decal with ID: " + str(id))
         return None
Exemplo n.º 10
0
 def getDecalTexNameByID(self, id):
     if id in self.decals:
         return self.decals[id].texture
     else:
         DBLOG_ERROR("Can't find decal with ID: " + str(id))
         return ''