Exemple #1
0
 def ForceContact(self, E, e):
     # Force a direct contact of e by E
     cnt = E.Contact(e)
     # If the contact doesn't exist
     if cnt == None:
         cnt = intelligence.sandbox_contact(e)
         E['agent'].ContactUpdate(cnt)
     # Force the visual contact
     if not cnt.IsDirectObs():
         sensor = E.GetDirectVisualSensor()
         sensor.Acquire(E, cnt, True)
Exemple #2
0
 def ForceContact(self, E, e):
   # Force a direct contact of e by E
   cnt = E.Contact(e)
   # If the contact doesn't exist
   if cnt == None:
     cnt = intelligence.sandbox_contact(e)
     E['agent'].ContactUpdate(cnt)
   # Force the visual contact
   if not cnt.IsDirectObs():
     sensor = E.GetDirectVisualSensor()
     sensor.Acquire(E, cnt, True)
Exemple #3
0
 def Detection(self, other):
   '''!
      Handle all the detection and classification as called by the simulator
   '''
   if other.has_key('delete me'):
     return
   
   # fetch the contact
   contact = self.Contact(other)
   if contact == None:
     contact = sandbox_contact(other)
     
   # Acquisition
   self['intelligence'].AcquireTarget(self, other)
Exemple #4
0
    def Detection(self, other):
        """!
       Handle all the detection and classification as called by the simulator
    """
        if other.has_key("delete me"):
            return

        # fetch the contact
        contact = self.Contact(other)
        if contact == None:
            contact = sandbox_contact(other)

        # Acquisition
        self["intelligence"].AcquireTarget(self, other)
Exemple #5
0
  def fromXML(self, doc, node):
    # Read templates and data from XML to populate the data fields.
    # Identity, size and echelon
    self['name'] = doc.SafeGet(node, 'identity', self.GetName())
    self['side'] = doc.SafeGet(node, 'side', self['side'])
    self['size'] = doc.SafeGet(node, 'size', self['size'])
    self['command_echelon'] = doc.SafeGet(node, 'command_echelon', self['command_echelon'])
    
    # Deploment Status
    self['stance'] = doc.SafeGet(node, 'stance', self['stance'])
    self['dismounted'] = bool(doc.SafeGet(node, 'dismounted', self['dismounted']))
    self['readiness'] = doc.SafeGet(node, 'readiness', self['readiness'])
    
    # Position descriptor ###################################
    # Fetch the node, either a pos_desc or location
    ploc = doc.Get(node, 'location')
    if ploc != '':
      # Check for type of location
      loctype = doc.Get(ploc, 'type')
      if loctype == '':
        raise SandboxException('NoTypedLocation',self.GetName())
      if loctype == 'coordinates':
        # Get the content of the node
        coord = doc.Get(ploc)
      elif loctype == 'named_location':
        # Get the coordinate from the network
        nd = self.sim.network.GetNode(doc.Get(ploc))
        # Get the coordinate from the node
        coord = nd.Coordinates()
      else:
        raise SandboxException('UnsupportedLocationType',[loctype,self.GetName()])
      # convert to a position vector
      self.SetPosition(self.sim.map.MGRS.AsVect(coord))
    
    # Systems #####################################################
    models = doc.Get(node,'models')
    if models != '':
      for i in ['C4I','combat','intelligence','movement','logistics']:
        # Get the model node
        x = doc.Get(models,i)
        
        # No model specified
        if x == '':
          self.sim.data.FetchData(self[i],i,'base')
        elif doc.Get(x,'template') in ['', 'base']:
          # Load base model
          self.sim.data.FetchData(self[i],i,'base')
        else:
          # Load correct template
          self.sim.data.FetchData(self[i],i,doc.Get(x,'template'))
          
        # Read the node itself
        if x:
          self[i].fromXML(doc,x)
      
    # Systems and components #######################################
    x = doc.Get(node, 'TOE')
    if x:
      z = doc.Get(x,'category')
      if z:
        self['TOE'] = z

      # Personel
      z = doc.Get(x,'personel', True)
      for it in z:
        kit = doc.Get(it,'template')
        auth = doc.Get(it,'authorized')
        count = doc.Get(it,'count')
        if count == '':
          count = auth
        self.personel[kit] = sandbox_component_state('personel', self.sim.data.Get('personel',kit), count, auth)
        
      # vehicle
      z = doc.Get(x,'vehicle', True)
      for it in z:
        kit = doc.Get(it,'template')
        auth = doc.Get(it,'authorized')
        count = doc.Get(it,'count')
        if count == '':
          count = auth
        self.vehicle[kit] = sandbox_component_state('vehicle', self.sim.data.Get('vehicle',kit), count, auth)     
      self['movement'].SetVehicles(self.vehicle.values())
      
      # Sensors TODO
      
    # Human Factors ################################################
    x = doc.Get(node, 'human_factors')
    if x:
      temp = doc.AttributesAsDict(x)
      for i in temp.keys():
        self[i] = temp[i]
        
    # Operational Orders ###########################################
    x = doc.SafeGet(node, 'OPORD', self['OPORD'])
      
        
    # Chain of command #############################################
    coc = doc.Get(node, 'chain_of_command')
    if coc:
      # HIGHER (the TOE HQ)
      hq = doc.Get(coc, 'HIGHER')
      opcon = doc.Get(coc, 'OPCON')
      subs = doc.Get(coc, 'subordinate', True)
      if self.sim:
        # The HIGHER unit
        x = self.sim.GetEntity(self['side'],hq)
        if x:
          self['HQ'] = x
        elif hq:
          self['HQ'] = hq
        
        # The OPCON unit
        x = self.sim.GetEntity(self['side'],opcon)
        if x:
          self['OPCON'] = x
        elif hq:
          self['OPCON'] = opcon
          
        # Subordinates
        for u in subs:
          # The subordinates unit
          x = self.sim.GetEntity(self['side'],u)
          if x:
            self.AddSubordinate(x)
          else:
            # Will need to be connected to the right pointer after loading the file
            self['subordinates'] = u
        
        # INTEL picture
        intel = doc.Get(node, 'intel_picture')
        if intel:
          # Read in the contacts
          for nd in doc.ElementAsList(intel):
            key = doc.Get(nd,'key')
            cnt = sandbox_contact()
            cnt.fromXML(doc, nd)
            self['contacts'][key] = cnt
