Ejemplo n.º 1
0
        private void ChangeObjectThrottle(DoubleValue newThrottle, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];
            if (obj == null)
                return;
            LocationValue destination = obj["DestinationLocation"].GetDataValue() as LocationValue;

            if (destination != null)
            {
                if (destination.exists)
                {
                    SendMoveObjectEvent(objectID, newThrottle.value, destination);
                }
            }

            obj["Throttle"].SetDataValue(newThrottle);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
 private void ChangeObjectFuelRate(DoubleValue newRate, string objectID)
 {
     SimulationObjectProxy obj = objectProxies[objectID];
     if (obj == null)
         return;
     obj["FuelConsumptionRate"].SetDataValue(newRate);
 }
Ejemplo n.º 4
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;
            }

        }
Ejemplo n.º 5
0
        private void ChangeObjectFuelAmount(DoubleValue newAmount, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];
            if (obj == null)
                return;
            double fuelCapacity = ((DoubleValue)obj["FuelCapacity"].GetDataValue()).value;
            double newAmountValue = Math.Min(newAmount.value, fuelCapacity); //enforce constraint

            obj["FuelAmount"].SetDataValue(DataValueFactory.BuildDouble(newAmountValue));
        }
Ejemplo n.º 6
0
        private void ChangeObjectMaximumSpeed(DoubleValue newSpeed, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];
            if (obj == null)
                return;
            
            obj["MaximumSpeed"].SetDataValue(newSpeed);
            double throttle = ((DoubleValue)obj["Throttle"].GetDataValue()).value;
            LocationValue lv = obj["DestinationLocation"].GetDataValue() as LocationValue;

            //If the object was previously in motion, update that path
            if (lv != null)
            {
                if (lv.exists)
                {
                    ResetObjectMovement(objectID, throttle, lv);
                }
            }
        }
Ejemplo n.º 7
0
 private void ChangeObjectSize(DoubleValue newSize, string objectID)
 {
     SimulationObjectProxy obj = objectProxies[objectID];
     if (obj == null)
         return;
     //DoubleValue objectSize = obj["Size"].GetDataValue() as DoubleValue;
     obj["Size"].SetDataValue(newSize);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Given a double, a new DataValue is created, and assigned as a 
 /// DoubleValue.  This DoubleValue's value setting is set to the input
 /// double, and then the DoubleValue is returned as a DataValue.
 /// </summary>
 /// <param name="input">
 /// A double to be assigned to a DoubleValue.
 /// </param>
 /// <returns>
 ///</returns>
 private static DataValue ConvertDouble(double input)
 {//Replaced by method in DataValueFactory...
     DataValue dv = new DoubleValue();
     ((DoubleValue)dv).value = input;
     return dv;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// This method takes in a dictionary that represents the SimulationModel parameters, and a Dictionary
        /// that is to be used to populate a DataValue dictionary given the Simulation Model.  Foreach entry
        /// in the SimModel dictionary, if the same key (witch is converted from SimCoreKey to ScenConKey)
        /// exists in the given DataValue dictionary, then that value is used rather than a default DataValue.
        /// The newly created DataValue dictionary represents every member in the SimModel dictionary, and uses
        /// the available data from the given DataValue dictionary.
        /// </summary>
        /// <param name="objectAttributes">
        /// This Dictionary is indexed by a string that is the parameter name, and the value is an AttributeInfo
        /// object that contains the name and type of the parameter.
        /// </param>
        /// <param name="SendingEventAttributes">
        /// This dictionary contains attributes given from the ScenCon, to be passed on to the SimCore.  The 
        /// data is copied over to the correct entry in the resulting dictionary.
        /// </param>
        /// <returns></returns>
        private static Dictionary<string, DataValue> ParseAttributesList(Dictionary<string, AttributeInfo> objectAttributes, Dictionary<string, object> SendingEventAttributes)
        {
            Dictionary<string, DataValue> myAtt = new Dictionary<string, DataValue>();
            DataValue dv;
            string scenConKey,
                   simCoreKey,
                   attributeType;

            foreach (KeyValuePair<string, AttributeInfo> pair in objectAttributes)
            {
                if (!simModelIgnoreList.Contains(pair.Key))
                {
                    simCoreKey = pair.Key;
                    scenConKey = convertSimCoreToScenCon(simCoreKey);
                    if (SendingEventAttributes.ContainsKey(scenConKey))
                    {//Copy over the data 
                        attributeType = pair.Value.dataType;
                        switch (attributeType)
                        { //attribute type will be either the system defined name, or Dennis' type
                            case "StringType":

                                if (SendingEventAttributes.ContainsKey(scenConKey))
                                {
                                    myAtt.Add(simCoreKey, DataValueFactory.BuildString(Convert.ToString(SendingEventAttributes[scenConKey])));
                                }/*ConvertString(Convert.ToString(SendingEventAttributes[scenConKey])*/
                                else
                                {
                                    myAtt.Add(simCoreKey, DataValueFactory.BuildString(string.Empty));
                                }/*ConvertString(String.Empty)*/

                                break;
                            case "IntegerType":
                                dv = new IntegerValue();
                                if (SendingEventAttributes.ContainsKey(scenConKey))
                                {
                                    dv = DataValueFactory.BuildInteger(Convert.ToInt32(SendingEventAttributes[scenConKey]));//ConvertInteger(Convert.ToInt32(SendingEventAttributes[scenConKey]));
                                }
                                myAtt.Add(simCoreKey, dv);
                                break;
                            case "BooleanType":
                                dv = new BooleanValue();
                                if (SendingEventAttributes.ContainsKey(scenConKey))
                                {
                                    dv = DataValueFactory.BuildBoolean(Convert.ToBoolean(SendingEventAttributes[scenConKey]));//ConvertBoolean(Convert.ToBoolean(SendingEventAttributes[scenConKey]));
                                }
                                myAtt.Add(simCoreKey, dv);
                                break;
                            case "DoubleType":
                                dv = new DoubleValue();
                                if (SendingEventAttributes.ContainsKey(scenConKey))
                                {
                                    dv = DataValueFactory.BuildDouble(Convert.ToDouble(SendingEventAttributes[scenConKey]));//ConvertDouble(Convert.ToDouble(SendingEventAttributes[scenConKey]));
                                }
                                myAtt.Add(simCoreKey, dv);
                                break;

                            case "LocationType":

                                dv = new LocationValue();
                                ((LocationValue)dv).exists = false;
                                if (SendingEventAttributes.ContainsKey(scenConKey))
                                {
                                    LocationType lt = SendingEventAttributes[scenConKey] as LocationType;
                                    dv = DataValueFactory.BuildLocation(lt.X, lt.Y, lt.Z, true);//ConvertLocation((LocationType)SendingEventAttributes[scenConKey], true);
                                }
                                myAtt.Add(simCoreKey, dv);
                                break;
                            case "VelocityType":

                                dv = new VelocityValue();
                                if (SendingEventAttributes.ContainsKey(scenConKey))
                                {
                                    VelocityType vt = SendingEventAttributes[scenConKey] as VelocityType;
                                    dv = DataValueFactory.BuildVelocity(vt.VX, vt.VY, vt.VZ);//ConvertVelocity((VelocityType)SendingEventAttributes[scenConKey]);
                                }
                                myAtt.Add(simCoreKey, dv);
                                break;

                            case "StringListType":
                                dv = new StringListValue();
                                if (SendingEventAttributes.ContainsKey(scenConKey))
                                {
                                    ((StringListValue)dv).strings = (List<string>)SendingEventAttributes[scenConKey];
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            return myAtt;
        }