Beispiel #1
0
        private bool CancelAttack(string attackingObjectID, string targetObjectID, string capabilityName)
        {
            //get attacker proxy
            SimulationObjectProxy attacker = objectProxies[attackingObjectID];

            //find engagement between attacker and target
            AttackCollectionValue attacks = attacker["CurrentAttacks"].GetDataValue() as AttackCollectionValue;
            List <AttackCollectionValue.AttackValue> attacksToRemove = new List <AttackCollectionValue.AttackValue>();

            foreach (AttackCollectionValue.AttackValue att in attacks.GetCurrentAttacksOnTarget(targetObjectID))
            {
                if (att.capabilityName == capabilityName && att.attackingObjectId == attackingObjectID && att.targetObjectId == targetObjectID)
                {
                    //cancel out Transition amount applied for this attack
                    RemoveIntensityFromTargetsVulnerability(targetObjectID, capabilityName, att.appliedIntensity);
                    attacksToRemove.Add(att);
                }
            }

            //for attacker, cancel the attack.
            foreach (AttackCollectionValue.AttackValue atv in attacksToRemove)
            {
                attacks.RemoveAttack(atv);
            }

            attacker["CurrentAttacks"].SetDataValue(attacks);

            return(true);
        }
Beispiel #2
0
        private void ClickHandler(SimulationEvent e)
        {
            String objectID = ((StringValue)e["ObjectID"]).value;
            String dmID     = ((StringValue)e["UserID"]).value;

            if (objectID == string.Empty)
            {
                return;//weird edge case
            }
            if (objectProxies.Count == 0)
            {
                return; //another weird edge case
            }
            SimulationObjectProxy proxy = objectProxies[objectID];

            //AD: TODO Need to only set this if the target object's Item belongs to the clicking DM
            //TODO": add attributes for onCourse, onLocation, booleans for if the objects are in the correct regions and moving towards the correct regions

            if (DMAssignedAsset(dmID, objectID) || IndividualDMIsLoggedIn)
            {
                if (((IntegerValue)proxy["DetectTime"].GetDataValue()).value != -1)
                {
                    return;
                }
                else
                {
                    proxy["DetectTime"].SetDataValue(DataValueFactory.BuildInteger(time));
                    proxy["DetectedBy"].SetDataValue(DataValueFactory.BuildString(((StringValue)e["UserID"]).value));
                }
            }
        }
Beispiel #3
0
        private void TimeTick(SimulationEvent e)
        {
            foreach (StateDB.ActiveRegion region in StateDB.dynamicRegions.Values)
            {
                if (region.linkedObject == "")
                {
                    continue; //don't draw unlinked regions
                }
                SimulationObjectProxy obProx = objectProxies[region.linkedObject];
                //Calculate new absolute poly for region and send ViewPro event
                LocationValue lvLoc = (LocationValue)obProx["Location"].GetDataValue();
                Vec2D         loc   = new Vec2D(lvLoc);
                if (!lvLoc.exists)
                {
                    return; //possible that the tractor object doesn't exist, so don't show it.
                }
                Polygon3D absolutePoly = GetAbsolutePolygon(loc, region.poly.Footprint);
                absolutePoly.TopZ             = region.poly.TopZ;
                absolutePoly.BottomZ          = region.poly.BottomZ;
                region.referencePoint         = loc;
                region.currentAbsolutePolygon = absolutePoly;

                this.SendViewProActiveRegionUpdate(region.id, region.isVisible, region.displayColor, absolutePoly);
            }
        }
