Example #1
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;
        }
Example #2
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);
     }
 }
Example #3
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]);
         }
     }
 }
Example #4
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);
            }

        }
Example #5
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;
                }
            }
Example #6
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);
        }
Example #7
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);
        }
Example #8
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));

            if (_revealedObjects.ContainsKey(id))
            {
                SeamateObject ob = _revealedObjects[id];
                String owner = ob.Owner;
                if (isInEntryRegion(ob) && owner == "Merchant DM")
                {
                    Console.WriteLine("Detected vessel " + id + " ending move in entry region, turning state to Dead.");
                    _dddConnection.SendStateChange(id, "Dead");
                }
            }

            _revealedObjects[id].SetAttributes(atts);
        }
Example #9
0
 /// <summary>
 /// Send an ExternalApp_Message event to communicate with another external application.
 /// </summary>
 /// <param name="appName"></param>
 /// <param name="message"></param>
 public void SendExternalAppMessage(String appName, AttributeCollectionValue message)
 {
     SimulationEvent e = SimulationEventFactory.BuildEvent(ref m_simModel, "ExternalApp_Message");
     ((StringValue)(e["AppName"])).value = appName;
     e["Message"] = message;
     m_netClient.PutEvent(e);
 }
Example #10
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");
                }
            }

        }
Example #11
0
        /// <summary>
        /// This is used as a normalizer, in which every client's view is reset to the server's view
        /// for that client.  Foreach object in each player's view, send out a ViewProInitializeObject
        /// event, and then foreach object on the motion list, send out motion updates.
        /// </summary>
        private void ResumeScenario()
        {
            if (initialReplaySpeed != null)
            {
                distClient.PutEvent(initialReplaySpeed);
            }
            else
            {
                SimulationEvent ev = SimulationEventFactory.BuildEvent(ref simModel, "GameSpeed");
                ev["SpeedFactor"] = DataValueFactory.BuildDouble(1); //default speed of 1
                ev["Time"] = DataValueFactory.BuildInteger(currentTick);
                distClient.PutEvent(ev);
            }
            //initialize views:
            foreach (string dm in dmViews.Keys)
            {
                foreach (string objID in dmViews[dm].GetObjectKeys())
                {
                    if (!dmViews[dm][objID].attributes.ContainsKey("Location"))
                    {//if a dm doesn't know an object's location, then that object 
                        //is not visible to the dm.
                        continue;
                    }
                    AttributeCollectionValue acv = new AttributeCollectionValue();
                    acv["ID"] = DataValueFactory.BuildString(objID);
                    SendViewProInitializeObject(dm, acv);

                }
            }

            //send motion updates:
            AttributeCollectionValue tempACV = new AttributeCollectionValue();
            tempACV.attributes.Add("ObjectID", DataValueFactory.BuildString(string.Empty));

            foreach (string objectID in movingObjects)
            {
                tempACV["ObjectID"] = DataValueFactory.BuildString(objectID);
                //SendViewProStopObjectUpdate(objectID);
                SendViewProMotionUpdate(tempACV);
            }

            foreach (StateDB.ActiveRegion reg in StateDB.activeRegions.Values)
            {
               
                SendViewProActiveRegionUpdate(reg.id, reg.isVisible, reg.displayColor, reg.currentAbsolutePolygon);
            }
        }