Exemple #6
0
 def type_contact(self, node):
     '''! \brief Return an instance of contact from a node definition.
     '''
     out = sandbox_contact()
     out.fromXML(self, node)
     return out
Exemple #7
0
 def type_contact(self, node):
     '''! \brief Return an instance of contact from a node definition.
     '''
     out = sandbox_contact()
     out.fromXML(self, node)
     return out
Exemple #8
0
    def fromXML(self, doc, node):
        # Read templates and data from XML to populate the data fields.
        # Identity, size and echelon
        self["name"] = doc.SafeGet(node, "identity", self.GetName())
        self["side"] = doc.SafeGet(node, "side", self["side"])
        self["size"] = doc.SafeGet(node, "size", self["size"])
        self["command_echelon"] = doc.SafeGet(node, "command_echelon", self["command_echelon"])

        # Deploment Status
        self["stance"] = doc.SafeGet(node, "stance", self["stance"])
        self["dismounted"] = bool(doc.SafeGet(node, "dismounted", self["dismounted"]))
        self["readiness"] = doc.SafeGet(node, "readiness", self["readiness"])

        # Position descriptor ###################################
        # Fetch the node, either a pos_desc or location
        ploc = doc.Get(node, "location")
        if ploc != "":
            # Check for type of location
            loctype = doc.Get(ploc, "type")
            if loctype == "":
                raise SandboxException("NoTypedLocation", self.GetName())
            if loctype == "coordinates":
                # Get the content of the node
                coord = doc.Get(ploc)
            elif loctype == "named_location":
                # Get the coordinate from the network
                nd = self.sim.network.GetNode(doc.Get(ploc))
                # Get the coordinate from the node
                coord = nd.Coordinates()
            else:
                raise SandboxException("UnsupportedLocationType", [loctype, self.GetName()])
            # convert to a position vector
            self.SetPosition(self.sim.map.MGRS.AsVect(coord))

        # Systems #####################################################
        models = doc.Get(node, "models")
        if models != "":
            for i in ["C4I", "combat", "intelligence", "movement", "logistics"]:
                # Get the model node
                x = doc.Get(models, i)

                # No model specified
                if x == "":
                    self.sim.data.FetchData(self[i], i, "base")
                elif doc.Get(x, "template") in ["", "base"]:
                    # Load base model
                    self.sim.data.FetchData(self[i], i, "base")
                else:
                    # Load correct template
                    self.sim.data.FetchData(self[i], i, doc.Get(x, "template"))

                # Read the node itself
                if x:
                    self[i].fromXML(doc, x)

        # Systems and components #######################################
        x = doc.Get(node, "TOE")
        if x:
            z = doc.Get(x, "category")
            if z:
                self["TOE"] = z

            # Personel
            z = doc.Get(x, "personel", True)
            for it in z:
                kit = doc.Get(it, "template")
                auth = doc.Get(it, "authorized")
                count = doc.Get(it, "count")
                if count == "":
                    count = auth
                self.personel[kit] = sandbox_component_state(
                    "personel", self.sim.data.Get("personel", kit), count, auth
                )

            # vehicle
            z = doc.Get(x, "vehicle", True)
            for it in z:
                kit = doc.Get(it, "template")
                auth = doc.Get(it, "authorized")
                count = doc.Get(it, "count")
                if count == "":
                    count = auth
                self.vehicle[kit] = sandbox_component_state("vehicle", self.sim.data.Get("vehicle", kit), count, auth)
            self["movement"].SetVehicles(self.vehicle.values())

            # Sensors TODO

        # Human Factors ################################################
        x = doc.Get(node, "human_factors")
        if x:
            temp = doc.AttributesAsDict(x)
            for i in temp.keys():
                self[i] = temp[i]

        # Operational Orders ###########################################
        x = doc.SafeGet(node, "OPORD", self["OPORD"])

        # Chain of command #############################################
        coc = doc.Get(node, "chain_of_command")
        if coc:
            # HIGHER (the TOE HQ)
            hq = doc.Get(coc, "HIGHER")
            opcon = doc.Get(coc, "OPCON")
            subs = doc.Get(coc, "subordinate", True)
            if self.sim:
                # The HIGHER unit
                x = self.sim.GetEntity(self["side"], hq)
                if x:
                    self["HQ"] = x
                elif hq:
                    self["HQ"] = hq

                # The OPCON unit
                x = self.sim.GetEntity(self["side"], opcon)
                if x:
                    self["OPCON"] = x
                elif hq:
                    self["OPCON"] = opcon

                # Subordinates
                for u in subs:
                    # The subordinates unit
                    x = self.sim.GetEntity(self["side"], u)
                    if x:
                        self.AddSubordinate(x)
                    else:
                        # Will need to be connected to the right pointer after loading the file
                        self["subordinates"] = u

                # INTEL picture
                intel = doc.Get(node, "intel_picture")
                if intel:
                    # Read in the contacts
                    for nd in doc.ElementAsList(intel):
                        key = doc.Get(nd, "key")
                        cnt = sandbox_contact()
                        cnt.fromXML(doc, nd)
                        self["contacts"][key] = cnt