Beispiel #4
0
        private void RevealObject(SimulationEvent e)
        {
            String objectID             = ((StringValue)e["ObjectID"]).value;
            SimulationObjectProxy proxy = objectProxies[objectID];

            //initialize values for times to -1
            proxy["DetectTime"].SetDataValue(DataValueFactory.BuildInteger(-1));
            proxy["IdentifyTime"].SetDataValue(DataValueFactory.BuildInteger(-1));
            proxy["TrackingTime"].SetDataValue(DataValueFactory.BuildInteger(-1));
            proxy["DestroyedTime"].SetDataValue(DataValueFactory.BuildInteger(-1));
            proxy["HostileActionTime"].SetDataValue(DataValueFactory.BuildInteger(-1));
            proxy["GroundTruthIFF"].SetDataValue(DataValueFactory.BuildString("Unknown"));
            proxy["UserClassifiedIFF"].SetDataValue(DataValueFactory.BuildString("Unknown"));
            proxy["RevealTime"].SetDataValue(DataValueFactory.BuildInteger(time));
            proxy["TrackedBy"].SetDataValue(DataValueFactory.BuildString(""));

            if (((AttributeCollectionValue)e["Attributes"]).attributes.ContainsKey("DefaultClassification"))
            {
                //has IFF on
                String iff = ((StringValue)((AttributeCollectionValue)e["Attributes"]).attributes["DefaultClassification"]).value;
                proxy["GroundTruthIFF"].SetDataValue(DataValueFactory.BuildString(iff));
                proxy["UserClassifiedIFF"].SetDataValue(DataValueFactory.BuildString(iff));
            }
            else
            {
                String owner = ((StringValue)proxy["OwnerID"].GetDataValue()).value;
                if (owner.ToLower().Contains("pirate"))
                {
                    proxy["GroundTruthIFF"].SetDataValue(DataValueFactory.BuildString("Suspect"));
                }
            }
            proxy["IsInSeaLane"].SetDataValue(DataValueFactory.BuildBoolean(false));
            proxy["IsGoingTowardsPort"].SetDataValue(DataValueFactory.BuildBoolean(false));
        }
Beispiel #5
0
        private void NewObject(SimulationEvent e)
        {
            string id   = ((StringValue)e["ID"]).value;
            string type = ((StringValue)e["ObjectType"]).value;

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

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

            if (v3 != null)
            {
            }
        }
Beispiel #6
0
        private void CancelCapabilityAttack(string capabilityName, string attackingObjectID)
        {
            SimulationObjectProxy attacker = objectProxies[attackingObjectID];

            if (attacker == null)
            {
                return;
            }

            List <AttackCollectionValue.AttackValue> attacksToRemove = new List <AttackCollectionValue.AttackValue>();
            AttackCollectionValue currentAttacks = attacker["CurrentAttacks"].GetDataValue() as AttackCollectionValue;

            foreach (AttackCollectionValue.AttackValue av in currentAttacks.GetCurrentAttacks())
            {
                if (av.capabilityName == capabilityName && attackingObjectID == av.attackingObjectId)
                {
                    attacksToRemove.Add(av);
                }
            }

            foreach (AttackCollectionValue.AttackValue av in attacksToRemove)
            {
                RemoveIntensityFromTargetsVulnerability(av.targetObjectId, av.capabilityName, av.appliedIntensity);
                currentAttacks.RemoveAttack(av);
            }

            attacker["CurrentAttacks"].SetDataValue(currentAttacks);
            attacksToRemove.Clear();
        }
Beispiel #7
0
        private void RevealObject(SimulationEvent e)
        {
            AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"];
            string id = ((StringValue)e["ObjectID"]).value;

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

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


            foreach (string attname in atts.attributes.Keys)
            {
                if (attname == "ID")
                {
                    continue;
                }
                if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner())
                {
                    prox[attname].SetDataValue(atts[attname]);
                }
            }
        }
Beispiel #8
0
        private void UpdateAttackTimeWindow(SimulationEvent e)
        {
            string targetObjectId    = ((StringValue)e["TargetObjectID"]).value;
            string attackingObjectId = ((StringValue)e["AttackingObjectID"]).value;
            string capabilityName    = ((StringValue)e["CapabilityName"]).value;
            int    newAttackWindow   = ((IntegerValue)e["NewAttackTimeWindow"]).value;

            //get attacker proxy
            SimulationObjectProxy attacker = objectProxies[attackingObjectId];
            AttackCollectionValue attacks  = attacker["CurrentAttacks"].GetDataValue() as AttackCollectionValue;

            //find engagement between attacker and target
            AttackCollectionValue.AttackValue av = null;
            foreach (AttackCollectionValue.AttackValue att in attacks.GetCurrentAttacksOnTarget(targetObjectId))
            {
                if (att.capabilityName == capabilityName && att.attackingObjectId == attackingObjectId && att.targetObjectId == targetObjectId)
                {
                    av = att;
                    break;
                }
            }

            if (av != null)
            {
                //set the CurrentAttacks time window accordingly
                av.attackTimeWindow = newAttackWindow;

                attacker["CurrentAttacks"].SetDataValue(attacks);
            }
        }