Example #12
0
        /// <summary>
        /// This method takes in a Create_EventType (ScenCon defined object), and retrieves
        /// the data from the object, packages up the data into a SimulationEvent (SimCore defined
        /// object), and then sends the event to the network server.  This method was pulled out of
        /// the main block of code to simplify sending the event and code readability.
        /// </summary>
        /// <param name="incoming">The Create_EventType object whose data is packaged
        /// into an outgoing SimulationEvent.</param>
        private static void SendCreateEvent(Create_EventType incoming)
        {
            SimulationEvent e = SimulationEventFactory.BuildEvent(ref simModelInfo, "NewObject");
            Dictionary<string, DataValue> myAtt = new Dictionary<string, DataValue>();
            Dictionary<string, object> DictionaryOfStates;
            DataValue dv;
            ObjectInfo myObject;
            string objectType = incoming.Genus.ToString();
            myObject = simModelInfo.objectModel.objects[objectType];
            dv = new StateTableValue();

            try
            {
                e["Time"] = DataValueFactory.BuildInteger(incoming.Time);//ConvertInteger(incoming.Timer);
                e["ObjectType"] = DataValueFactory.BuildString(objectType); //ConvertString(objectType);
                e["ID"] = DataValueFactory.BuildString(incoming.UnitID);//ConvertString(incoming.UnitID);

                /*********** Define the State Table ***********************/
                DictionaryOfStates = incoming.Parameters.GetDictionary();
            }
            catch
            {
                throw new Exception("Missing Required Data for Create Event");
            }
            Dictionary<string, DataValue> SimCoreStateTable = new Dictionary<string, DataValue>();

            foreach (KeyValuePair<string, object> kvp in DictionaryOfStates)
            {
                DataValue capabilities,
                          vulnerabilities,
                          currentSimCoreState;

                capabilities = new CapabilityValue();
                vulnerabilities = new VulnerabilityValue();
                currentSimCoreState = new AttributeCollectionValue();
                ExtendedStateBody currentScenConState = new ExtendedStateBody();

                currentScenConState = (ExtendedStateBody)incoming.Parameters[kvp.Key];

                capabilities = DefineCapabilityValue(currentScenConState.Capabilities);
                ((AttributeCollectionValue)currentSimCoreState).attributes.Add("Capability", capabilities);

                vulnerabilities = DefineVulnerabilityValue(currentScenConState.Vulnerabilities, currentScenConState.Combinations);
                ((AttributeCollectionValue)currentSimCoreState).attributes.Add("Vulnerability", vulnerabilities);

                DataValue sensorArray = DataValueFactory.BuildValue("SensorArrayType");
                DataValue sensor;

                Dictionary<string, SensorType> sensors = new Dictionary<string, SensorType>();

                Dictionary<string, List<ConeValue>> ranges;
                sensors = currentScenConState.Sensors;

                foreach (string sensorKind in sensors.Keys)
                {
                    ranges = new Dictionary<string, List<ConeValue>>();
                    sensor = DataValueFactory.BuildValue("SensorType");
                    SensorType typeOfSensor = sensors[sensorKind];
                    string attributeSensed = typeOfSensor.Attribute;
                    List<Cone> cones = typeOfSensor.Cones;
                    double maxRange = 0.0;

                    ((SensorValue)sensor).attIsEngram[attributeSensed] = sensors[sensorKind].IsEngram;
                    List<ConeValue> simCoreCones = new List<ConeValue>();

                    foreach (Cone aCone in sensors[sensorKind].Cones)
                    {
                        LocationValue direction = new LocationValue();
                        direction.X = aCone.Direction.X;
                        direction.Y = aCone.Direction.Y;
                        direction.Z = aCone.Direction.Z;
                        direction.exists = true;
                        ConeValue cv = new ConeValue();
                        cv.direction = direction;
                        cv.extent = aCone.Extent;
                        if (aCone.Extent > maxRange)
                            maxRange = aCone.Extent;
                        cv.level = aCone.Level;
                        cv.spread = aCone.Spread;
                        simCoreCones.Add(cv);
                    }

                    ranges.Add(attributeSensed, simCoreCones);
                    ((SensorValue)sensor).ranges = ranges;
                    ((SensorValue)sensor).sensorName = sensorKind;
                    if (((SensorValue)sensor).maxRange < maxRange)
                    {
                        ((SensorValue)sensor).maxRange = maxRange;
                    }
                    ((SensorArrayValue)sensorArray).sensors.Add((SensorValue)sensor);
                }


                ((AttributeCollectionValue)currentSimCoreState).attributes.Add("Sensors", sensorArray);

                //Emitters
                DataValue emitter = DataValueFactory.BuildValue("EmitterType");

                Dictionary<string, EmitterType> scenConEmitters = currentScenConState.Emitters;
                EmitterType emission;
                foreach (string s in scenConEmitters.Keys)
                {
                    emission = scenConEmitters[s].DeepCopy();
                    string attributeName = s;
                    ((EmitterValue)emitter).attIsEngram[s] = emission.IsEngram;
                    // string level;
                    //        double variance;
                    Dictionary<string, double> levels = new Dictionary<string, double>();
                    foreach (string level in emission.Levels.Keys)
                    {
                        //           levels.Add(level, (double)(emission[level]));
                        double dublet = Double.Parse((emission.Levels[level].ToString()));
                        levels.Add(level, dublet);
                    }
                    ((EmitterValue)emitter).emitters.Add(attributeName, levels);
                }

                ((AttributeCollectionValue)currentSimCoreState).attributes.Add("Emitters", emitter);

                foreach (AttributeInfo attr in myObject.attributes.Values)
                {
                    string attrType = attr.dataType;
                    string simCoreName = attr.name;
                    string scenConKey = convertSimCoreToScenCon(simCoreName);

                    if (currentScenConState.Parameters.ContainsKey(scenConKey))
                    {
                        switch (attrType)
                        {
                            case "StringType":
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildString(Convert.ToString(currentScenConState.Parameters[scenConKey])));
                                break;/*ConvertString(Convert.ToString(currentScenConState.Parameters[scenConKey])*/

                            case "IntegerType":
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildInteger(Convert.ToInt32(currentScenConState.Parameters[scenConKey])));
                                break;/*ConvertInteger(Convert.ToInt32(currentScenConState.Parameters[scenConKey])*/

                            case "DoubleType":
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildDouble(Convert.ToDouble(currentScenConState.Parameters[scenConKey])));
                                break;/*ConvertDouble(Convert.ToDouble(currentScenConState.Parameters[scenConKey])*/

                            case "LocationType":
                                LocationType lt = currentScenConState.Parameters[scenConKey] as LocationType;
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildLocation(lt.X, lt.Y, lt.Z, false));
                                break;/*ConvertLocation((LocationType)currentScenConState.Parameters[scenConKey])*/

                            case "VelocityType":
                                VelocityType vt = currentScenConState.Parameters[scenConKey] as VelocityType;
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildVelocity(vt.VX, vt.VY, vt.VZ));
                                break;/*ConvertVelocity((VelocityType)currentScenConState.Parameters[scenConKey])*/
                            case "BooleanType":
                                if (currentScenConState.Parameters.ContainsKey(attr.name))
                                {
                                    string booleanVal = currentScenConState.Parameters[attr.name].ToString();
                                    bool value = false;
                                    if (booleanVal == "true" || booleanVal == "True" || booleanVal == "TRUE")
                                    {
                                        value = true;
                                    }
                                    ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildBoolean(value));
                                }/*ConvertBoolean(value)*/
                                break;
                            case "StringListType":
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, DataValueFactory.BuildStringList((List<String>)currentScenConState.Parameters[scenConKey]));
                                break;
                            case "ClassificationDisplayRulesType":
                                ((AttributeCollectionValue)currentSimCoreState).attributes.Add(simCoreName, (DataValue)currentScenConState.Parameters[scenConKey]);
                                break;
                            default:
                                break;
                        }
                    }
                }

                SimCoreStateTable.Add(kvp.Key, currentSimCoreState);
            }
            dv = new StateTableValue();
            ((StateTableValue)dv).states = SimCoreStateTable;
            e["StateTable"] = dv;

            ((AttributeCollectionValue)e["Attributes"]).attributes.Add("OwnerID", DataValueFactory.BuildString(incoming.Owner));/*ConvertString(    .Owner)*/
            ((AttributeCollectionValue)e["Attributes"]).attributes.Add("ClassName", DataValueFactory.BuildString(incoming.UnitBase));/*ConvertString(incoming.UnitBase)*/


            server.PutEvent(e);
        }
Example #13
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);
        }
Example #14
0
        /// <summary>
        /// When a move done event is received, then a normalizing ViewProMotionUpdate is sent out,
        /// and that object is removed from the MovingObjects list.  The VPMU that is sent out gives
        /// a destination location that is equal to its current location, and a throttle of 0.
        /// </summary>
        /// <param name="e">Incoming event</param>
        private void MoveDone(SimulationEvent e)
        {
            string id = ((StringValue)e["ObjectID"]).value;
            double throttle = ((DoubleValue)objectProxies[id]["Throttle"].GetDataValue() as DoubleValue).value;
            //LocationValue location = objectProxies[id]["DestinationLocation"].GetDataValue() as LocationValue;
            LocationValue location = objectProxies[id]["Location"].GetDataValue() as LocationValue;

            AttributeCollectionValue newACV = new AttributeCollectionValue();
            newACV.attributes.Add("ObjectID", DataValueFactory.BuildString(id));
            newACV.attributes.Add("Throttle", DataValueFactory.BuildDouble(throttle));
            newACV.attributes.Add("Time", DataValueFactory.BuildInteger(currentTick));
            newACV.attributes.Add("Location", location);
            newACV.attributes.Add("DestinationLocation", location);

            if (movingObjects.Contains(id))
            {
                movingObjects.Remove(id);
            }
            SendViewProStopObjectUpdate(id);
            SendViewProMotionUpdate(newACV);
        }
