示例#1
0
        private void btnOpenVoice_Click(object sender, EventArgs e)
        {
            if (null == lbxDecisionMakers.SelectedItem)
            {
                MessageBox.Show("Please select an owner for the voice channel.");
                return;
            }
            if ((null == lbxVoiceMembers.SelectedItems) || (lbxVoiceMembers.SelectedItems.Count < 2))
            {
                MessageBox.Show("Please select at least two members for the voice channel.");
                return;
            }
            if ("" == txtOpenVoiceName.Text)
            {
                MessageBox.Show("Please provide a name for the voice channel.");
                return;
            }
            SimulationEvent openVoice = SimulationEventFactory.BuildEvent(ref simModelInfo, "RequestVoiceChannelCreate");

            openVoice["ChannelName"] = DataValueFactory.BuildString(txtOpenVoiceName.Text);
            openVoice["SenderDM_ID"] = DataValueFactory.BuildString((string)lbxDecisionMakers.SelectedItem);
            StringListValue voiceMembers = new StringListValue();

            for (int i = 0; i < lbxVoiceMembers.SelectedItems.Count; i++)
            {
                voiceMembers.strings.Add((string)lbxVoiceMembers.SelectedItems[i]);
            }
            openVoice["MembershipList"] = DataValueFactory.BuildFromDataValue(voiceMembers);
            EventListener.Network.PutEvent(openVoice);
        }
示例#2
0
        private void TimeTick(SimulationEvent e)
        {
            //update time
            if (((IntegerValue)e["Time"]).value % 1000 == 0)
            {
                time = ((IntegerValue)e["Time"]).value / 1000; // time is in ms, we want seconds
            }

            /*
             * "Time" is an attribute of all events.  The SimulationModel.xml file lists all of the top-level attributes for each event.
             * Certain events have an additional "Attribute" attribute, which contains a key-value pair collection of additional attributes.
             * See RevealObject for an example of this.
             */
            if (((IntegerValue)e["Time"]).value == 1000)
            {
                InitializeAllScores();
            }
            SimulationObjectProxy obProx;

            foreach (string id in objectProxies.Keys)
            {
                obProx = objectProxies[id];
                bool            isInSealane       = false;
                bool            movingTowardsPort = false;
                StringListValue slv  = obProx["InActiveRegions"].GetDataValue() as StringListValue;
                LocationValue   dest = obProx["DestinationLocation"].GetDataValue() as LocationValue;
                if (dest.exists)
                {
                    Vec2D     destVec = new Vec2D(dest);
                    Polygon2D p;
                    foreach (Aptima.Asim.DDD.CommonComponents.SimulatorTools.StateDB.ActiveRegion a in StateDB.activeRegions.Values)
                    {
                        if (!a.id.Contains("Entry-"))
                        {
                            continue;
                        }
                        p = new Polygon2D();
                        p = a.poly.Footprint;

                        if (Aptima.Asim.DDD.CommonComponents.SimMathTools.Polygon2D.IsPointInside(p, destVec))
                        {
                            movingTowardsPort = true;
                        }
                    }
                }



                if (slv.strings.Count > 0)
                {
                    isInSealane = true;
                }

                obProx["IsInSeaLane"].SetDataValue(DataValueFactory.BuildBoolean(isInSealane));
                obProx["IsGoingTowardsPort"].SetDataValue(DataValueFactory.BuildBoolean(movingTowardsPort));
            }
        }
示例#3
0
        private void ChangeCanOwn(StringListValue newValue, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];

            if (obj == null)
            {
                return;
            }
            obj["CanOwn"].SetDataValue(newValue);
        }
        /// <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");
                }
            }
        }
示例#5
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);
        }