Beispiel #9
0
        private void ChangeObjectCapability(CapabilityValue newCapabilitySet, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];

            if (obj == null)
            {
                return;
            }

            CapabilityValue previousCapabilityValue = obj["Capability"].GetDataValue() as CapabilityValue;
            List <string>   previousCapabilityNames = previousCapabilityValue.GetCapabilityNames();
            List <string>   newCapabilityNames      = newCapabilitySet.GetCapabilityNames();
            List <string>   missingCapabilities     = new List <string>();

            foreach (string capName in previousCapabilityNames)
            {
                if (!newCapabilityNames.Contains(capName))
                {
                    if (!missingCapabilities.Contains(capName))
                    {
                        missingCapabilities.Add(capName);
                    }
                }
            }
            foreach (string capName in missingCapabilities)
            {
                CancelCapabilityAttack(capName, objectID);
            }

            obj["Capability"].SetDataValue(newCapabilitySet);
            missingCapabilities.Clear();
            newCapabilityNames.Clear();
            previousCapabilityNames.Clear();
        }
        private void NewObject(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies(); // update my objects record
            // initialize any object values I need to.
            string id   = ((StringValue)e["ID"]).value;
            string type = ((StringValue)e["ObjectType"]).value;

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

            if (prox == null)
            {
                return;
            }
            if (!objectProxies.ContainsKey(id))
            {
                objectProxies.Add(id, prox);
            }
            else
            {
                objectProxies[id] = prox;
            }
        }
Beispiel #11
0
        private void StateChange(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies(); // update my objects record
            string id = ((StringValue)e["ObjectID"]).value;
            SimulationObjectProxy prox = null; // objectProxies[id];

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

            string newState = ((StringValue)e["NewState"]).value;

            DataValue dv = prox["StateTable"].GetDataValue();

            if (((StateTableValue)dv).states.ContainsKey(newState))
            {
                DataValue dv2 = ((StateTableValue)dv).states[newState];
                foreach (string attname in ((AttributeCollectionValue)dv2).attributes.Keys)
                {
                    if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner())
                    {
                        prox[attname].SetDataValue(((AttributeCollectionValue)dv2).attributes[attname]);
                    }
                }
            }
        }
Beispiel #12
0
        private void RevealObject(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies(); // update my objects record
            AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"];

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

                // initialize any object values I need to.

                foreach (string attname in atts.attributes.Keys)
                {
                    if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner())
                    {
                        prox[attname].SetDataValue(atts[attname]);
                    }
                }
            }
        }
Beispiel #13
0
        private void ForceUpdateObjectAttribute(SimulationEvent e)
        {
            string objectId      = ((StringValue)e["ObjectID"]).value;
            string attributeName = ((StringValue)e["AttributeName"]).value;

            if (!objectProxies.ContainsKey(objectId))
            {
                return;
            }
            try
            {
                if (!objectProxies[objectId].GetKeys().Contains(attributeName))
                {
                    return;
                }
                if (!objectProxies[objectId][attributeName].IsOwner())
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                return;
            }

            DataValue attributeValue = e["AttributeValue"];

            if (attributeValue.dataType != "WrapperType")
            {
                return;
            }
            attributeValue = ((WrapperValue)attributeValue).value;
            SimulationObjectProxy obj = null;

            //depending on the attribute, you might have specific functionality
            switch (attributeName)
            {
            case "Intent":
                ChangeIntent(attributeValue as StringValue, objectId);
                break;

            default:
                break;
            }

            //try
            //{
            //    obj[attributeName].SetDataValue(attributeValue);
            //}
            //catch (Exception ex)
            //{
            //    return;
            //}

            attributeValue = null;
            obj            = null;
        }