Example #15
0
        /// <summary>
        /// When a weapon is launched, a ViewProInitializeObject event must be first sent out to its 
        /// owner, and then a ViewProMotionUpdate must be sent out.  A weapon launch event only contains
        /// an ObjectID (of weapon), a ParentObjectID (the object launching the weapon), and a
        /// TargetObjectID (object being attacked by weapon.  We'll need to extract the target's
        /// location, the ParentObjectID's location for the initial Location, and the weapon's
        /// MaximumSpeed and icon for the VPMU event.  IsWeapon is set to true, and throttle is 1.
        /// Other objects will become aware of this weapon on the next time tick when the sensing
        /// algorithm occurs.
        /// </summary>
        /// <param name="e">Incoming event</param>
        private void WeaponLaunch(SimulationEvent e)
        {
            string weaponID = ((StringValue)e["ObjectID"]).value;
            string parentID = ((StringValue)e["ParentObjectID"]).value;
            string targetID = ((StringValue)e["TargetObjectID"]).value;
            string errorAt = "OwnerID";
            string errorAtOwner = weaponID;
            string ownerID;
            string iconName;
            LocationValue initialLocation;
            LocationValue destinationLocation;
            double throttle = 1;
            double maxSpeed = 0.0;
            bool isWeapon = true;
            AttributeCollectionValue newACV = new AttributeCollectionValue();
            newACV.attributes.Add("ObjectID", DataValueFactory.BuildString(weaponID));
            newACV.attributes.Add("Throttle", DataValueFactory.BuildDouble(throttle));
            newACV.attributes.Add("IsWeapon", DataValueFactory.BuildBoolean(isWeapon));
            SimulationObjectProxy obj;

            try
            {
                errorAtOwner = weaponID;
                obj = objectProxies[weaponID];
                errorAt = "OwnerID";
                ownerID = ((StringValue)obj["OwnerID"].GetDataValue()).value;
                newACV.attributes.Add("OwnerID", DataValueFactory.BuildString(ownerID));

                errorAt = "IconName";
                iconName = ((StringValue)obj["IconName"].GetDataValue()).value;
                newACV.attributes.Add("IconName", DataValueFactory.BuildString(iconName));

                errorAt = "MaximumSpeed";
                maxSpeed = ((DoubleValue)obj["MaximumSpeed"].GetDataValue()).value;
                newACV.attributes.Add("MaximumSpeed", DataValueFactory.BuildDouble(maxSpeed));

                errorAtOwner = parentID;
                obj = objectProxies[parentID];
                errorAt = "Location";
                initialLocation = obj["Location"].GetDataValue() as LocationValue;
                newACV.attributes.Add("Location", initialLocation as DataValue);

                errorAtOwner = targetID;
                obj = objectProxies[targetID];
                errorAt = "DestinationLocation";
                destinationLocation = obj["Location"].GetDataValue() as LocationValue;
                newACV.attributes.Add("DestinationLocation", destinationLocation as DataValue);
            }
            catch
            {
                throw new Exception(String.Format("Error in ViewPro: Error retrieving {0} attribute from the object {1}.", errorAt, errorAtOwner));
            }
            SendViewProInitializeObject(ownerID, weaponID, initialLocation, iconName, ownerID, true);
            SendViewProMotionUpdate(newACV);
        }
Example #16
0
        private void ActiveRegionSpeedMultiplierUpdate(SimulationEvent e)
        {
            AttributeCollectionValue atts;

            atts = new AttributeCollectionValue();
            string id = ((StringValue)e["ObjectID"]).value;
            atts.attributes.Add("ObjectID", DataValueFactory.BuildString(id));
            SendViewProStopObjectUpdate(id);
            SendViewProMotionUpdate(atts);

        }
Example #17
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        private void GameSpeed(SimulationEvent e)
        {
            initialReplaySpeed = e;
            AttributeCollectionValue atts;
            List<string> myObjects = new List<string>(movingObjects);

            foreach (string obID in myObjects)
            {
                atts = new AttributeCollectionValue();
                atts.attributes.Add("ObjectID", DataValueFactory.BuildString(obID));
                SendViewProStopObjectUpdate(obID);
                SendViewProMotionUpdate(atts);
            }
        }
Example #18
0
        private void ForceUpdateObjectAttribute(SimulationEvent e)
        {
            //if location send location/movement update
            string attributeName = ((StringValue)e["AttributeName"]).value;
            DataValue val = ((WrapperValue)e["AttributeValue"]).value;
            string objectID = ((StringValue)e["ObjectID"]).value;
            if (!objectProxies.ContainsKey(objectID))
            {
                return;
            }
            if (attributeName == "Location")
            {
                LocationValue origLocation = objectProxies[objectID]["Location"].GetDataValue() as LocationValue;
                LocationValue origDestination = objectProxies[objectID]["DestinationLocation"].GetDataValue() as LocationValue;

                AttributeCollectionValue acv = new AttributeCollectionValue();
                acv.attributes.Add(attributeName, val);
                acv.attributes.Add("ObjectID", DataValueFactory.BuildString(objectID));
                if (DataValueFactory.CompareDataValues(origDestination, origLocation))
                {
                    acv.attributes.Add("DestinationLocation", val); // if object wasn't moving, keep it that way.
                }
                SendViewProMotionUpdate(acv);
            }

                return;

        }
Example #19
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;
            }
        }
