def addProp(self, propertieName: str, propertieValue: object): """Add a propertie to object (used for create method) """ if propertieName != OBJECTSCRIPT and propertieName != MULTIPLAYERPLANECONFIG: if propertieName in self.PropList and propertieName not in DUPLICATE_CTRIGGER: warning_msg( DUPLICATE_PROPERTIE.format(propertieName, self.PropList[INDEX])) else: self.PropList[propertieName] = propertieValue else: # handle multiple "ObjectScript" or "MultiplayerPlaneConfig" if propertieName not in self.PropList: self.PropList[propertieName] = list() self.PropList[propertieName].append(propertieValue)
def add_ObjScriptList(mission: Mission, objList: list, ObjScriptList: list = None, Countries: list = None, reset=0): """ add object scripts if provided and countries if provided in field "ObjectScript" and "country" of objects objList :param mission: Mission mission containing objects to modify :param objList: list list of object ID to modify : must be complex trigger :param objScriptList: list list of script names to add (can be empty if only countries are to be added) :param countries: list list of countries ID to add (can be empty if only script names are to be added) :param reset: int optional if set to 1 reset script and country list """ # for all objects try to update prop for obj in objList: #check if prop OBJECTSCRIPT exists if OBJECTSCRIPT not in mission.ObjList[obj].PropList: warning_msg(PROP_NOT_EXISTING_FOR_MOD.format(OBJECTSCRIPT, obj)) else: # update the prop obj script if param not empty if ObjScriptList: if reset == 1: mission.ObjList[obj].PropList[OBJECTSCRIPT] = list() for scriptName in ObjScriptList: # fix in case of " missing if '\"' not in scriptName: scriptName = '\"' + scriptName + '\"' mission.ObjList[obj].PropList[OBJECTSCRIPT].append( scriptName) # check if prop COUNTRIES exists if COUNTRY not in mission.ObjList[obj].PropList: warning_msg(PROP_NOT_EXISTING_FOR_MOD.format(COUNTRY, obj)) else: # update the prop obj script if param not empty if Countries: if reset == 1: mission.ObjList[obj].PropList[COUNTRY] = list() for countryID in Countries: mission.ObjList[obj].PropList[COUNTRY].append(countryID) return
def modify_kv(mission: Mission, objList: list, **properties): """ modify key Value properties for a list of objects :param mission: Mission mission containing objects to modify :param objList: list list of object ID to modify :param properties : dict list of key / value to modify """ #not really used... status = 0 for objIndex in objList: for key, val in properties.items(): if key in mission.ObjList[objIndex].PropList: value = val if key == INDEX: criticalError(CAN_NOT_MODIFY_INDEX.format(objIndex)) if callable(val): value = val(mission.ObjList[objIndex]) if type(mission.ObjList[objIndex].PropList[key]) == float: mission.ObjList[objIndex].PropList[key] = float(value) if type(mission.ObjList[objIndex].PropList[key]) == int: mission.ObjList[objIndex].PropList[key] = int(value) if type(mission.ObjList[objIndex].PropList[key]) == str: mission.ObjList[objIndex].PropList[key] = str(value) elif LINKTRID in mission.ObjList[objIndex].PropList: #test if prop exists in linked entity linkTRID = mission.ObjList[objIndex].PropList[LINKTRID] tempdict = {key: val} if linkTRID != 0: # try to update prop in object tempList = [linkTRID] status = modify_kv(mission, tempList, **tempdict) else: # prop not existing for object name = "" if NAME in mission.ObjList[objIndex].PropList: name = mission.ObjList[objIndex].PropList[NAME] warning_msg( PROP_TO_MODIFY_NOT_EXISTS.format(key, objIndex, name)) return status
def add_OnReports(mission: Mission, objList: list, reportName: str, commandID: list, targetID: list, reset=0): """ add targetList objects for event reportNumber of objects objList :param mission: Mission mission containing objects to modify :param objList: list list of object ID to modify :param reportName: str name of report (see declarations\report_definition.py) :param commandID: list object ID to use as command, in a list comming from "find object' :param targetID: list object ID to use as target, in a list comming from "find object' :param reset: int if set to 1 reset Report list """ for obj in objList: #Find MCU_TR_Entity associated to object if LINKTRID in mission.ObjList[obj].PropList: linkTrId = mission.ObjList[obj].PropList[LINKTRID] if linkTrId == 0: warning_msg(ENTITY_NOT_LINKED.format(obj, 'add_OnReport')) else: if reset == 1 or ONREPORTS not in mission.ObjList[ linkTrId].PropList: # reset or create OnReports list mission.ObjList[linkTrId].PropList[ONREPORTS] = list() #create a new propertie and add it to the 'OnReports' list prop = Properties('') prop.Value = dict() prop.Value[TYPE] = findReport(mission.ObjList[obj].type, reportName) prop.Value[CMDID] = commandID[0] prop.Value[TARID] = targetID[0] prop.Value['LIST_NAME;'] = ONREPORT mission.ObjList[linkTrId].PropList[ONREPORTS].append(prop) else: warning_msg(ENTITY_NOT_LINKED.format(obj, 'add_OnReport'))
def findObjectInRange(mission:Mission, centerObj:list, Range:int, **parameters): """find objects of a mission by using range from a given object and same filtering parameter as for findObject :param mission: Mission mission containing objects to search :param centerObj: list ID of object center of the range to search :param: range : int Radius of the circle around centerObj that whill be used to filter objects :param parameters: dict all criterion to search objects, separated by , eg groupList = findObject(newMission, Type='Vehicle', Index=range(11,16), XPos=range(29000,29700), ZPos=range(25000,27000)) filter criterions key=value eg: Name='Blue', Xpos=3.23, Type="Plane" if string is used fpr any key except Type, it will be used as regex. Eg 'Plane' = ok for every string containing 'Plane', '^Plane$' ok only for string containing strictly Plane Type field must be the exact string with exact case key=range(min, max) eg Index=range(11,16), XPos=range(29000,29700) range value must be int but propertie can be float. Criterion will be ok if Range min <= key value <= Range Max :return list: list of object ID that fullfill criterions """ filteredList = list() if 'FromPoint' in parameters: criticalError(DOUBLE_RANGE_FILTER) else: if len(centerObj) == 0: warning_msg(EMPTY_CENTER) elif len(centerObj) > 1: warning_msg(ONLY_FIRST_OBJECT_USED.format(centerObj)) else: #create FromPoint parameter fromPointlist=list() fromPointlist.append(int(mission.ObjList[centerObj[0]].PropList[XPOS])) fromPointlist.append(int(mission.ObjList[centerObj[0]].PropList[ZPOS])) fromPointlist.append(Range) parameters['FromPoint']=fromPointlist filteredList = findObject(mission, **parameters) return filteredList
def filterListOfObject(mission:Mission, objIndexList:list, dictOfFilter:dict ): """find objects of a mission by using and key = value parameters""" filteredList=list() for index in objIndexList: criterion = 0 # create an object by cloning current object and its linked entity if any currentObj = mission.ObjList[index].cloneWithLinkedEntityProp(0, mission) for key, val in dictOfFilter.items(): if key not in currentObj.PropList and key not in EXCEPTION_FOR_FILTER: warning_msg(PROP_NOT_EXISTING.format(key,mission.ObjList[index].PropList[INDEX])) elif key not in EXCEPTION_FOR_FILTER: #handle standard properties processing currentProp = currentObj.PropList[key] if isinstance(val, str): #handle string criterion if re.search(val, str(currentProp).replace("\"","")): criterion += 1 elif isinstance(val, range): #handle range criterion rangeprobe=list(val) if len(rangeprobe) == 0: criticalError(BAD_FILTER_RANGE.format(val)) if isinstance(rangeprobe[0], int) and isinstance(currentProp, int): # do iteration on range fixedRange = list(range(rangeprobe[0], rangeprobe[len(rangeprobe)-1] + 2)) if index in fixedRange: criterion += 1 elif isinstance(rangeprobe[0], int) and type(currentProp) == float: #float values: use min and max if currentProp >= rangeprobe[0] and currentProp <= rangeprobe[len(rangeprobe)-1]: criterion += 1 else : criticalError(INVALID_TYPE_FOR_RANGE.format(type(currentObj.PropList[key]), key, val, currentObj.PropList[NAME])) else: #handle direct comparison or list scanning #unitary value if type(currentObj.PropList[key]) == float or type(currentObj.PropList[key]) == int or type(currentObj.PropList[key]) == str: #if mission.ObjList[index].PropList[key] == val: if currentObj.PropList[key] == val: criterion += 1 #handle set (target, object) elif type(currentObj.PropList[key]) == set: if type(val) != int: warning_msg(TYPE_NOT_SUPPORTED_FOR_REQUEST.format(type(val), key)) if val in currentObj.PropList[key]: criterion += 1 #handle tupple : should be only 'ObjectScript' elif type(currentObj.PropList[key]) == tuple: if type(val) != str and key == OBJECTSCRIPT: warning_msg(TYPE_NOT_SUPPORTED_FOR_REQUEST.format(type(val), key)) if val in currentObj.PropList[key]: criterion += 1 else: #FromProint Xcenter =val[0] Zcenter=val[1] radius=val[2] distanceX = (Xcenter-currentObj.PropList[XPOS])*(Xcenter-currentObj.PropList[XPOS]) distanceZ = (Zcenter-currentObj.PropList[ZPOS])*(Zcenter-currentObj.PropList[ZPOS]) distance = math.sqrt( distanceX+distanceZ ) if (distance <= radius): criterion+=1 if criterion == len(dictOfFilter): filteredList.append(index) return filteredList