Beispiel #14
0
        private void ChangeEngagementDuration(IntegerValue newEngagementDuration, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];

            if (obj == null)
            {
                return;
            }
            obj["EngagementDuration"].SetDataValue(newEngagementDuration);
        }
Beispiel #15
0
        private void ChangeObjectFuelRate(DoubleValue newRate, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];

            if (obj == null)
            {
                return;
            }
            obj["FuelConsumptionRate"].SetDataValue(newRate);
        }
Beispiel #16
0
        private void ChangeCanOwn(StringListValue newValue, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];

            if (obj == null)
            {
                return;
            }
            obj["CanOwn"].SetDataValue(newValue);
        }
Beispiel #17
0
        private void ChangeObjectIcon(StringValue newIconName, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];

            if (obj == null)
            {
                return;
            }
            obj["IconName"].SetDataValue(newIconName);
        }
Beispiel #18
0
        private void ChangeObjectFuelDepleteState(StringValue newState, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];

            if (obj == null)
            {
                return;
            }
            obj["FuelDepletionState"].SetDataValue(newState);
        }
Beispiel #19
0
        private void ChangeRemoveOnDestruction(BooleanValue newValue, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];

            if (obj == null)
            {
                return;
            }
            obj["RemoveOnDestruction"].SetDataValue(newValue);
        }
Beispiel #20
0
        private void ChangeIntent(StringValue newIntent, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];

            if (obj == null)
            {
                return;
            }
            obj["Intent"].SetDataValue(newIntent);
        }
Beispiel #21
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);
        }
Beispiel #22
0
        private void TrackRemoved(SimulationEvent e)
        {
            if (objectProxies.Count == 0)
            {
                return; //another weird edge case
            }
            String objectID             = ((StringValue)e["ObjectID"]).value;
            SimulationObjectProxy proxy = objectProxies[objectID];

            proxy["TrackedBy"].SetDataValue(DataValueFactory.BuildString(""));
        }
Beispiel #23
0
        private void SelfDefenseAttackStarted(SimulationEvent e)
        {
            //<SelfDefenseAttackStarted>
            //<Parameter><Name>AttackerObjectID</Name><Value><StringType>3734</StringType></Value></Parameter>
            //<Parameter><Name>TargetObjectID</Name><Value><StringType>2213</StringType></Value></Parameter>
            //<Parameter><Name>Time</Name><Value><IntegerType>62000</IntegerType></Value></Parameter></SelfDefenseAttackStarted>
            String attackerID = ((StringValue)e["AttackerObjectID"]).value;
            String targetID   = ((StringValue)e["TargetObjectID"]).value;
            String hash       = attackerID + "_" + targetID;

            if (_attackTargetHashes.Contains(hash))
            {
                return;//only handle one attack stimuli from one target-attacker pair
            }
            SimulationObjectProxy attProx  = objectProxies[attackerID];
            SimulationObjectProxy targProx = objectProxies[targetID];

            if (attProx == null || targProx == null)
            {
                return;
            }
            //if attacker is owned by pirate DM, send stimulus event.
            if (((StringValue)attProx["OwnerID"].GetDataValue()).value == "Pirate DM")
            {
                //i don't know an item id unfortunately.
                String itemID = "UNK?";
                String dmID   = "";
                String type   = "Attack";
                if (objectAssignmentList.ContainsKey(attackerID))
                {
                    dmID = objectAssignmentList[attackerID];
                }
                ItemInfo lastItem = null;
                if (mostRecentItemsForStimulators.ContainsKey(attackerID))
                {
                    lastItem = mostRecentItemsForStimulators[attackerID];// = new ItemInfo(itemID, userId, objectId, ff_dif, tt_dif, StimulusType, "", time);
                }
                else
                {
                    lastItem = new ItemInfo(itemID, dmID, attackerID, 0.0, 0.0, type, targetID, 0);
                }

                SimulationEvent ev = SimulationEventFactory.BuildEvent(ref simModel, "SEAMATE_StimulusSent");
                ((StringValue)ev["DM_ID"]).value        = lastItem.userId;
                ((StringValue)ev["ItemID"]).value       = lastItem.itemID;
                ((StringValue)ev["ObjectID"]).value     = lastItem.objectId;
                ((StringValue)ev["StimulusType"]).value = type;
                ((DoubleValue)ev["FFDifficulty"]).value = lastItem.ff_dif;
                ((DoubleValue)ev["TTDifficulty"]).value = lastItem.tt_dif;
                distributor.PutEvent(ev);
                _attackTargetHashes.Add(hash);
            }
        }