Example #20
0
        /// <summary>
        /// This method extracts an objects attributes from DetectedValues in an ACV, and then sends
        /// out the appropriate info to a specified player.
        /// </summary>
        /// <param name="destinationPlayerID"></param>
        /// <param name="objectsAttributes"></param>
        /// <param name="time"></param>
        private void SendViewProAttributeUpdate(string destinationPlayerID, AttributeCollectionValue objectsAttributes)
        {
            if (!activeDMs.Contains(destinationPlayerID))
                return;

            SimulationEvent vpu = null;
            objectsAttributes = ExtractDetectedValuesFromACV(objectsAttributes);
            AddCapabilitiesAndWeaponsList(ref objectsAttributes);
            if (objectsAttributes.attributes.ContainsKey("Vulnerability"))
            {
                List<string> vulnerabilityList = new List<string>();
                foreach (VulnerabilityValue.Transition t in ((VulnerabilityValue)objectsAttributes["Vulnerability"]).transitions)
                {
                    foreach (VulnerabilityValue.TransitionCondition tc in t.conditions)
                    {
                        if (!vulnerabilityList.Contains(tc.capability))
                        {
                            vulnerabilityList.Add(tc.capability);
                        }
                    }
                }
//                objectsAttributes.attributes.Remove("Vulnerability");
                StringListValue sl = new StringListValue();
                sl.strings = vulnerabilityList;
                objectsAttributes.attributes.Add("VulnerabilityList", sl as DataValue);
            }
            if (objectsAttributes.attributes.ContainsKey("Sensors"))
            {
                List<string> sensorList = new List<string>();
                foreach (SensorValue sv in ((SensorArrayValue)objectsAttributes["Sensors"]).sensors)
                {
                    if (!sensorList.Contains(sv.sensorName))
                    {
                        sensorList.Add(sv.sensorName);
                    }
                }

//                objectsAttributes.attributes.Remove("Sensors");
                StringListValue sl = new StringListValue();
                sl.strings = sensorList;
                objectsAttributes.attributes.Add("SensorList", sl as DataValue);
            }
            objectsAttributes["DockedObjects"] = new StringListValue();
            List<string> strList = new List<string>();
            //if (((StringValue)objectProxies[((StringValue)objectsAttributes["ID"]).value]["ParentObjectID"].GetDataValue()).value != string.Empty)
            //{
            //    strList.Add("Dock To Parent");
            //}
            strList.AddRange(((StringListValue)objectProxies[((StringValue)objectsAttributes["ID"]).value]["DockedObjects"].GetDataValue()).strings);
            ((StringListValue)objectsAttributes["DockedObjects"]).strings = strList;
            vpu = SimulationEventFactory.BuildEvent(ref simModel, "ViewProAttributeUpdate");
            if (!objectsAttributes.attributes.ContainsKey("MaximumSpeed"))
            {
                DoubleValue dv = new DoubleValue();
                dv.value = ((DoubleValue)objectProxies[((StringValue)objectsAttributes["ID"]).value]["MaximumSpeed"].GetDataValue()).value *
                    ((DoubleValue)objectProxies[((StringValue)objectsAttributes["ID"]).value]["ActiveRegionSpeedMultiplier"].GetDataValue()).value;
                objectsAttributes.attributes.Add("MaximumSpeed", dv as DataValue);
            }

            String classification = GetClassificationForDM(((StringValue)objectsAttributes["ID"]).value, destinationPlayerID);
            objectsAttributes["CurrentClassification"] = DataValueFactory.BuildString(classification);
            String overrideIcon = GetClassificationBasedIcon(((StringValue)objectsAttributes["ID"]).value, classification);
            if (overrideIcon != String.Empty)
            {
                objectsAttributes["IconName"] = DataValueFactory.BuildString(overrideIcon);
            }
            else
            {
                SimulationObjectProxy ob = objectProxies[((StringValue)objectsAttributes["ID"]).value];
                objectsAttributes["IconName"] = DataValueFactory.BuildString(((StringValue)ob["IconName"].GetDataValue()).value);
            }

            vpu["TargetPlayer"] = DataValueFactory.BuildString(destinationPlayerID);
            vpu["ObjectID"] = objectsAttributes["ID"];
            vpu["OwnerID"] = objectsAttributes["OwnerID"];

            //RANGE RING LOGIC
            string ownerId = ((StringValue)objectsAttributes["OwnerID"]).value;

            if (( (destinationPlayerID == ownerId || selectedRangeRingLevel == RangeRingLevels.FULL) ||
                     (selectedRangeRingLevel == RangeRingLevels.SENSORNETWORK && AreDecisionMakersInSharedNetwork(destinationPlayerID, ownerId)) ) &&
                    selectedRangeRingLevel != RangeRingLevels.DISABLED) //this needs to be based on ownership, etc.
            {
                SimulationObjectProxy objProxy = null;
                if (objectProxies.ContainsKey(((StringValue)objectsAttributes["ID"]).value))
                {
                    objProxy = objectProxies[((StringValue)objectsAttributes["ID"]).value];
                    AddRangeRings(ref objectsAttributes, ref objProxy);
                }
                else
                {
                    //if not, something's wrong
                    Console.WriteLine("HELP");
                }
            }
            else
            {
                objectsAttributes.attributes.Remove("Vulnerability");
                objectsAttributes.attributes.Remove("Sensors");
                objectsAttributes.attributes.Remove("Capability");
            }
            //

            //if (objectsAttributes.attributes.ContainsKey("MaximumSpeed"))
            //{
            //    Console.Out.Write(String.Format("{0} moving at {1}", ((StringValue)objectsAttributes["ID"]).value, ((DoubleValue)objectsAttributes["MaximumSpeed"]).value));
            //    //foreach (string s in objectsAttributes.attributes.Keys)
            //    //{
            //    //    Console.Out.Write(String.Format("{0}, ", s));
            //    //}
            //    Console.Out.WriteLine();
            //}
            vpu["Attributes"] = objectsAttributes;
            vpu["Time"] = DataValueFactory.BuildInteger(currentTick);

            string xml = DataValueFactory.XMLSerialize(objectsAttributes);
            AttributeCollectionValue temp = new AttributeCollectionValue();
            temp.FromXML(xml);


            distClient.PutEvent(vpu);
        }
Example #21
0
 /// <summary>
 /// Given a dictionary of [string, datavalue], a new DataValue is created, and assigned as an 
 /// Attribute Collection Value.  This AttributeCollectionValue's attribute setting is set to the input
 /// dictionary, and then the AttributeCollectionValue is returned as a DataValue.
 /// </summary>
 /// <param name="input">
 /// A dictionary of [string, DataValue] to be assigned to an AttributeCollectionValue.
 /// </param>
 /// <returns></returns>
 private static DataValue ConvertAttributeCollection(Dictionary<string, DataValue> input)
 {//Replaced by method in DataValueFactory...
     DataValue dv = new AttributeCollectionValue();
     ((AttributeCollectionValue)dv).attributes = input;
     return dv;
 }
