Ejemplo n.º 1
0
        protected void MoveDone(SimulationEvent ev)
        {//ObjectID, Reason
            String id = ((StringValue)ev["ObjectID"]).value;

            if (!_revealedObjects.ContainsKey(id))
            {
                return;
            }
            AttributeCollectionValue atts = new AttributeCollectionValue();

            atts.attributes.Add("DestinationLocation", new LocationValue());
            atts.attributes.Add("Throttle", DataValueFactory.BuildDouble(0));

            String owner = _revealedObjects[id].Owner;

            foreach (PolygonValue region in GetAllEntryRegions())
            {
                if (Polygon2D.IsPointInside(new Polygon2D(region), new Vec2D(GetSeamateObject(id).Location)) &&
                    owner == "Merchant DM")
                {
                    Console.WriteLine("Detected vessel " + id + " ending move in entry region, turning state to Dead.");
                    //atts.attributes.Add("State", DataValueFactory.BuildString("Dead"));
                    _dddConnection.SendStateChange(id, "Dead");
                }
            }


            //LocationValue destLoc =  as LocationValue;
            _revealedObjects[id].SetAttributes(atts);
        }
Ejemplo n.º 2
0
        private void RevealObject(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies(); // update my objects record
            AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"];

            if (e["ObjectID"] != null)
            {
                string id = ((StringValue)e["ObjectID"]).value;
                SimulationObjectProxy prox = null; // objectProxies[id];
                prox = GetObjectProxy(id);
                if (prox == null)
                {
                    return;
                }

                // initialize any object values I need to.

                foreach (string attname in atts.attributes.Keys)
                {
                    if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner())
                    {
                        prox[attname].SetDataValue(atts[attname]);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 protected void RevealObject(SimulationEvent ev)
 {
     lock (GroundTruthLock)
     {
         String id = ((StringValue)ev["ObjectID"]).value;
         AttributeCollectionValue atts          = ev["Attributes"] as AttributeCollectionValue;
         SeamateObject            seamateObject = null;
         if (_unrevealedObjects.ContainsKey(id))
         {
             seamateObject = _unrevealedObjects[id];
             _unrevealedObjects.Remove(id);
             Console.WriteLine("Removed from UnrevealedObjects: " + id);
         }
         else
         {
             seamateObject = new SeamateObject(id);
         }
         seamateObject.SetAttributes(atts);
         if (_revealedObjects.ContainsKey(id))
         {
             _revealedObjects.Remove(id);
         }
         _revealedObjects.Add(id, seamateObject);
         Console.WriteLine("Added to RevealedObjects: " + id);
         if (atts.attributes.ContainsKey("OwnerID"))
         {
             EstablishOwnership(id, ((StringValue)atts.attributes["OwnerID"]).value);
         }
     }
 }
Ejemplo n.º 4
0
        public override SimulationEvent ToSimulationEvent(ref SimulationModelInfo simModel)
        {
            SimulationEvent          ev         = SimulationEventFactory.BuildEvent(ref simModel, EVENTTYPE);
            AttributeCollectionValue attributes = new AttributeCollectionValue();

            attributes.attributes.Add("Location", this.Location);
            attributes.attributes.Add("State", DataValueFactory.BuildString(this.State));

            if (ObjectType != null && ObjectType != String.Empty)
            {
                attributes.attributes.Add("ClassName", DataValueFactory.BuildString(ObjectType));
            }
            if (OwnerID != null && OwnerID != String.Empty)
            {
                attributes.attributes.Add("OwnerID", DataValueFactory.BuildString(OwnerID));
            }

            if (StartupParameters != null)
            {
                foreach (String s in StartupParameters.Keys)
                {
                    attributes.attributes.Add(s, StartupParameters[s]);
                }
            }


            //do stuff
            ((StringValue)ev["ObjectID"]).value = this.ObjectID;
            ev["Attributes"] = attributes;



            return(ev);
        }
Ejemplo n.º 5
0
        private void RevealObject(SimulationEvent e)
        {
            AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"];
            string id = ((StringValue)e["ObjectID"]).value;

            SimulationObjectProxy prox = null;// objectProxies[id];

            prox = GetObjectProxy(id);
            if (prox == null)
            {
                return;
            }


            foreach (string attname in atts.attributes.Keys)
            {
                if (attname == "ID")
                {
                    continue;
                }
                if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner())
                {
                    prox[attname].SetDataValue(atts[attname]);
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="dmID"></param>
 /// <param name="incoming"></param>
 private void UpdateDMsViews(string dmID, ref Dictionary <string, AttributeCollectionValue> incoming)
 {
     foreach (string obj in incoming.Keys)
     {
         AttributeCollectionValue acv = incoming[obj];
         dmViews[dmID].UpdateObjectsAttributes(ref acv, obj);
     }
 }
Ejemplo n.º 7
0
 protected void ViewProAttributeUpdate(SimulationEvent ev)
 {
     lock (GroundTruthLock)
     {
         String id = ((StringValue)ev["ObjectID"]).value;
         AttributeCollectionValue atts = ev["Attributes"] as AttributeCollectionValue;
         if (_revealedObjects.ContainsKey(id))
         {
             _revealedObjects[id].SetAttributes(atts);
         }
     }
 }
Ejemplo n.º 8
0
            internal void SetAttributes(AttributeCollectionValue atts)
            {
                if (atts.attributes.ContainsKey("GroundTruthIFF"))
                {
                    this.GroundTruthIFF = ((StringValue)atts.attributes["GroundTruthIFF"]).value;
                }
                if (atts.attributes.ContainsKey("Heading"))
                {
                    this.Heading = ((DoubleValue)atts.attributes["Heading"]).value;
                }

                if (atts.attributes.ContainsKey("ClassName"))
                {
                    this.ClassName = ((StringValue)atts.attributes["ClassName"]).value;
                }
                if (atts.attributes.ContainsKey("State"))
                {
                    this.State = ((StringValue)atts.attributes["State"]).value;
                }
                if (atts.attributes.ContainsKey("Location"))
                {
                    this.Location = ((LocationValue)atts.attributes["Location"]);
                }
                if (atts.attributes.ContainsKey("Throttle"))
                {
                    this.Throttle = ((DoubleValue)atts.attributes["Throttle"]).value;
                }
                if (atts.attributes.ContainsKey("MaximumSpeed"))
                {
                    this.MaximumSpeed = ((DoubleValue)atts.attributes["MaximumSpeed"]).value;
                }
                if (atts.attributes.ContainsKey("DestinationLocation"))
                {
                    this.DestinationLocation = ((LocationValue)atts.attributes["DestinationLocation"]);
                }
                if (atts.attributes.ContainsKey("TeamName"))
                {
                    this.TeamName = ((StringValue)atts.attributes["TeamName"]).value;
                }
                if (atts.attributes.ContainsKey("OwnerID"))
                {
                    this.Owner = ((StringValue)atts.attributes["OwnerID"]).value;
                }
                if (atts.attributes.ContainsKey("Heading"))
                {
                    this.Heading = ((DoubleValue)atts.attributes["Heading"]).value;
                }
                if (atts.attributes.ContainsKey("ObjectName"))
                {
                    this.ObjectName = ((StringValue)atts.attributes["ObjectName"]).value;
                }
            }
Ejemplo n.º 9
0
        /// <summary>
        /// This method goes through each sensor network roster, and generates the networks' best views.
        /// </summary>
        /// <param name="sensorNetworkViews"></param>
        /// <param name="allObjectViews"></param>
        private void RetrieveSensorNetworkView(ref Dictionary <string, Dictionary <string, AttributeCollectionValue> > sensorNetworkViews,
                                               ref Dictionary <string, Dictionary <string, AttributeCollectionValue> > allObjectViews)
        {
            Dictionary <string, AttributeCollectionValue> singleSensorNetworkView;
            string userID;

            foreach (KeyValuePair <string, List <string> > sensorNetworks in networkRosters)
            {
                singleSensorNetworkView = new Dictionary <string, AttributeCollectionValue>();
                foreach (string snMemeber in sensorNetworks.Value)
                {
                    userID = snMemeber;
                    //if(dmViews.ContainsKey(userID))
                    if (dmOwnedObjects.ContainsKey(userID))
                    {
                        //foreach(string objectsID in dmViews[userID].GetObjectKeys())
                        foreach (string objectsID in dmOwnedObjects[userID])
                        {
                            if (allObjectViews.ContainsKey(objectsID))
                            {
                                if (allObjectViews[objectsID].Count == 0)
                                {//This occurs when the object has no changes in its view.
                                    if (!singleSensorNetworkView.ContainsKey(objectsID))
                                    {
                                        singleSensorNetworkView.Add(objectsID, new AttributeCollectionValue());
                                    }
                                    //MergeTwoAttributeCollections(ref singleSensorNetworkView[objectsID], new AttributeCollectionValue());
                                }
                                else
                                if (allObjectViews[objectsID].Count > 0)
                                {
                                    foreach (KeyValuePair <string, AttributeCollectionValue> objectView in allObjectViews[objectsID])
                                    {
                                        if (singleSensorNetworkView.ContainsKey(objectView.Key))
                                        {
                                            AttributeCollectionValue tempACV = singleSensorNetworkView[objectView.Key];
                                            MergeTwoAttributeCollections(ref tempACV, objectView.Value);
                                        }
                                        else
                                        {
                                            singleSensorNetworkView.Add(objectView.Key, objectView.Value);
                                        }
                                    }
                                }
                            }
                        }
                    }
                } //end foreach member
                sensorNetworkViews.Add(sensorNetworks.Key, singleSensorNetworkView);
            }     //end foreach network
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Given a detected value and an attribute collection, the detected value will be added to the collection only
 /// if the attribute is already not-existant within the collection, or if its confidence is higher.
 /// </summary>
 /// <param name="ACV"></param>
 /// <param name="attributeName"></param>
 /// <param name="dav"></param>
 private void AddAttributeToACV(ref AttributeCollectionValue ACV, string attributeName, DetectedAttributeValue dav)
 {
     if (ACV.attributes.ContainsKey(attributeName))
     {
         if (((DetectedAttributeValue)dav).stdDev > ((DetectedAttributeValue)ACV[attributeName]).stdDev)
         {
             ACV[attributeName] = dav;
         }
     }
     else
     {
         ACV.attributes.Add(attributeName, dav);
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// This method retrieves all sensable attributes from the target proxy into the referenced attribute collection value.
        /// </summary>
        /// <param name="ACV">Current collection to add attributes into.</param>
        /// <param name="targetProxy">SimulationProxy to retrieve attributes from.</param>
        private void SenseAllAttributes(ref AttributeCollectionValue singleObjectACV, SimulationObjectProxy targetProxy)
        {
            //for the target object, go through each observable attribute, and add to the view with full confidence.
            string targetObjectID = ((StringValue)targetProxy["ID"].GetDataValue()).value;
            string objectType     = targetProxy.GetObjectType();
            DetectedAttributeValue dav;
            List <string>          keys = targetProxy.GetKeys();

            foreach (string att in simModel.objectModel.objects[objectType].attributes.Keys)
            {
                if (simModel.objectModel.objects[objectType].attributes[att].otherObservable)
                {
                    if (keys.Contains(att))
                    {
                        dav = new DetectedAttributeValue();

                        if (att == "CustomAttributes")
                        {
                            DataValue t = targetProxy[att].GetDataValue();
                            if (t.dataType == "CustomAttributesType")
                            {
                                Dictionary <string, DataValue> copiedDict = CopyFromCustomAttributes(((CustomAttributesValue)t).attributes);
                                t = new CustomAttributesValue();
                                ((CustomAttributesValue)t).attributes = copiedDict;
                            }

                            dav        = new DetectedAttributeValue();
                            dav.stdDev = 100;
                            dav.value  = DataValueFactory.BuildFromDataValue(t);
                            //AddAttributeToACV(ref singleAttributeCollection, simModelAtt.Key, detectedAttribute);
                        }
                        else
                        {
                            dav.value  = DataValueFactory.BuildFromDataValue(targetProxy[att].GetDataValue());
                            dav.stdDev = 100;
                        }
                        if (((AttributeCollectionValue)singleObjectACV).attributes.ContainsKey(att))
                        {
                            ((AttributeCollectionValue)singleObjectACV)[att] = dav;
                        }
                        else
                        {
                            ((AttributeCollectionValue)singleObjectACV).attributes.Add(att, dav);
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// This method takes the sensor network views, and finds each DM's best view.
        /// </summary>
        /// <param name="dmViews"></param>
        /// <param name="sensorNetworkViews"></param>
        private void RetrieveAllDMViews(ref Dictionary <string, Dictionary <string, AttributeCollectionValue> > allDmViews,
                                        ref Dictionary <string, Dictionary <string, AttributeCollectionValue> > sensorNetworkViews)
        {
            string userID;
            Dictionary <string, AttributeCollectionValue> singleDMView;

            foreach (KeyValuePair <string, List <string> > networks in networkRosters)
            {
                foreach (string dmName in networks.Value)
                {
                    userID       = dmName;
                    singleDMView = new Dictionary <string, AttributeCollectionValue>();

                    foreach (string objectID in sensorNetworkViews[networks.Key].Keys)
                    {
                        if (singleDMView.ContainsKey(objectID))
                        {
                            AttributeCollectionValue tempACV = singleDMView[objectID];
                            MergeTwoAttributeCollections(ref tempACV, sensorNetworkViews[networks.Key][objectID]);
                        }
                        else
                        {
                            singleDMView.Add(objectID, sensorNetworkViews[networks.Key][objectID]);
                        }
                    }

                    if (allDmViews.ContainsKey(userID))
                    {//need to merge
                        foreach (string objectID in singleDMView.Keys)
                        {
                            if (allDmViews[userID].ContainsKey(objectID))
                            {
                                AttributeCollectionValue tempACV = allDmViews[userID][objectID];
                                MergeTwoAttributeCollections(ref tempACV, singleDMView[objectID]);
                            }
                            else
                            {
                                allDmViews[userID].Add(objectID, singleDMView[objectID]);
                            }
                        }
                    }
                    else
                    {
                        allDmViews.Add(userID, singleDMView);
                    }
                } //end foreach member
            }     //end foreach network
        }
Ejemplo n.º 13
0
        /// <summary>
        /// This method takes in the updated attribute collection value for a specified object,
        /// and each attribute in the collection that differs from the pre-existing attribute value.
        /// New attributes that did not exist before and modified attributes are added to an ACV which
        /// is returned as a collection of modified attributes.
        /// </summary>
        /// <param name="objectID">The unique object identifier of the object.</param>
        /// <param name="ACV">The collection of updated attributes for the specified object.</param>
        /// <returns>AttributeCollectionValue: Returns a collection of attributes that were not in
        /// or were different from pre-existing attributes in this object.</returns>
        public AttributeCollectionValue UpdateObject(string objectID, AttributeCollectionValue ACV)
        {
            AttributeCollectionValue returnACV = new AttributeCollectionValue();
            DataValue dv1;
            DataValue dv2;

            if (!objectsList.ContainsKey(objectID))
            {
                objectsList.Add(objectID, new AttributeCollectionValue());
            }
            foreach (KeyValuePair <string, DataValue> kvp in ACV.attributes)
            {
                if (objectsList[objectID].attributes.ContainsKey(kvp.Key))
                {//this object already contains the attribute
                    dv1 = GetNestedDataValue(objectsList[objectID][kvp.Key]);
                    dv2 = GetNestedDataValue(ACV[kvp.Key]);
                    if (DataValueFactory.CompareDataValues(dv1, dv2) == true)
                    {
                        //no change required
                    }
                    else
                    {//Need to update data, add to return ACV.
                        objectsList[objectID][kvp.Key] = ACV[kvp.Key];
                        returnACV.attributes.Add(kvp.Key, kvp.Value);
                    }
                }
                else
                { //this object does not already contain the attribute
                    objectsList[objectID].attributes.Add(kvp.Key, kvp.Value);
                    returnACV.attributes.Add(kvp.Key, kvp.Value);
                }
            }

            if (returnACV.attributes.Count == 0)
            {
                return(null);
            }
            //returned objects need ID and OwnerID passed.
            if (!returnACV.attributes.ContainsKey("ID"))
            {
                returnACV.attributes.Add("ID", ACV["ID"]);
            }
            if (!returnACV.attributes.ContainsKey("OwnerID"))
            {
                returnACV.attributes.Add("OwnerID", ACV["OwnerID"]);
            }
            return(returnACV);
        }
Ejemplo n.º 14
0
        protected void MoveObject(SimulationEvent ev)
        { //ObjectID, DestinationLocation, Throttle,
            String id = ((StringValue)ev["ObjectID"]).value;

            if (!_revealedObjects.ContainsKey(id))
            {
                return;
            }
            AttributeCollectionValue atts = new AttributeCollectionValue();

            atts.attributes.Add("DestinationLocation", ev["DestinationLocation"]);
            atts.attributes.Add("Throttle", ev["Throttle"]);

            //LocationValue destLoc =  as LocationValue;
            _revealedObjects[id].SetAttributes(atts);
        }
Ejemplo n.º 15
0
        private void NewObject(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies(); // update my objects record

            string id   = ((StringValue)e["ID"]).value;
            string type = ((StringValue)e["ObjectType"]).value;

            if (objectProxies == null)
            {
                objectProxies = new Dictionary <string, SimulationObjectProxy>();
            }
            SimulationObjectProxy prox = bbClient.GetObjectProxy(id);

            if (prox == null)
            {
                return;
            }
            if (!objectProxies.ContainsKey(id))
            {
                objectProxies.Add(id, prox);
            }
            else
            {
                objectProxies[id] = prox;
            }

            AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"];

            if (e["ID"] != null)
            {
                string id2 = ((StringValue)e["ID"]).value;
                if (objectProxies.ContainsKey(id2))
                {
                    SimulationObjectProxy proxi = objectProxies[id2];

                    // initialize any object values I own.

                    foreach (string attname in atts.attributes.Keys)
                    {
                        if (proxi.GetKeys().Contains(attname) && proxi[attname].IsOwner())
                        {
                            proxi[attname].SetDataValue(atts[attname]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Given two attribute collections, they will merge into one based on confidence values.
 /// </summary>
 /// <param name="startingACV"></param>
 /// <param name="incomingACV"></param>
 private void MergeTwoAttributeCollections(ref AttributeCollectionValue startingACV, AttributeCollectionValue incomingACV)
 {
     foreach (string attName in incomingACV.attributes.Keys)
     {
         if (startingACV.attributes.ContainsKey(attName))
         {
             if (((DetectedAttributeValue)startingACV[attName]).stdDev < ((DetectedAttributeValue)incomingACV[attName]).stdDev)
             {
                 startingACV[attName] = incomingACV[attName];
             }
         }
         else
         { //add attribute
             startingACV.attributes.Add(attName, incomingACV[attName]);
         }
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Given an attribute collection containing DetectedValues, this method will strip the
        /// detected value wrapper from the data values, and return the nested DV's.  This will
        /// NOT return any non-DetectedValue entries.
        /// </summary>
        /// <param name="ACV"></param>
        /// <returns></returns>
        private AttributeCollectionValue ExtractDetectedValuesFromACV(AttributeCollectionValue ACV)
        {
            AttributeCollectionValue returnACV = new AttributeCollectionValue();

            foreach (KeyValuePair <string, DataValue> kvp in ACV.attributes)
            {
                if (kvp.Value is DetectedAttributeValue)
                {
                    returnACV.attributes.Add(kvp.Key, ((DetectedAttributeValue)kvp.Value).value);
                }
                else if (!(kvp.Value is DetectedAttributeValue))
                {
                    returnACV.attributes.Add(kvp.Key, kvp.Value);
                }
            }
            return(returnACV);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// Called by the GUI, updates attributes for a specified object without returning a new ACV, or
 /// creating more memory objects.
 /// </summary>
 /// <param name="ACV"></param>
 /// <param name="objectID"></param>
 public void UpdateObjectsAttributes(ref AttributeCollectionValue ACV, string objectID)
 {
     if (!objectsList.ContainsKey(objectID))
     {
         objectsList.Add(objectID, new AttributeCollectionValue());
     }
     foreach (KeyValuePair <string, DataValue> kvp in ACV.attributes)
     {
         if (objectsList[objectID].attributes.ContainsKey(kvp.Key))
         {//this object already contains the attribute
             objectsList[objectID][kvp.Key] = ACV[kvp.Key];
         }
         else
         { //this object does not already contain the attribute
             objectsList[objectID].attributes.Add(kvp.Key, kvp.Value);
         }
     }
 }
Ejemplo n.º 19
0
        private void ViewProAttributeUpdate(SimulationEvent ev)
        {//TargetPlayer, ObjectID, Attributes
            //if Tracked asset, update attributes
            if (((StringValue)ev["TargetPlayer"]).value != MyDM)
            {
                return;
            }
            String objectID = ((StringValue)ev["ObjectID"]).value;
            //if (!IsBeingTracked(objectID))
            //    return;

            DDDObj d = GetFromAllObjects(objectID);

            if (d == null)
            {
                return;
            }
            AttributeCollectionValue acv = ev["Attributes"] as AttributeCollectionValue;

            if (acv.attributes.ContainsKey("ObjectName"))
            {
                if (((StringValue)acv["ObjectName"]).value != "")
                {
                    d.Name = ((StringValue)acv["ObjectName"]).value;
                }
            }
            if (acv.attributes.ContainsKey("ClassName"))
            {
                d.Type = ((StringValue)acv["ClassName"]).value;
            }
            if (acv.attributes.ContainsKey("CurrentClassification"))
            {
                d.Classification = ((StringValue)acv["CurrentClassification"]).value;
            }
            if (acv.attributes.ContainsKey("GroundTruthIFF"))
            {
                d.IFF = ((StringValue)acv["GroundTruthIFF"]).value;
            }
            if (IsBeingTracked(objectID))
            {
                RefreshTrackInfo();
            }
        }
Ejemplo n.º 20
0
        private RangeRingLevels selectedRangeRingLevel = RangeRingLevels.FULL; //DEFAULT
        #endregion

        #region sensory methods

        /// <summary>
        /// This method will run through each object and determine what those objects can sense.
        /// </summary>
        private void CalculateSensoryAlgorithm()
        {
            //objectProxies = bbClient.GetObjectProxies();
            Dictionary <string, Dictionary <string, AttributeCollectionValue> > allObjectsViews        = new Dictionary <string, Dictionary <string, AttributeCollectionValue> >();
            Dictionary <string, Dictionary <string, AttributeCollectionValue> > allSensorNetworksViews = new Dictionary <string, Dictionary <string, AttributeCollectionValue> >();
            Dictionary <string, Dictionary <string, AttributeCollectionValue> > allDMsViews            = new Dictionary <string, Dictionary <string, AttributeCollectionValue> >();

            //each object senses each other object, and the allObjectsViews is populated and returned.
            SenseAllObjects(ref allObjectsViews);

            //each sensor network goes through the views of objects contained within that network, and
            //creates its best view for all its members.
            RetrieveSensorNetworkView(ref allSensorNetworksViews, ref allObjectsViews);

            //Go through each sensor network, and create the best DM view for each active DM.
            RetrieveAllDMViews(ref allDMsViews, ref allSensorNetworksViews);

            //Send out view pro updates.
            List <string> recentlyDiscoveredObjects = new List <string>();
            bool          sendAttUpdate             = true;

            foreach (string dm in dmOwnedObjects.Keys)
            {
                if (!allDMsViews.ContainsKey(dm))
                {
                    continue;
                }
                CompareNewDMViewWithPrevious(dm, allDMsViews[dm], ref recentlyDiscoveredObjects);
            }
            foreach (string obj in recentlyDiscoveredObjects)
            {
                if (!movingObjects.Contains(obj))
                {
                    continue;
                }
                AttributeCollectionValue atts = new AttributeCollectionValue();
                atts.attributes.Add("ObjectID", DataValueFactory.BuildString(obj));
                SendViewProMotionUpdate(atts);
            }
        }
Ejemplo n.º 21
0
        private void ProcessRegion(SimulationEvent ev)
        {
            String id = ((StringValue)ev["ID"]).value;
            AttributeCollectionValue atts = ((AttributeCollectionValue)ev["Attributes"]);
            PolygonValue             pv   = atts.attributes["Polygon"] as PolygonValue;

            if (atts.attributes.ContainsKey("CurrentAbsolutePolygon"))
            {
                pv = atts["CurrentAbsolutePolygon"] as PolygonValue;
            }
            if (id.StartsWith("SeaLane-"))
            {
                if (!_seaLanes.ContainsKey(id))
                {
                    _seaLanes.Add(id, pv);
                }
                else
                {
                    _seaLanes[id] = pv;
                }
            }
            else if (id.StartsWith("Entry-"))
            {
                if (!_entryPoints.ContainsKey(id))
                {
                    _entryPoints.Add(id, pv);
                }
                else
                {
                    _entryPoints[id] = pv;
                }
            }
            else if (id.StartsWith("AO-"))
            {
                //AO's handled differently now
            }
        }
Ejemplo n.º 22
0
        private void ProcessObject(SimulationEvent ev)
        {
            String id                              = ((StringValue)ev["ID"]).value;
            String objectType                      = ((StringValue)((AttributeCollectionValue)ev["Attributes"])["ClassName"]).value;
            AttributeCollectionValue atts          = ev["Attributes"] as AttributeCollectionValue;
            SeamateObject            seamateObject = null;

            if (_unrevealedObjects.ContainsKey(id))
            {
            }
            else
            {
                _unrevealedObjects.Add(id, new SeamateObject(id));
                Console.WriteLine("Added to UnrevealedObjects: " + id);
            }
            _unrevealedObjects[id].SetAttributes(atts);
            if (atts.attributes.ContainsKey("OwnerID"))
            {
                EstablishOwnership(id, ((StringValue)atts.attributes["OwnerID"]).value);
            }
            if (ev.parameters.ContainsKey("StateTable") && !_speciesPossibleStates.ContainsKey(objectType))
            {
                _speciesPossibleStates.Add(objectType, new Dictionary <string, AttributeCollectionValue>());
                StateTableValue          stv             = (StateTableValue)ev["StateTable"];
                AttributeCollectionValue stateAttributes = null;
                foreach (String stateName in stv.states.Keys)
                {
                    stateAttributes = (AttributeCollectionValue)stv[stateName];
                    _speciesPossibleStates[objectType].Add(stateName, new AttributeCollectionValue());
                    foreach (String att in stateAttributes.attributes.Keys)
                    {
                        _speciesPossibleStates[objectType][stateName].attributes.Add(att, DataValueFactory.BuildFromDataValue(stateAttributes[att]));
                    }
                }
            }
        }
Ejemplo n.º 23
0
        private void AttackSucceeded(SimulationEvent e)
        {
            if (objectProxies.Count == 0)
            {
                return; //another weird edge case
            }
            try
            {
                String objectID             = ((StringValue)e["ObjectID"]).value;
                SimulationObjectProxy proxy = objectProxies[objectID];

                String targetID = ((StringValue)e["TargetID"]).value;
                SimulationObjectProxy targetProxy = objectProxies[targetID];

                String transitionState = ((StringValue)e["NewState"]).value;

                // It's a sea vessel if it's not a BAMS or Firescout
                String targetClassName = ((StringValue)targetProxy["ClassName"].GetDataValue()).value;
                if (targetClassName != "BAMS" && targetClassName != "Firescout" && transitionState == "Dead")
                {
                    targetProxy["DestroyedTime"].SetDataValue(DataValueFactory.BuildInteger(time));
                    targetProxy["DestroyedBy"].SetDataValue(DataValueFactory.BuildString(objectID));

                    //AD: TODO Send view pro attribute event for these objects.
                    SimulationEvent          ev  = SimulationEventFactory.BuildEvent(ref simModel, "ViewProAttributeUpdate");
                    AttributeCollectionValue acv = new AttributeCollectionValue();
                    //                  acv.attributes.Add("DestroyedTime", DataValueFactory.BuildDetectedValue(DataValueFactory.BuildInteger(time), 100));
//                    acv.attributes.Add("DestroyedBy", DataValueFactory.BuildDetectedValue(DataValueFactory.BuildString(objectID), 100));
                    acv.attributes.Add("DestroyedTime", DataValueFactory.BuildInteger(time));
                    acv.attributes.Add("DestroyedBy", DataValueFactory.BuildString(objectID));


                    ((StringValue)ev["TargetPlayer"]).value = "BAMS DM";
                    ((StringValue)ev["ObjectID"]).value     = ((StringValue)targetProxy["ID"].GetDataValue()).value;
                    ((StringValue)ev["OwnerID"]).value      = ((StringValue)targetProxy["OwnerID"].GetDataValue()).value;
                    ((IntegerValue)ev["Time"]).value        = time * 1000;
                    ev["Attributes"] = acv;

                    distClient.PutEvent(ev);

                    ((StringValue)ev["TargetPlayer"]).value = "Firescout DM";
                    distClient.PutEvent(ev);
                    ((StringValue)ev["TargetPlayer"]).value = "Individual DM";
                    distClient.PutEvent(ev);
                }

                String targetOwnerID   = ((StringValue)targetProxy["OwnerID"].GetDataValue()).value;
                String attackerOwnerID = ((StringValue)proxy["OwnerID"].GetDataValue()).value;


                if (transitionState == "Dead")
                {
                    //Clear the intent of any other vessel mentioned in target's intent (pursued or pursuee).
                    String targetIntent = ((StringValue)targetProxy["Intent"].GetDataValue()).value;
                    if (targetIntent != "")
                    {
                        String[] intentArray = targetIntent.Split(":".ToCharArray());
                        if (intentArray.Length > 1)
                        {
                            SimulationObjectProxy vesselProxyToClear = objectProxies[intentArray[1]];
                            vesselProxyToClear["Intent"].SetDataValue(DataValueFactory.BuildString(""));
                        }
                    }

                    //IF friendly, increment counter
                    if (!targetOwnerID.ToLower().Contains("pirate"))
                    {
                        IncrementFriendliesLost(1);
                        String attackClassName = ((StringValue)proxy["ClassName"].GetDataValue()).value;
                        if (attackClassName == "BAMS" || attackClassName == "Firescout")
                        {
                            //IF friendly, and attacker was BAMS/FS
                            IncrementFriendliesDestroyedByPlayers(1);
                        }
                    }
                    else
                    {
                        //if hostile increment counter
                        IncrementHostileTargetsDestroyed(1);
                    }
                }
                //if (targetClassName == "BAMS" || targetClassName == "Firescout")
                //{
                //    //if bams/firescout, increment counter
                //    IncrementHitsTakenByAssets(1);
                //}

                if (!attackerOwnerID.Contains("BAMS") && !attackerOwnerID.Contains("Firescout") && !attackerOwnerID.Contains("Individual"))
                {
                    return; //the following section is only for YOUR attacks, so return if its not BAMS or FS
                }
                String attackClass          = ((StringValue)proxy["ClassName"].GetDataValue()).value;
                String targetClassification = "";
                try
                {
                    targetClassification = classifications[targetID];
                }
                catch (Exception exc)
                { }
                if (targetClassification != "Hostile" && (targetClassName != "BAMS" || targetClassName != "Firescout"))
                {
                    //if asset was not classified as hostile, violated ROE
                    IncrementRulesOfEngagementViolations(1);
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// This method takes in a capabilities list, and a docked weapons list, and quantifies the weapons and
        /// combines those results with the capabilities list for a returned "CapabilitiesList", which the
        /// client displays to its user.
        /// </summary>
        /// <param name="atts"></param>
        private void AddCapabilitiesAndWeaponsList(ref AttributeCollectionValue atts)
        {
            List <string>            capabilities         = new List <string>();
            Dictionary <string, int> weaponsAndQuantities = new Dictionary <string, int>();
            string objectID           = ((StringValue)atts["ID"]).value;
            SimulationObjectProxy obj = objectProxies[objectID];
            CapabilityValue       cv;

            if (atts.attributes.ContainsKey("Capability"))
            {
                cv = atts["Capability"] as CapabilityValue;
                // atts.attributes.Remove("Capability");
            }
            else
            {
                cv = obj["Capability"].GetDataValue() as CapabilityValue;
            }
            foreach (CapabilityValue.Effect ef in ((CapabilityValue)cv).effects)
            {
                if (!capabilities.Contains(ef.name))
                {
                    capabilities.Add(ef.name);
                }
            }

            StringListValue       sl;
            SimulationObjectProxy wep;
            string className;

            if (atts.attributes.ContainsKey("DockedWeapons"))
            {
                sl = atts["DockedWeapons"] as StringListValue;
            }
            else
            {
                sl = obj["DockedWeapons"].GetDataValue() as StringListValue;
            }
            foreach (string weapon in sl.strings)
            {
                wep       = objectProxies[weapon];
                className = ((StringValue)wep["ClassName"].GetDataValue()).value;
                if (!weaponsAndQuantities.ContainsKey(className))
                {
                    weaponsAndQuantities.Add(className, 0);
                }
                weaponsAndQuantities[className]++;
            }

            List <string> CapabilitiesAndWeaponsList = new List <string>();

            foreach (string c in capabilities)
            {
                CapabilitiesAndWeaponsList.Add(c);
            }
            foreach (string w in weaponsAndQuantities.Keys)
            {
                CapabilitiesAndWeaponsList.Add(String.Format("{0} ({1}x)", w, weaponsAndQuantities[w]));
            }
            DataValue retDV = DataValueFactory.BuildValue("StringListType");

            ((StringListValue)retDV).strings = CapabilitiesAndWeaponsList;

            atts.attributes.Add("CapabilitiesList", retDV);
        }
Ejemplo n.º 25
0
        internal void ViewProAttributeUpdate(SimulationEvent ev)
        {
            String id = ((StringValue)ev["ObjectID"]).value;

            if (m_allObjects.ContainsKey(id))
            {
                SimObject ob = m_allObjects[id];

                AttributeCollectionValue atts = (AttributeCollectionValue)ev["Attributes"];
                foreach (String attName in atts.attributes.Keys)
                {
                    switch (attName)
                    {
                    case "Location":
                        ob.Location = (LocationValue)atts[attName];
                        m_lastLocationUpdateTime = DateTime.Now;
                        UpdateInActiveRegions(ref ob);
                        break;

                    case "DestinationLocation":
                        ob.DestinationLocation = (LocationValue)atts[attName];
                        break;

                    case "Velocity":
                        ob.Velocity = (VelocityValue)atts[attName];
                        break;

                    case "ClassName":
                        ob.ClassName = ((StringValue)atts[attName]).value;
                        break;

                    case "Heading":
                        ob.CurrentHeading = ((DoubleValue)atts[attName]).value;
                        break;

                    case "MaximumSpeed":
                        ob.MaximumSpeed = ((DoubleValue)atts[attName]).value;
                        break;

                    case "Throttle":
                        ob.Throttle = ((DoubleValue)atts[attName]).value;
                        break;

                    case "OwnerID":
                        String newOwner = ((StringValue)atts[attName]).value;
                        if (newOwner != ob.Owner)
                        {
                            ob.Owner = newOwner;
                        }
                        break;

                    case "IconName":
                        ob.IconName = ((StringValue)atts[attName]).value;
                        break;

                    case "VulnerabilityList":
                        ob.VulnerabilityList = ((StringListValue)atts[attName]).strings;
                        break;

                    case "CapabilitiesList":
                        ob.CapabilityList = ((StringListValue)atts[attName]).strings;
                        break;

                    case "DockedObjects":
                        ob.DockedObjects = ((StringListValue)atts[attName]).strings;
                        if (ob.DockedObjects.Contains("Dock To Parent"))
                        {
                            ob.DockedObjects.Remove("Dock To Parent");
                        }
                        break;

                    case "DockedWeapons":
                        ob.DockedWeapons = ((StringListValue)atts[attName]).strings;
                        break;

                    case "State":
                        ob.State = ((StringValue)atts[attName]).value;
                        break;

                    case "CustomAttributes":
                        ob.CustomAttributes = (CustomAttributesValue)atts[attName];
                        break;

                    case "Capability":
                        ob.Capabilities = (CapabilityValue)atts[attName];
                        break;

                    case "Vulnerability":
                        ob.Vulnerabilities = (VulnerabilityValue)atts[attName];
                        break;

                    case "CapabilityRangeRings":
                        ob.CapabilityRangeRings = (CustomAttributesValue)atts[attName];
                        break;

                    case "VulnerabilityRangeRings":
                        ob.VulnerabilityRangeRings = (CustomAttributesValue)atts[attName];
                        break;

                    case "IsWeapon":
                        ob.IsWeapon = ((BooleanValue)atts[attName]).value;
                        break;

                    case "TeamName":
                        ob.TeamName = ((StringValue)atts[attName]).value;
                        break;

                    case "FuelConsumptionRate":
                        ob.FuelConsumptionRate = ((DoubleValue)atts[attName]).value;
                        break;

                    case "FuelAmount":
                        ob.FuelAmount = ((DoubleValue)atts[attName]).value;
                        break;

                    case "FuelCapacity":
                        ob.FuelCapacity = ((DoubleValue)atts[attName]).value;
                        break;

                    case "Sensors":
                        ob.Sensors = (SensorArrayValue)atts[attName];
                        break;

                    case "ChildObjects":
                        ob.ChildObjects = ((StringListValue)atts[attName]).strings;
                        break;

                    case "DockedToParent":
                        ob.DockedToParent = ((BooleanValue)atts[attName]).value;
                        break;

                    case "ParentObjectID":
                        ob.ParentObjectID = ((StringValue)atts[attName]).value;
                        break;

                    default:
                        //Console.WriteLine(String.Format("ViewProAttributeUpdate:{0} unsupported",attName));
                        break;
                    }
                }
            }
            if (PlayerAgent != null)
            {
                PlayerAgent.ViewProAttributeUpdate(ev);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Similar to CalculateRangeRings, this is done with ABSOLUTE data, not detected values.
        /// This method is called in a ViewProAttributeUpdate call, which only contains attributes
        /// which have CHANGED, and will determine if either the sensors, vulnerabilties, or capabilities (including docked weapons) has
        /// changed.  If so, then new attributes will be added to the attribute collection value.
        /// </summary>
        /// <param name="acv"></param>
        /// <param name="fullObjectView"></param>
        /// <returns></returns>
        private void AddRangeRings(ref AttributeCollectionValue acv, ref SimulationObjectProxy fullObjectView)
        {
            if (acv.attributes.ContainsKey("Sensors"))
            {
                //detected contains a sensor array type
                CustomAttributesValue sensorCollection = DataValueFactory.BuildCustomAttributes(new Dictionary <string, DataValue>()) as CustomAttributesValue;
                RangeRingDisplayValue sensorRing;
                SensorArrayValue      detectedSensors = acv["Sensors"] as SensorArrayValue;

                foreach (SensorValue sv in detectedSensors.sensors)
                {
                    sensorRing = DataValueFactory.BuildRangeRingDisplayValue(sv.sensorName, "Sensors", false, new Dictionary <int, int>()) as RangeRingDisplayValue;
                    sensorRing.rangeIntensities.Add(Convert.ToInt32(sv.maxRange), -1);

                    sensorCollection.attributes.Add(sv.sensorName, sensorRing);
                }

                if (sensorCollection.attributes.Count > 0)
                {
                    acv.attributes.Add("SensorRangeRings", sensorCollection);
                }
                else
                {
                    Console.WriteLine("No SensorRangeRings added to ACV");
                }
            }
            if (acv.attributes.ContainsKey("Vulnerability"))
            {
                //gets detected values, containing a vulnerability type
                CustomAttributesValue    vulnerabilityCollection = DataValueFactory.BuildCustomAttributes(new Dictionary <string, DataValue>()) as CustomAttributesValue;
                RangeRingDisplayValue    vulnerabilityRing;
                VulnerabilityValue       detectedVulnerability = acv["Vulnerability"] as VulnerabilityValue;
                Dictionary <string, int> longestRange          = new Dictionary <string, int>();//[Capability],[Range]

                foreach (VulnerabilityValue.Transition tr in detectedVulnerability.transitions)
                {
                    foreach (VulnerabilityValue.TransitionCondition tc in tr.conditions)
                    {
                        if (!longestRange.ContainsKey(tc.capability))
                        {
                            longestRange.Add(tc.capability, -1);
                        }
                        if (longestRange[tc.capability] < Convert.ToInt32(tc.range))
                        {
                            longestRange[tc.capability] = Convert.ToInt32(tc.range);
                        }
                    }
                }

                foreach (KeyValuePair <string, int> kvp in longestRange)
                {
                    vulnerabilityRing = DataValueFactory.BuildRangeRingDisplayValue(kvp.Key, "Vulnerability", false, new Dictionary <int, int>()) as RangeRingDisplayValue;
                    vulnerabilityRing.rangeIntensities.Add(kvp.Value, -1);

                    vulnerabilityCollection.attributes.Add(kvp.Key, vulnerabilityRing);
                }


                if (vulnerabilityCollection.attributes.Count > 0)
                {
                    acv.attributes.Add("VulnerabilityRangeRings", vulnerabilityCollection);
                }
                else
                {
                    Console.WriteLine("No VulnerabilityRangeRings added to ACV");
                }
            }
            if (acv.attributes.ContainsKey("Capability") || acv.attributes.ContainsKey("DockedWeapons"))
            {
                CustomAttributesValue capabilityCollection = DataValueFactory.BuildCustomAttributes(new Dictionary <string, DataValue>()) as CustomAttributesValue;
                RangeRingDisplayValue capabilityRing;

                Dictionary <string, int> longestWeaponRange = new Dictionary <string, int>();//[Capability],[Range]


                //docked weapons gets string list of IDs
                if (acv.attributes.ContainsKey("DockedWeapons"))
                {
                    StringListValue dockedWeapons = acv["DockedWeapons"] as StringListValue;
                    foreach (String weaponID in dockedWeapons.strings)
                    {
                        //get weapon id
                        //get proxy info for weapon
                        SimulationObjectProxy weapon = objectProxies[weaponID];
                        string species = ((StringValue)weapon["ClassName"].GetDataValue()).value;
                        if (longestWeaponRange.ContainsKey(species))
                        {
                            continue;
                            //For now, assume that all weapons of the same species type have the same ranges.
                            //this will cut back on unneccessary loops, and for the most part is 100% true.
                        }

//get max speed, maxfuel or current fuel, get fuel consumption rate, get SHORTEST capability range
                        double maxSpeed             = ((DoubleValue)weapon["MaximumSpeed"].GetDataValue()).value;
                        double maxFuel              = ((DoubleValue)weapon["FuelCapacity"].GetDataValue()).value;
                        double fuelConsumptionRate  = ((DoubleValue)weapon["FuelConsumptionRate"].GetDataValue()).value;
                        double shortCapabilityRange = -1;

                        CapabilityValue             weaponCV  = (CapabilityValue)weapon["Capability"].GetDataValue();
                        Dictionary <string, double> capRanges = new Dictionary <string, double>();

                        foreach (CapabilityValue.Effect ef in weaponCV.effects)
                        {
                            if (!capRanges.ContainsKey(ef.name))
                            {
                                capRanges.Add(ef.name, ef.range);
                            }
                            else
                            {
                                if (capRanges[ef.name] > ef.range)
                                {//You want the smaller range here because that's how weapons work.  Auto-attacks use the SHORTEST range to trigger.
                                    capRanges[ef.name] = ef.range;
                                }
                            }
                        }
                        //but here, you want the LONGEST of the ranges that could trigger an auto-attack.
                        foreach (KeyValuePair <string, double> kvp in capRanges)
                        {
                            if (kvp.Value > shortCapabilityRange)
                            {
                                shortCapabilityRange = kvp.Value;
                            }
                        }

                        double thisRange = maxSpeed * maxFuel * fuelConsumptionRate + shortCapabilityRange;
                        longestWeaponRange.Add(species, Convert.ToInt32(thisRange));
                    }
                    //
                }

                Dictionary <string, Dictionary <double, double> > capabilityRanges = new Dictionary <string, Dictionary <double, double> >();
                if (acv.attributes.ContainsKey("Capability"))
                {
                    CapabilityValue detectedCapability = acv["Capability"] as CapabilityValue;


                    foreach (CapabilityValue.Effect ef in detectedCapability.effects)
                    {
                        if (!capabilityRanges.ContainsKey(ef.name))
                        {
                            capabilityRanges.Add(ef.name, new Dictionary <double, double>());
                        }

                        capabilityRanges[ef.name].Add(ef.range, ef.intensity);
                    }
                }

                //add all capabilities to ring collection
                foreach (string capName in capabilityRanges.Keys)
                {
                    if (!capabilityCollection.attributes.ContainsKey(capName))
                    {
                        capabilityRing = DataValueFactory.BuildRangeRingDisplayValue(capName, "Capability", false, new Dictionary <int, int>()) as RangeRingDisplayValue;
                        Dictionary <int, int> convertedRanges = new Dictionary <int, int>();
                        foreach (KeyValuePair <double, double> kvp in capabilityRanges[capName])
                        {
                            convertedRanges.Add(Convert.ToInt32(kvp.Key), Convert.ToInt32(kvp.Value));
                        }
                        capabilityRing.AddAndSortRanges(convertedRanges); //this sorts as well

                        capabilityCollection.attributes.Add(capName, capabilityRing);
                    }
                    else
                    {
                        Console.WriteLine("Failed to add duplicate capability to collection, {0}", capName);
                    }
                }

                foreach (string weaponSpeciesName in longestWeaponRange.Keys)
                {
                    if (!capabilityCollection.attributes.ContainsKey(weaponSpeciesName))
                    {
                        capabilityRing = DataValueFactory.BuildRangeRingDisplayValue(weaponSpeciesName, "Capability", true, new Dictionary <int, int>()) as RangeRingDisplayValue;
                        capabilityRing.rangeIntensities.Add(longestWeaponRange[weaponSpeciesName], -1); //TODO: Maybe add intensity above?
                        capabilityCollection.attributes.Add(weaponSpeciesName, capabilityRing);
                    }
                    else
                    {
                        Console.WriteLine("Failed to add duplicate capability(Weapon species) to collection, {0}", weaponSpeciesName);
                    }
                }

                if (capabilityCollection.attributes.Count > 0)
                {
                    acv.attributes.Add("CapabilityRangeRings", capabilityCollection);
                }
                else
                {
                    Console.WriteLine("No CapabilityRangeRings added to ACV");
                }
            }
        }
Ejemplo n.º 27
0
        private void NewObject(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies(); // update my objects record

            string id   = ((StringValue)e["ID"]).value;
            string type = ((StringValue)e["ObjectType"]).value;

            if (objectProxies == null)
            {
                objectProxies = new Dictionary <string, SimulationObjectProxy>();
            }
            SimulationObjectProxy prox = bbClient.GetObjectProxy(id);

            if (prox == null)
            {
                return;
            }
            if (!objectProxies.ContainsKey(id))
            {
                objectProxies.Add(id, prox);
            }
            else
            {
                objectProxies[id] = prox;
            }

            AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"];

            string id2 = ((StringValue)e["ID"]).value;
            SimulationObjectProxy proxi = objectProxies[id2];

            if (proxi.GetKeys().Contains("StateTable"))
            {
                proxi["StateTable"].SetDataValue(e["StateTable"]);
            }


            if (objectProxies.ContainsKey(id2))
            {
                // initialize any object values I own.

                foreach (string attname in atts.attributes.Keys)
                {
                    if (proxi.GetKeys().Contains(attname) && proxi[attname].IsOwner())
                    {
                        proxi[attname].SetDataValue(atts[attname]);
                        if (attname == "Sensors")
                        {
                            double           maxSensor = -1.0;
                            SensorArrayValue sav       = atts[attname] as SensorArrayValue;
                            foreach (SensorValue sv in sav.sensors)
                            {
                                maxSensor = Math.Max(maxSensor, sv.maxRange);
                            }
                            if (maxSensor >= 0)
                            {
                                ObjectDistances.UpdateObjectSensorRange(id2, maxSensor);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 28
0
        private void CompareNewDMViewWithPrevious(string dm, Dictionary <string, AttributeCollectionValue> singleDMView, ref List <string> recentDiscoveries)
        {
            if (!dmViews.ContainsKey(dm))
            {
                return;
            }
            ObjectsAttributeCollection prevDMView     = dmViews[dm];
            List <string> objectsToRemove             = new List <string>();
            List <string> objectsToAdd                = new List <string>();
            List <string> previouslyNotVisibleObjects = new List <string>();

            foreach (string obj in prevDMView.GetObjectKeys())
            {
                if (!singleDMView.ContainsKey(obj))
                {
                    objectsToRemove.Add(obj);
                }
                if (prevDMView[obj].attributes.ContainsKey("Location"))
                {
                    if (!((LocationValue)((DetectedAttributeValue)prevDMView[obj]["Location"]).value).exists)
                    {
                        previouslyNotVisibleObjects.Add(obj);
                    }
                }
            }
            foreach (string obj in singleDMView.Keys)
            {
                if (!prevDMView.ContainsObject(obj) && singleDMView[obj].attributes.ContainsKey("Location"))
                {
                    objectsToAdd.Add(obj);
                }
            }
            AttributeCollectionValue acv = new AttributeCollectionValue();

            //acv.attributes.Add("ID", new StringValue() as DataValue);
            foreach (string obj in objectsToAdd.ToArray())
            {
                //
                acv = singleDMView[obj]; //singleDMView stores DetectedValues, which need to be
                //stripped before sending to SendVPIO
                if (acv.attributes.ContainsKey("Location"))
                {
                    if (!((LocationValue)((DetectedAttributeValue)acv["Location"]).value).exists)
                    {
                        objectsToRemove.Add(obj);
                        objectsToAdd.Remove(obj);
                        continue;
                    }
                    else
                    {
                        //if (!previouslyNotVisibleObjects.Contains(obj))
                        //    continue;
                        //objectsToAdd.Add(obj);
                        //objectsToRemove.Remove(obj);
                    }
                }
                if (!acv.attributes.ContainsKey("ID"))
                {
                    acv["ID"] = DataValueFactory.BuildDetectedValue(DataValueFactory.BuildString(obj), 100);
                }
                if (!acv.attributes.ContainsKey("OwnerID"))
                {
                    acv["OwnerID"] = DataValueFactory.BuildDetectedValue(objectProxies[obj]["OwnerID"].GetDataValue(), 100);
                }
                SendViewProInitializeObject(dm, ExtractDetectedValuesFromACV(acv));
            }

            foreach (string obj in objectsToRemove)
            {
                SendRemoveObjectEvent(obj, dm);
                prevDMView.RemoveObject(obj);
            }

            bool anyAttributeChanged = false;

            acv = null;

            foreach (string obj in objectsToAdd)
            {
                //AttributeCollectionValue atts = new AttributeCollectionValue(); //prevDMView.UpdateObject(obj, singleDMView[obj]);
                //SendViewProAttributeUpdate(dm, atts);
                prevDMView.UpdateObject(obj, new AttributeCollectionValue());
                if (!movingObjects.Contains(obj))
                {
                    continue;
                }
                if (!activeDMs.Contains(dm))
                {
                    continue;
                }
                if (!recentDiscoveries.Contains(obj))
                {
                    recentDiscoveries.Add(obj);
                }
                //atts["ObjectID"] = DataValueFactory.BuildString(obj);//this is needed as the
                //                                                     //above Update call will
                //                                                     //add "ID", not "ObjectID"
                //SendViewProMotionUpdate(atts);
            }
            foreach (string obj in prevDMView.GetObjectKeys())
            {
                acv = prevDMView.UpdateObject(obj, singleDMView[obj]);
                //add recent tags
                if (recentUnitTags != null)
                {
                    if (recentUnitTags.ContainsKey(obj))
                    {
                        if (recentUnitTags[obj].ContainsKey(dm))
                        {
                            if (acv == null)
                            {
                                acv = new AttributeCollectionValue();
                            }
                            acv.attributes["InitialTag"] = DataValueFactory.BuildString(recentUnitTags[obj][dm]);
                            recentUnitTags[obj].Remove(dm); //remove once the DM has been notified.
                            acv.attributes["ID"]      = DataValueFactory.BuildString(obj);
                            acv.attributes["OwnerID"] = prevDMView[obj]["OwnerID"];
                        }
                    }
                }

                String classification = GetChangedClassificationForDM(obj, dm);
                if (classification != null)
                {
                    if (acv == null)
                    {
                        acv = new AttributeCollectionValue();
                        acv.attributes["ID"]      = DataValueFactory.BuildString(obj);
                        acv.attributes["OwnerID"] = prevDMView[obj]["OwnerID"];
                    }
                    acv.attributes["CurrentClassification"] = DataValueFactory.BuildString(classification);
                }

                if (acv == null)
                {
                    continue;
                }
                if (acv.attributes.ContainsKey("Location"))
                {
                    if (((LocationValue)((DetectedAttributeValue)acv["Location"]).value).exists)
                    {
                        //SendViewProInitializeObject(dm, ExtractDetectedValuesFromACV(prevDMView[obj]));
                    }
                }

                SendViewProAttributeUpdate(dm, acv);
                if (acv.attributes.ContainsKey("OwnerID") && acv.attributes.ContainsKey("CurrentAttacks"))
                {
                    if (((StringValue)((DetectedAttributeValue)acv.attributes["OwnerID"]).value).value == dm)
                    {
                        AttackCollectionValue attacks = (AttackCollectionValue)((DetectedAttributeValue)acv.attributes["CurrentAttacks"]).value;
                        foreach (AttackCollectionValue.AttackValue av in attacks.GetCurrentAttacks())
                        {
                            foreach (Attack a in currentAttacks)
                            {
                                if (a.attacker == av.attackingObjectId && a.target == av.targetObjectId && a.capabilityName == av.capabilityName)
                                {
                                    a.SetTimes(av.attackStartTime, av.attackTimeWindow);
                                }
                            }
                        }
                    }
                }
                if (acv.attributes.ContainsKey("DestinationLocation") ||
                    acv.attributes.ContainsKey("Throttle"))
                {
                    if (!recentDiscoveries.Contains(obj))
                    {
                        recentDiscoveries.Add(obj);
                    }
                    //acv["ObjectID"] = acv["ID"];
                    //SendViewProMotionUpdate(ExtractDetectedValuesFromACV(acv));
                }
                acv = null;
            }
        }
Ejemplo n.º 29
0
        private void RevealObject(SimulationEvent e)
        {
            AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"];
            string id = ((StringValue)e["ObjectID"]).value;

            SimulationObjectProxy prox = null;

            prox = GetObjectProxy(id);
            if (prox == null)
            {
                return;
            }

            //Set State info?
            //AD: This is kind of a quick fix.  Gabe would have a better idea on a more permanent
            //solution.
            DataValue stv = new DataValue();

            stv = prox["StateTable"].GetDataValue();
            Dictionary <string, DataValue> tempDict = ((StateTableValue)stv).states;

            tempDict = ((AttributeCollectionValue)tempDict[((StringValue)atts["State"]).value]).attributes;

            foreach (KeyValuePair <String, DataValue> kvp in tempDict)
            {
                if (!atts.attributes.ContainsKey(kvp.Key))
                {//if att exists in atts, it should NOT overwrite reveal attributes.
                    atts.attributes.Add(kvp.Key, kvp.Value);
                }
            }
            ////AD
            foreach (string attname in atts.attributes.Keys)
            {
                if (attname == "ID")
                {
                    continue;
                }
                if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner())
                {
                    prox[attname].SetDataValue(atts[attname]);
                    if (attname == "Sensors")
                    {
                        double           maxSensor = -1.0;
                        SensorArrayValue sav       = atts[attname] as SensorArrayValue;
                        foreach (SensorValue sv in sav.sensors)
                        {
                            maxSensor = Math.Max(maxSensor, sv.maxRange);
                        }
                        if (maxSensor >= 0)
                        {
                            ObjectDistances.UpdateObjectSensorRange(id, maxSensor);
                        }
                    }
                }
            }
            Dictionary <string, DataValue> x = new Dictionary <string, DataValue>();

            EmitterValue em = (EmitterValue)prox["Emitters"].GetDataValue();

            foreach (string attName in em.attIsEngram.Keys)
            {
                if (em.attIsEngram[attName])
                {
                    if (StateDB.engrams.ContainsKey(attName))
                    {
                        x[attName] = DataValueFactory.BuildString(StateDB.engrams[attName].engramValue);
                    }
                }
            }

            prox["CustomAttributes"].SetDataValue(DataValueFactory.BuildCustomAttributes(x));
        }
Ejemplo n.º 30
0
        public void StartListening()
        {
            while (!network.IsConnected())
            {
                Thread.Sleep(100);
            }
            subscribeToEvents();
            isActive = true;
            while (network.IsConnected())
            {// as long as there's a network we remain open to input events
                while (isActive && network.IsConnected())
                {
                    events = network.GetEvents();

                    foreach (SimulationEvent e in events)
                    {
                        switch (e.eventType)
                        {
                        case "RevealObject":
                            if (ScudLauncher.AgentControls(((StringValue)e["ObjectID"]).value))
                            {
                                AttributeCollectionValue attributes = (AttributeCollectionValue)e["Attributes"];
                                LocationValue            locus      = (LocationValue)attributes["Location"];
                                ScudLauncher.AddUnit(((StringValue)e["ObjectID"]).value, locus.X, locus.Y);
                            }
                            else if (Target.IsTarget((((StringValue)e["ObjectID"]).value)))
                            {
                                Target.AddUnit(((StringValue)e["ObjectID"]).value);
                            }

                            break;

                        case "StateChange":
                            if (ScudLauncher.AgentControls(((StringValue)e["ObjectID"]).value))
                            {
                                if ("Dead" == ((StringValue)e["NewState"]).value)
                                {
                                    if (ScudLauncher.AgentControls(((StringValue)e["ObjectID"]).value))
                                    {
                                        if (ScudLauncher.AgentControls(((StringValue)e["ObjectID"]).value))
                                        {
                                            ScudLauncher.DropUnit(((StringValue)e["ObjectID"]).value);
                                        }
                                        else if (Target.IsTarget((((StringValue)e["ObjectID"]).value)))
                                        {
                                            Target.DropUnit(((StringValue)e["ObjectID"]).value);
                                        }
                                    }
                                }
                            }
                            break;

                        /*        case "MoveDone":
                         *          if (ScudLauncher.AgentControls(((StringValue)e["ObjectID"]).value))
                         *              ScudLauncher.GetScudLauncher((((StringValue)e["ObjectID"]).value)).InMotion = false;
                         *
                         *          break;*/
                        case "SimulationTimeEvent":
                            if (0 == ((IntegerValue)e["Time"]).value % 1000)    // only bother with full seconds
                            {
                                ScudLauncher.Tick(((IntegerValue)e["Time"]).value);
                            }
                            break;

                        case "ViewProMotionUpdate":
                            if (ScudLauncher.AgentControls(((StringValue)e["ObjectID"]).value))
                            {
                                string        objectID = ((StringValue)e["ObjectID"]).value;
                                LocationValue locVal   = (LocationValue)e["Location"];
                                Location      current  = new Location(locVal.X, locVal.Y);
                                locVal = (LocationValue)e["DestinationLocation"];
                                Location destination = new Location(locVal.X, locVal.Y);

                                Boolean moving = (current.X != destination.X) || (current.Y != destination.Y);
                                if (moving != ScudLauncher.IsMoving(objectID))
                                {
                                    if (!moving)
                                    {
                                        Console.WriteLine("Updating position of " + objectID + " to (" + destination.X.ToString() + "," + destination.Y.ToString() + ")");
                                        ScudLauncher.SetLocation(objectID, current);
                                    }
                                }
                                ScudLauncher.SetMovement(objectID, moving);
                            }
                            break;
                        }
                    }

                    Thread.Sleep(100);
                }
                if (!network.IsConnected())
                {
                    isActive = false;
                }
            }
            Console.WriteLine("Lost connection.");
            network = null;
        }