Example #1
0
 public void SetDataValue(DataValue dv)
 {
     lock (blackboard.blackboardLock)
     {
         if (publish)
         {
             blackboard[objectID][attributeName] = dv;
             ObjectLog.Write(blackboard.simTime, objectID, attributeName, DataValueFactory.XMLSerialize(dv));
         }
         else
         {
             throw new Exception("Error: Simulator tried to modify attribute it doesn't own.");
         }
     }
 }
Example #2
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 #3
0
        /*
         * static public SimulationEvent DeepCopy(ref SimulationEvent e)
         * {
         *  SimulationEvent n = new SimulationEvent();
         *  n.eventType = e.eventType;
         *  foreach (string p in e.parameters.Keys)
         *  {
         *      n.parameters[p] = e.parameters[p];
         *  }
         *
         *  return n;
         * }
         */

        static public string XMLSerialize(SimulationEvent e)
        {
            StringBuilder sb;

            lock (e.eventLock)
            {
                sb = new StringBuilder(String.Format("<{0}>", e.eventType));

                foreach (string key in e.parameters.Keys)
                {
                    sb.Append(String.Format("<Parameter><Name>{0}</Name><Value>{1}</Value></Parameter>", key, DataValueFactory.XMLSerialize(e.parameters[key])));
                }
                sb.Append(String.Format("</{0}>", e.eventType));
            }
            return(sb.ToString());
        }
Example #4
0
        static void Main(string[] args)
        {
            Polygon2D poly = new Polygon2D();

            poly.AddVertex(new Vec2D(1, 1));
            poly.AddVertex(new Vec2D(4, 1));
            poly.AddVertex(new Vec2D(2.5, 3));
            poly.AddVertex(new Vec2D(4, 3));
            poly.AddVertex(new Vec2D(4, 4));
            poly.AddVertex(new Vec2D(2, 3.5));

            bool r;

            r = Polygon2D.IsPointInside(poly, new Vec2D(5, 3));                                                 //false
            r = Polygon2D.IsPointInside(poly, new Vec2D(2, 2));                                                 //true
            r = Polygon2D.IsPointInside(poly, new Vec2D(3.5, 3.5));                                             //true
            r = Polygon2D.IsPointInside(poly, new Vec2D(1, 3.5));                                               //false
            r = Polygon2D.IsPointInside(poly, new Vec2D(3, 2.5));                                               //false

            r = Polygon2D.DoLinesIntersect(new Vec2D(0, 2), new Vec2D(3, 0), new Vec2D(1, 1), new Vec2D(3, 3)); //true
            r = Polygon2D.DoLinesIntersect(new Vec2D(0, 2), new Vec2D(3, 0), new Vec2D(2, 1), new Vec2D(3, 3)); //false

            DataValue dv = DataValueFactory.BuildValue("CapabilityType");

            ((CapabilityValue)dv).effects.Add(new CapabilityValue.Effect("foo", 45, 10, .50));
            ((CapabilityValue)dv).effects.Add(new CapabilityValue.Effect("foo", 100, 5, .25));

            string s = DataValueFactory.XMLSerialize(dv);

            DataValue dv2 = DataValueFactory.XMLDeserialize(s);

            DataValue dv3 = DataValueFactory.BuildValue("VulnerabilityType");

            VulnerabilityValue.Transition t = new VulnerabilityValue.Transition("dead");
            t.conditions.Add(new VulnerabilityValue.TransitionCondition("foo", 50, 0, 0));
            t.conditions.Add(new VulnerabilityValue.TransitionCondition("bar", 20, 0, 0));

            ((VulnerabilityValue)dv3).transitions.Add(t);

            t = new VulnerabilityValue.Transition("hurt");
            t.conditions.Add(new VulnerabilityValue.TransitionCondition("foo", 25, 0, 0));
            ((VulnerabilityValue)dv3).transitions.Add(t);

            s = DataValueFactory.XMLSerialize(dv3);

            DataValue dv4 = DataValueFactory.XMLDeserialize(s);

            System.Console.WriteLine(s == DataValueFactory.XMLSerialize(dv4));

            DataValue dv5 = DataValueFactory.BuildValue("StateTableType");
            DataValue dv6 = DataValueFactory.BuildValue("AttributeCollectionType");

            ((StateTableValue)dv5).states["foo"] = DataValueFactory.BuildValue("DoubleType");
            ((AttributeCollectionValue)dv6).attributes["foo2"] = DataValueFactory.BuildValue("DoubleType");
            ((StateTableValue)dv5).states["bar"] = dv6;

            s = DataValueFactory.XMLSerialize(dv5);

            DataValue dv7 = DataValueFactory.XMLDeserialize(s);

            DataValue dv8 = DataValueFactory.BuildValue("StringListType");

            ((StringListValue)dv8).strings.Add("Foo");
            ((StringListValue)dv8).strings.Add("Bar");

            s = DataValueFactory.XMLSerialize(dv8);

            dv8 = DataValueFactory.XMLDeserialize(s);

            DataValue dv9 = DataValueFactory.BuildValue("PolygonType");

            ((PolygonValue)dv9).points.Add(new PolygonValue.PolygonPoint(0, 0));
            ((PolygonValue)dv9).points.Add(new PolygonValue.PolygonPoint(10.234, 34.097));
            ((PolygonValue)dv9).points.Add(new PolygonValue.PolygonPoint(10.234, 1.2));

            s = DataValueFactory.XMLSerialize(dv9);

            DataValue dv10 = DataValueFactory.XMLDeserialize(s);
        }