Example #22
0
        private void SendViewProInitializeObject(string targetPlayerID, AttributeCollectionValue acv)
        {
            if (!activeDMs.Contains(targetPlayerID))
                return;

            string objectID = ((StringValue)acv["ID"]).value;
            string ownerID;
            string iconName;
            SimulationObjectProxy objectProxy = objectProxies[objectID];
            LocationValue location;
            bool isWeapon = false;
            AttributeCollectionValue playersView = new AttributeCollectionValue();
            if (!dmViews.ContainsKey(targetPlayerID))
            {
                dmViews.Add(targetPlayerID, new Aptima.Asim.DDD.CommonComponents.ObjectsAttributeCollection.ObjectsAttributeCollection());
            }
            if (!dmViews[targetPlayerID].ContainsObject(objectID))
            {
                dmViews[targetPlayerID].UpdateObject(objectID, new AttributeCollectionValue());
            }
            playersView = dmViews[targetPlayerID][objectID];

            
            if (acv.attributes.ContainsKey("Location"))
            {
                location = acv["Location"] as LocationValue;
            }
            else if (playersView.attributes.ContainsKey("Location"))
            {
                location = ((DetectedAttributeValue)playersView["Location"]).value as LocationValue;
            }
            else
            {
                location = objectProxy["Location"].GetDataValue() as LocationValue;
            }
            if (acv.attributes.ContainsKey("OwnerID"))
            {
                ownerID = ((StringValue)acv["OwnerID"]).value;
            }
            else if (playersView.attributes.ContainsKey("OwnerID"))
            {
                ownerID = ((StringValue)((DetectedAttributeValue)playersView["OwnerID"]).value).value;
            }
            else
            {
                ownerID = ((StringValue)objectProxy["OwnerID"].GetDataValue()).value;
            }
            if (acv.attributes.ContainsKey("IconName"))
            {
                iconName = ((StringValue)acv["IconName"]).value;
            }
            else if (playersView.attributes.ContainsKey("IconName"))
            {
                iconName = ((StringValue)((DetectedAttributeValue)playersView["IconName"]).value).value;
            }
            else
            {
                iconName = "ImageLib.Unknown.png";// ((StringValue)objectProxy["IconName"].GetDataValue()).value;
            }
            if (acv.attributes.ContainsKey("IsWeapon"))
            {
                isWeapon = ((BooleanValue)acv["IsWeapon"]).value;
            }
            else if (playersView.attributes.ContainsKey("IsWeapon"))
            {
                isWeapon = ((BooleanValue)((DetectedAttributeValue)playersView["IsWeapon"]).value).value;
            }
            else
            {
                isWeapon = ((BooleanValue)objectProxy["IsWeapon"].GetDataValue()).value;
            }

            SendViewProInitializeObject(targetPlayerID, objectID, location, iconName, ownerID, isWeapon);
        }
Example #23
0
        /// <summary>
        /// Takes an xml string, and returns a DataValue object.
        /// Returns null if the xml doesn't represent a DataValue.
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static DataValue XMLDeserialize(string xml)
        {
            Match m = typeregex.Match(xml);
            if (m.Success)
            {
                Group g = m.Groups[1];

                string dataType = g.ToString();
                switch (dataType)
                {
                    case "StringType":
                        StringValue sv = new StringValue();
                        sv.FromXML(xml);
                        return sv;
                    case "DoubleType":
                        DoubleValue dv = new DoubleValue();
                        dv.FromXML(xml);
                        return dv;
                    case "IntegerType":
                        IntegerValue iv = new IntegerValue();
                        iv.FromXML(xml);
                        return iv;
                    case "BooleanType":
                        BooleanValue bv = new BooleanValue();
                        bv.FromXML(xml);
                        return bv;
                    case "LocationType":
                        LocationValue lv = new LocationValue();
                        lv.FromXML(xml);
                        return lv;
                    case "VelocityType":
                        VelocityValue vv = new VelocityValue();
                        vv.FromXML(xml);
                        return vv;
                    case "AttributeCollectionType":
                        AttributeCollectionValue av = new AttributeCollectionValue();
                        av.FromXML(xml);
                        return av;
                    case "CustomAttributesType":
                        CustomAttributesValue cav = new CustomAttributesValue();
                        cav.FromXML(xml);
                        return cav;
                    case "StringListType":
                        StringListValue slv = new StringListValue();
                        slv.FromXML(xml);
                        return slv;
                    case "PolygonType":
                        PolygonValue polyv = new PolygonValue();
                        polyv.FromXML(xml);
                        return polyv;
                    case "StateTableType":
                        StateTableValue stv = new StateTableValue();
                        stv.FromXML(xml);
                        return stv;
                    case "CapabilityType":
                        CapabilityValue cv = new CapabilityValue();
                        cv.FromXML(xml);
                        return cv;
                    case "VulnerabilityType":
                        VulnerabilityValue vv2 = new VulnerabilityValue();
                        vv2.FromXML(xml);
                        return vv2;
                    case "ConeType":
                        ConeValue cv2 = new ConeValue();
                        cv2.FromXML(xml);
                        return cv2;
                    case "SensorType":
                        SensorValue sv2 = new SensorValue();
                        sv2.FromXML(xml);
                        return sv2;
                    case "SensorArrayType":
                        SensorArrayValue sav = new SensorArrayValue();
                        sav.FromXML(xml);
                        return sav;
                    case "EmitterType":
                        EmitterValue ev = new EmitterValue();
                        ev.FromXML(xml);
                        return ev;
                    case "RangeRingDisplayType":
                        RangeRingDisplayValue rrdv = new RangeRingDisplayValue();
                        rrdv.FromXML(xml);
                        return rrdv;
                    case "AttackCollectionType":
                        AttackCollectionValue attCV = new AttackCollectionValue();
                        attCV.FromXML(xml);
                        return attCV;
                    case "WrapperType":
                        WrapperValue wrapper = new WrapperValue();
                        wrapper.FromXML(xml);
                        return wrapper;
                    case "ClassificationDisplayRulesType":
                        ClassificationDisplayRulesValue cdrv = new ClassificationDisplayRulesValue();
                        cdrv.FromXML(xml);
                        return cdrv;
                    default:
                        return null;
                }
            }
            else
            {
                return null;
            }

        }
Example #24
0
        /// <summary>
        /// When a pause event is received, foreach object in the movement list, a ViewProMotionUpdate
        /// must be sent out with a throttle of 0 (all the rest of the values can remain the same from
        /// an object proxy).
        /// </summary>
        private void PauseScenario()
        {
            AttributeCollectionValue tempACV = new AttributeCollectionValue();
            tempACV.attributes.Add("Throttle", DataValueFactory.BuildDouble(0));
            tempACV.attributes.Add("ObjectID", DataValueFactory.BuildString(string.Empty));

            foreach (string objectID in movingObjects)
            {
                tempACV["ObjectID"] = DataValueFactory.BuildString(objectID);
                SendViewProMotionUpdate(tempACV);
            }

        }
Example #25
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;
 }
Example #26
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);
                        }
                    }
                }
            }
        }