Beispiel #24
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));
        }
Beispiel #25
0
        private void TrackAdded(SimulationEvent e)
        {
            if (objectProxies.Count == 0)
            {
                return; //another weird edge case
            }
            String objectID             = ((StringValue)e["ObjectID"]).value;
            SimulationObjectProxy proxy = objectProxies[objectID];

            string id = ((StringValue)e["UserID"]).value;

            proxy["TrackedBy"].SetDataValue(DataValueFactory.BuildString(id));
            proxy["TrackingTime"].SetDataValue(DataValueFactory.BuildInteger(time));
        }
Beispiel #26
0
        private void AttackObject(SimulationEvent e)
        {
            String objectID                   = ((StringValue)e["ObjectID"]).value;
            SimulationObjectProxy proxy       = objectProxies[objectID];
            String targetID                   = ((StringValue)e["TargetObjectID"]).value;
            SimulationObjectProxy targetProxy = objectProxies[targetID];

            // It's a sea vessel if it's not a BAMS or Firescout
            String className = ((StringValue)proxy["ClassName"].GetDataValue()).value;

            if (className != "BAMS" && className != "Firescout")
            {
                proxy["HostileActionTime"].SetDataValue(DataValueFactory.BuildInteger(time));
                proxy["GroundTruthIFF"].SetDataValue(DataValueFactory.BuildString("Hostile"));
            }
        }
Beispiel #27
0
        private SimulationObjectProxy GetObjectProxy(string id)
        {
            SimulationObjectProxy prox = null;

            try
            {
                prox = objectProxies[id];
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("Error retrieving id = '{0}' from object proxies; {1}", id, ex.Message), ex);
                return(null);
            }

            return(prox);
        }
Beispiel #28
0
        private void NewObject(SimulationEvent e)
        {
            //objectProxies = bbClient.GetObjectProxies(); // update my objects record

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

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

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

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

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

                    // initialize any object values I own.

                    foreach (string attname in atts.attributes.Keys)
                    {
                        if (proxi.GetKeys().Contains(attname) && proxi[attname].IsOwner())
                        {
                            proxi[attname].SetDataValue(atts[attname]);
                        }
                    }
                }
            }
        }
Beispiel #29
0
        private void RemoveIntensityFromTargetsVulnerability(String targetObjectID, String capabilityName, int intensityToReduceBy)
        {
            //get target proxy
            SimulationObjectProxy target = objectProxies[targetObjectID];

            //get vulnerabilities
            VulnerabilityValue vv = target["Vulnerability"].GetDataValue() as VulnerabilityValue;

            //remove effect from vulnerability
            foreach (VulnerabilityValue.Transition t in vv.transitions)
            {
                if (t.RemoveSingleEffect(capabilityName, intensityToReduceBy))
                {
                    bool removed = true;// send message instead?
                }
            }
            //save vulnerabilities
            target["Vulnerability"].SetDataValue(vv);
        }
Beispiel #30
0
        private void ChangeObjectState(StringValue newState, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];

            if (obj == null)
            {
                return;
            }
            string          newStateName      = newState.value;
            StateTableValue currentStateTable = obj["StateTable"].GetDataValue() as StateTableValue;

            foreach (String stateName in currentStateTable.states.Keys)
            {
                if (stateName == newStateName)
                {
                    SendStateChangeEvent(objectID, newStateName);
                }
            }
        }