Example #27
0
        /// <summary>
        /// This event is broadcast out to each client.  The client will attempt to put the object in motion, but
        /// will only succeed if the object already exists in its playfield.
        /// </summary>
        /// <param name="attributes">This is a collection of object attributes.  If any necessary attributes for
        /// a ViewProMotionUpdate are missing from this collection, the appropriate attribute values will be
        /// retrieved from that object's blackboard proxy.</param>
        private void SendViewProMotionUpdate(AttributeCollectionValue attributes)
        {
            string objectID = ((StringValue)attributes["ObjectID"]).value;
            string ownerID;
            string iconName;
            SimulationObjectProxy objectProxy = objectProxies[objectID];
            LocationValue location;
            LocationValue destLocation;
            double maxSpeed;
            double throttle;
            bool isWeapon = false;
            double activeRegionSpeedMultiplier;

            activeRegionSpeedMultiplier = ((DoubleValue)objectProxy["ActiveRegionSpeedMultiplier"].GetDataValue()).value;

            if (attributes.attributes.ContainsKey("Location"))
            {
                location = attributes["Location"] as LocationValue;
            }
            else
            {
                location = objectProxy["Location"].GetDataValue() as LocationValue;
            }

            if (attributes.attributes.ContainsKey("DestinationLocation"))
            {
                destLocation = attributes["DestinationLocation"] as LocationValue;
            }
            else
            {
                destLocation = objectProxy["DestinationLocation"].GetDataValue() as LocationValue;
            }

            if (attributes.attributes.ContainsKey("OwnerID"))
            {
                ownerID = ((StringValue)attributes["OwnerID"]).value;
            }
            else
            {
                ownerID = ((StringValue)objectProxy["OwnerID"].GetDataValue()).value;
            }

            if (attributes.attributes.ContainsKey("MaximumSpeed"))
            {
                maxSpeed = ((DoubleValue)attributes["MaximumSpeed"]).value;
            }
            else
            {
                maxSpeed = ((DoubleValue)objectProxy["MaximumSpeed"].GetDataValue()).value;
            }

            if (attributes.attributes.ContainsKey("Throttle"))
            {
                throttle = ((DoubleValue)attributes["Throttle"]).value;
            }
            else
            {
                throttle = ((DoubleValue)objectProxy["Throttle"].GetDataValue()).value;
            }
            if (attributes.attributes.ContainsKey("IconName"))
            {
                iconName = ((StringValue)attributes["IconName"]).value;
            }
            else
            {
                iconName = ((StringValue)objectProxy["IconName"].GetDataValue()).value;
            }
            if (attributes.attributes.ContainsKey("IsWeapon"))
            {
                isWeapon = ((BooleanValue)attributes["IsWeapon"]).value;
            }
            else
            {
                isWeapon = ((BooleanValue)objectProxy["IsWeapon"].GetDataValue()).value;
            }
            SendViewProMotionUpdate(objectID, ownerID, location, destLocation, maxSpeed, throttle, iconName, isWeapon, activeRegionSpeedMultiplier);
        }
Example #28
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="allObjectViews"></param>
        private void SenseAllObjects(ref Dictionary<string, Dictionary<string, AttributeCollectionValue>> allObjectsViews)
        {
            SimulationObjectProxy sensingProxy = null;
            SimulationObjectProxy targetProxy = null;
            Vec3D sensingLocation = null;
            Vec3D targetsLocation = null;
            LocationValue senLocation = null;
            LocationValue tarLocation = null;
            double distance = 0.0;
            SensorArrayValue sav = null;
            DataValue targetsAttribute = null;
            string ownerID = null;
            string objectType = null;
            DetectedAttributeValue detectedAttribute;
            AttributeCollectionValue singleAttributeCollection = null;
            bool isSensed = false;

            // The dictionary is constantly created in this method //
            Dictionary<string, AttributeCollectionValue> singleObjectView;

            //AD to improve this later:
            // for each object in the visible ObjectDistances collection
            //    for each object after the current index
            //       check for the index object's view of the nested object
            //       check for the nested object's view of the index object
            //Possible hangup is the "All" emitter.





            int x = 0;
            //Each object senses each other object
            //foreach (string sensorObjectID in listOfObjectIDs)
            foreach (KeyValuePair<string, List<string>> networks in networkRosters)
            {
                if (!activeSensorNetworks[networks.Key])
                    continue;
                foreach (string sensorObjectID in networkObjects[networks.Key])
                {
                    sensingProxy = objectProxies[sensorObjectID];
                    objectType = sensingProxy.GetObjectType();
                    senLocation = sensingProxy["Location"].GetDataValue() as LocationValue;
                    if (senLocation.exists)
                    {
                        ownerID = ((StringValue)sensingProxy["OwnerID"].GetDataValue()).value;
                        singleObjectView = new Dictionary<string, AttributeCollectionValue>();
                        x++;
                        //foreach (string targetObjectID in listOfObjectIDs)
                        foreach (List<string> objects in networkObjects.Values)
                        {
                            if (objects.Contains(sensorObjectID))
                            {
                                if (((EmitterValue)sensingProxy["Emitters"].GetDataValue()).emitters.ContainsKey("Invisible"))
                                {
                                    continue;
                                }
                                string target = sensorObjectID;

                                singleAttributeCollection = new AttributeCollectionValue();
                                foreach (KeyValuePair<string, AttributeInfo> simModelAtt in simModel.objectModel.objects[objectType].attributes)
                                {
                                    if (!simModelAtt.Value.ownerObservable == true)
                                        continue;
                                    //if (!sensingProxy.GetKeys().Contains(simModelAtt.Key))
                                    //    continue;
                                    DataValue t = sensingProxy[simModelAtt.Key].GetDataValue();
                                    if (t.dataType == "CustomAttributesType")
                                    {
                                        Dictionary<string, DataValue> copiedDict = CopyFromCustomAttributes(((CustomAttributesValue)t).attributes);
                                        t = new CustomAttributesValue();
                                        ((CustomAttributesValue)t).attributes = copiedDict;
                                    }
                                    detectedAttribute = new DetectedAttributeValue();
                                    detectedAttribute.stdDev = 100;
                                    detectedAttribute.value = DataValueFactory.BuildFromDataValue(t);
                                    AddAttributeToACV(ref singleAttributeCollection, simModelAtt.Key, detectedAttribute);
                                }//end foreach sensable attribute

                                if (!allObjectsViews.ContainsKey(sensorObjectID))
                                {
                                    allObjectsViews.Add(sensorObjectID, new Dictionary<string, AttributeCollectionValue>());
                                }
                                if (!objectViews.ContainsKey(sensorObjectID))
                                {
                                    objectViews.Add(sensorObjectID, new ObjectsAttributeCollection());
                                }
                                //update the global "allObjectViews".  The return from UpdateObject is the collection of attributes
                                //that have changed.  These attributes are stored in allObjectsViews and then sent out
                                //to users.
                                AttributeCollectionValue changedAttributes = objectViews[sensorObjectID].UpdateObject(target, singleAttributeCollection);

                                //if (changedAttributes != null && selectedRangeRingLevel != RangeRingLevels.DISABLED)
                                //{
                                //    CalculateRangeRings(ref changedAttributes, ref sensingProxy);
                                //}

                                if (changedAttributes != null)
                                {
                                    allObjectsViews[sensorObjectID].Add(target, changedAttributes);
                                }
                                else//this is so there is at least the empty entry for the detected object so 
                                //you still know it is detected.
                                {
                                    if (!allObjectsViews[sensorObjectID].ContainsKey(target))
                                    {
                                        allObjectsViews[sensorObjectID].Add(target, new AttributeCollectionValue());
                                    }
                                }
                            }
                            else
                            {
                                foreach (string targetObjectID in objects)
                                {//sensing and target objects are not the same 
                                    targetProxy = objectProxies[targetObjectID];
                                    tarLocation = targetProxy["Location"].GetDataValue() as LocationValue;
                                    if (tarLocation.exists)
                                    {
                                        EmitterValue emitters = targetProxy["Emitters"].GetDataValue() as EmitterValue;
                                        if (emitters.emitters.ContainsKey("All"))
                                        {
                                            //if an object has an all emitter, retrieve all attributes without sensing algorithm
                                            AttributeCollectionValue atts = new AttributeCollectionValue();
                                            if (singleObjectView.ContainsKey(targetObjectID))
                                            {
                                                atts = singleObjectView[targetObjectID];
                                            }
                                            SenseAllAttributes(ref atts, targetProxy);
                                            singleObjectView[targetObjectID] = atts;
                                            isSensed = true;

                                            if (!allObjectsViews.ContainsKey(sensorObjectID))
                                            {
                                                allObjectsViews.Add(sensorObjectID, new Dictionary<string, AttributeCollectionValue>());
                                            }
                                            if (!objectViews.ContainsKey(sensorObjectID))
                                            {
                                                objectViews.Add(sensorObjectID, new ObjectsAttributeCollection());
                                            }
                                            //update the global "allObjectViews".  The return from UpdateObject is the collection of attributes
                                            //that have changed.  These attributes are stored in allObjectsViews and then sent out
                                            //to users.
                                            AttributeCollectionValue changedAttributes = objectViews[sensorObjectID].UpdateObject(targetObjectID, atts);

                                            //if (changedAttributes != null && selectedRangeRingLevel == RangeRingLevels.FULL)
                                            //{//the only way to sense a "target" here is for FULL ring display
                                            //    CalculateRangeRings(ref changedAttributes, ref targetProxy);
                                            //}

                                            if (changedAttributes != null)
                                            {
                                                allObjectsViews[sensorObjectID].Add(targetObjectID, changedAttributes);
                                            }
                                            else//this is so there is at least the empty entry for the detected object so 
                                            //you still know it is detected.
                                            {
                                                if (!allObjectsViews[sensorObjectID].ContainsKey(targetObjectID))
                                                {
                                                    allObjectsViews[sensorObjectID].Add(targetObjectID, new AttributeCollectionValue());
                                                }
                                            }
                                        }
                                        else if (emitters.emitters.ContainsKey("Invisible"))
                                        {
                                            continue;
                                        }
                                        else
                                        {//object does not have an all emitter, continue to check each emitter value 
                                            AttributeCollectionValue atts = new AttributeCollectionValue();
                                            if (Omniscience)
                                            {
                                                if (singleObjectView.ContainsKey(targetObjectID))
                                                {
                                                    atts = singleObjectView[targetObjectID];
                                                }
                                                SenseAllAttributes(ref atts, targetProxy);
                                                singleObjectView[targetObjectID] = atts;
                                                isSensed = true;
                                                if (!allObjectsViews.ContainsKey(sensorObjectID))
                                                {
                                                    allObjectsViews.Add(sensorObjectID, new Dictionary<string, AttributeCollectionValue>());
                                                }
                                                if (!objectViews.ContainsKey(sensorObjectID))
                                                {
                                                    objectViews.Add(sensorObjectID, new ObjectsAttributeCollection());
                                                }
                                                //update the global "allObjectViews".  The return from UpdateObject is the collection of attributes
                                                //that have changed.  These attributes are stored in allObjectsViews and then sent out
                                                //to users.
                                                AttributeCollectionValue changedAttributes = objectViews[sensorObjectID].UpdateObject(targetObjectID, atts);

                                                //if (changedAttributes != null && selectedRangeRingLevel == RangeRingLevels.FULL)
                                                //{//the only way to sense a "target" here is for FULL ring display
                                                //    CalculateRangeRings(ref changedAttributes, ref targetProxy);
                                                //}

                                                if (changedAttributes != null)
                                                {
                                                    allObjectsViews[sensorObjectID].Add(targetObjectID, changedAttributes);
                                                }
                                                else//this is so there is at least the empty entry for the detected object so 
                                                //you still know it is detected.
                                                {
                                                    if (!allObjectsViews[sensorObjectID].ContainsKey(targetObjectID))
                                                    {
                                                        allObjectsViews[sensorObjectID].Add(targetObjectID, new AttributeCollectionValue());
                                                    }
                                                }
                                                continue;
                                            }

                                            sensingLocation = new Vec3D(senLocation);
                                            targetsLocation = new Vec3D(tarLocation);
                                            isSensed = false;
                                            distance = sensingLocation.ScalerDistanceTo(targetsLocation);
                                            sav = sensingProxy["Sensors"].GetDataValue() as SensorArrayValue;

                                            foreach (SensorValue sv in sav.sensors)
                                            {
                                                if (distance < sv.maxRange)
                                                {
                                                    //Find obstructions
                                                    List<SimulationObjectProxy> obstructions = FindObstructions(sensingLocation, targetsLocation);

                                                    foreach (KeyValuePair<string, List<ConeValue>> kvp in sv.ranges)
                                                    { //Key is the attribute being sensed, value is a list of cones
                                                        if (kvp.Key == "All")
                                                        {
                                                            atts = new AttributeCollectionValue();
                                                            if (singleObjectView.ContainsKey(targetObjectID))
                                                            {
                                                                atts = singleObjectView[targetObjectID];
                                                            }
                                                            SenseAllAttributes(ref atts, targetProxy);
                                                            singleObjectView[targetObjectID] = atts;
                                                            isSensed = true;
                                                        }
                                                        else //not an All sensor, so run detection algorithm
                                                        {//Added in main-line
                                                            if (!emitters.emitters.ContainsKey(kvp.Key))
                                                            {
                                                                continue;
                                                            }
                                                            //Custom attributes fix:
                                                            DataValue currentDataValue;
                                                            try
                                                            {
                                                                currentDataValue = targetProxy[kvp.Key].GetDataValue();
                                                            }
                                                            catch
                                                            {
                                                                currentDataValue = targetProxy["CustomAttributes"].GetDataValue();
                                                                currentDataValue = ((CustomAttributesValue)currentDataValue)[kvp.Key];
                                                                //will throw an error here if object doesn't contain custom atts, or 
                                                                //if it doesnt contain the specified custom att.
                                                            }

                                                            bool isObstructed = false;
                                                            foreach (SimulationObjectProxy reg in obstructions)
                                                            {
                                                                foreach (string attributeBlocked in ((StringListValue)reg["BlocksSensorTypes"].GetDataValue()).strings)
                                                                {
                                                                    if (kvp.Key == attributeBlocked)
                                                                    {
                                                                        isObstructed = true;
                                                                    }
                                                                }
                                                            }
                                                            if (isObstructed)
                                                            {
                                                                detectedAttribute = new DetectedAttributeValue();
                                                                detectedAttribute.value = DataValueFactory.BuildValue(currentDataValue.dataType);
                                                                detectedAttribute.confidence = 0;
                                                                //continue;
                                                            }
                                                            else
                                                            {
                                                                targetsAttribute = DataValueFactory.BuildFromDataValue(currentDataValue);
                                                                //ev is emitters
                                                                Dictionary<string, double> emitterCollection = emitters.emitters[kvp.Key];

                                                                detectedAttribute = new DetectedAttributeValue();
                                                                detectedAttribute = ObjectMath.Detection(senLocation, tarLocation, targetsAttribute, kvp.Value, emitterCollection, obstructions, ref randomGenerator);
                                                            }
                                                            if (detectedAttribute != null)
                                                            {
                                                                singleAttributeCollection = new AttributeCollectionValue();
                                                                if (singleObjectView.ContainsKey(targetObjectID))
                                                                {
                                                                    singleAttributeCollection = singleObjectView[targetObjectID];
                                                                }
                                                                AddAttributeToACV(ref singleAttributeCollection, kvp.Key, detectedAttribute);
                                                                isSensed = true;
                                                            }
                                                        }
                                                    }//end foreach attribute in sensor

                                                    //if the object has any attributes sensed, fill in some other info for the object's view.
                                                    if (isSensed)
                                                    {
                                                        detectedAttribute = new DetectedAttributeValue();
                                                        detectedAttribute.stdDev = 100;
                                                        detectedAttribute.value = targetProxy["ID"].GetDataValue();
                                                        if (singleAttributeCollection == null)
                                                        {
                                                            singleAttributeCollection = new AttributeCollectionValue();
                                                        }
                                                        if (!singleObjectView.ContainsKey(targetObjectID))
                                                        {
                                                            singleObjectView.Add(targetObjectID, singleAttributeCollection);
                                                        }
                                                        singleAttributeCollection = singleObjectView[targetObjectID];
                                                        AddAttributeToACV(ref singleAttributeCollection, "ID", detectedAttribute);

                                                        detectedAttribute = new DetectedAttributeValue();
                                                        detectedAttribute.stdDev = 100;
                                                        detectedAttribute.value = targetProxy["OwnerID"].GetDataValue();
                                                        AddAttributeToACV(ref singleAttributeCollection, "OwnerID", detectedAttribute);
                                                    }//end if isSensed.
                                                }
                                            }//end foreach sensor in sensor array

                                            if (singleObjectView.ContainsKey(targetObjectID))
                                            {
                                                AttributeCollectionValue attr = singleObjectView[targetObjectID];
                                                if (!allObjectsViews.ContainsKey(sensorObjectID))
                                                {
                                                    allObjectsViews.Add(sensorObjectID, new Dictionary<string, AttributeCollectionValue>());
                                                }
                                                if (!objectViews.ContainsKey(sensorObjectID))
                                                {
                                                    objectViews.Add(sensorObjectID, new ObjectsAttributeCollection());
                                                }

                                                if (attr.attributes.ContainsKey("CustomAttributes"))
                                                {
                                                    DataValue t = ((DetectedAttributeValue)attr["CustomAttributes"]).value;
                                                    double conf = ((DetectedAttributeValue)attr["CustomAttributes"]).confidence;
                                                    Dictionary<string, DataValue> copiedDict = CopyFromCustomAttributes(((CustomAttributesValue)t).attributes);
                                                    t = new CustomAttributesValue();
                                                    ((CustomAttributesValue)t).attributes = copiedDict;
                                                    attr.attributes.Remove("CustomAttributes");
                                                    attr.attributes.Add("CustomAttributes", DataValueFactory.BuildDetectedValue(t, Convert.ToInt32(conf)));
                                                }
                                                //update the global "allObjectViews".  The return from UpdateObject is the collection of attributes
                                                //that have changed.  These attributes are stored in allObjectsViews and then sent out
                                                //to users.
                                                AttributeCollectionValue changedAttributes = objectViews[sensorObjectID].UpdateObject(targetObjectID, attr);

                                                //if (changedAttributes != null && selectedRangeRingLevel == RangeRingLevels.FULL)
                                                //{//the only way to sense a "target" here is for FULL ring display
                                                //    CalculateRangeRings(ref changedAttributes, ref targetProxy);
                                                //}

                                                if (changedAttributes != null)
                                                {
                                                    allObjectsViews[sensorObjectID].Add(targetObjectID, changedAttributes);
                                                }
                                                else//this is so there is at least the empty entry for the detected object so 
                                                //you still know it is detected.
                                                {
                                                    if (!allObjectsViews[sensorObjectID].ContainsKey(targetObjectID))
                                                    {
                                                        allObjectsViews[sensorObjectID].Add(targetObjectID, new AttributeCollectionValue());
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (objectViews.ContainsKey(sensorObjectID))
                                                {
                                                    if (objectViews[sensorObjectID].ContainsObject(targetObjectID))
                                                    {
                                                        objectViews[sensorObjectID].RemoveObject(targetObjectID);
                                                        //if you once knew of this object, and now don't, remove it from object's view.
                                                    }
                                                }
                                            }
                                        }//end emitter detection
                                    }//end if target is visible
                                }
                            }
                        }//end foreach target object
                    }//end if sensor is visible
                }//end of foreach sensing object
            }//end of Foreach sensor network
            //if (x > 0)
            //  Console.Out.WriteLine("ViewPro: {0} objects were sensing at time {1}.", x, currentTick / 1000);
        }
Example #29
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)
            {
            }
        }
 /// <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);
         }
     }
 }