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]); } } } }
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]); } } }
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]); } } } }
/// <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); } } } } }
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]); } } } } }
private void ChangeObjectState(string id, string newState) { SimulationObjectProxy prox = null; // objectProxies[id]; prox = GetObjectProxy(id); if (prox == null) { return; } 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]); } } } }
private void StateChange(SimulationEvent e) { 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]; //AD: Added state to attributes DataValue temp = new StringValue(); ((StringValue)temp).value = newState; ((AttributeCollectionValue)dv2).attributes["State"] = temp; //AD foreach (string attname in ((AttributeCollectionValue)dv2).attributes.Keys) { if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner()) { prox[attname].SetDataValue(((AttributeCollectionValue)dv2).attributes[attname]); if (attname == "Sensors") { double maxSensor = -1.0; SensorArrayValue sav = ((AttributeCollectionValue)dv2).attributes[attname] as SensorArrayValue; foreach (SensorValue sv in sav.sensors) { maxSensor = Math.Max(maxSensor, sv.maxRange); } if (maxSensor >= 0) { ObjectDistances.UpdateObjectSensorRange(id, maxSensor); } } } } } CustomAttributesValue cav = prox["CustomAttributes"].GetDataValue() as CustomAttributesValue; Dictionary <string, DataValue> x = new Dictionary <string, DataValue>(); if (cav != null) { x = cav.attributes; } EmitterValue em = (EmitterValue)prox["Emitters"].GetDataValue(); foreach (string attName in em.attIsEngram.Keys) { if (em.attIsEngram[attName]) { if (StateDB.engrams.ContainsKey(attName)) { x[attName] = DataValueFactory.BuildString(StateDB.engrams[attName].engramValue); } } } prox["CustomAttributes"].SetDataValue(DataValueFactory.BuildCustomAttributes(x)); }
private void RevealObject(SimulationEvent e) { AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"]; string id = ((StringValue)e["ObjectID"]).value; SimulationObjectProxy prox = null; prox = GetObjectProxy(id); if (prox == null) { return; } //Set State info? //AD: This is kind of a quick fix. Gabe would have a better idea on a more permanent //solution. DataValue stv = new DataValue(); stv = prox["StateTable"].GetDataValue(); Dictionary <string, DataValue> tempDict = ((StateTableValue)stv).states; tempDict = ((AttributeCollectionValue)tempDict[((StringValue)atts["State"]).value]).attributes; foreach (KeyValuePair <String, DataValue> kvp in tempDict) { if (!atts.attributes.ContainsKey(kvp.Key)) {//if att exists in atts, it should NOT overwrite reveal attributes. atts.attributes.Add(kvp.Key, kvp.Value); } } ////AD foreach (string attname in atts.attributes.Keys) { if (attname == "ID") { continue; } if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner()) { prox[attname].SetDataValue(atts[attname]); if (attname == "Sensors") { double maxSensor = -1.0; SensorArrayValue sav = atts[attname] as SensorArrayValue; foreach (SensorValue sv in sav.sensors) { maxSensor = Math.Max(maxSensor, sv.maxRange); } if (maxSensor >= 0) { ObjectDistances.UpdateObjectSensorRange(id, maxSensor); } } } } Dictionary <string, DataValue> x = new Dictionary <string, DataValue>(); EmitterValue em = (EmitterValue)prox["Emitters"].GetDataValue(); foreach (string attName in em.attIsEngram.Keys) { if (em.attIsEngram[attName]) { if (StateDB.engrams.ContainsKey(attName)) { x[attName] = DataValueFactory.BuildString(StateDB.engrams[attName].engramValue); } } } prox["CustomAttributes"].SetDataValue(DataValueFactory.BuildCustomAttributes(x)); }
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"]; string id2 = ((StringValue)e["ID"]).value; SimulationObjectProxy proxi = objectProxies[id2]; if (proxi.GetKeys().Contains("StateTable")) { proxi["StateTable"].SetDataValue(e["StateTable"]); } if (objectProxies.ContainsKey(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]); if (attname == "Sensors") { double maxSensor = -1.0; SensorArrayValue sav = atts[attname] as SensorArrayValue; foreach (SensorValue sv in sav.sensors) { maxSensor = Math.Max(maxSensor, sv.maxRange); } if (maxSensor >= 0) { ObjectDistances.UpdateObjectSensorRange(id2, maxSensor); } } } } } }
private void RevealObject(SimulationEvent e) { bool dockedToParent; bool isWeapon; //objectProxies = bbClient.GetObjectProxies(); // update my objects record 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 (prox.GetKeys().Contains(attname) && prox[attname].IsOwner()) { prox[attname].SetDataValue(atts[attname]); } } SimulationObjectProxy parentProx = null; string parentID = null; if (atts.attributes.ContainsKey("ParentObjectID")) { parentID = ((StringValue)atts.attributes["ParentObjectID"]).value; if (objectProxies.ContainsKey(parentID)) { parentProx = objectProxies[parentID]; } } if (parentProx != null) { DataValue dv = parentProx["ChildObjects"].GetDataValue(); ((StringListValue)dv).strings.Add(id); parentProx["ChildObjects"].SetDataValue(dv); dockedToParent = ((BooleanValue)prox["DockedToParent"].GetDataValue()).value; isWeapon = ((BooleanValue)prox["IsWeapon"].GetDataValue()).value; if (dockedToParent) { if (isWeapon) { dv = parentProx["DockedWeapons"].GetDataValue(); ((StringListValue)dv).strings.Add(id); parentProx["DockedWeapons"].SetDataValue(dv); } else { dv = parentProx["DockedObjects"].GetDataValue(); ((StringListValue)dv).strings.Add(id); parentProx["DockedObjects"].SetDataValue(dv); } } } }
private void UpdateObjectsList() { if (!objectStatus.Checked) { return; } if (bbClient == null) { objectListBox.Items.Clear(); return; } Dictionary <string, SimulationObjectProxy> objectPoxies = bbClient.GetObjectProxies(); //objectListBox.Items.Clear(); foreach (string id in objectPoxies.Keys) { if (!objectListBox.Items.Contains(id)) { objectListBox.Items.Add(id); } } List <string> idsToRemove = new List <string>(); foreach (string id2 in objectListBox.Items) { if (!objectPoxies.ContainsKey(id2)) { idsToRemove.Add(id2); //objectListBox.Items.Remove(id2); } } foreach (string id4 in idsToRemove) { objectListBox.Items.Remove(id4); } //objectAttributeList.Items.Clear(); //treeView1.Nodes.Clear(); foreach (TreeNode tn in treeView1.Nodes) { if (tn.Name != (string)objectListBox.SelectedItem) { treeView1.Nodes.Remove(tn); } } SimulationObjectProxy prox = null; if (objectListBox.SelectedItem != null) { string id3 = (string)objectListBox.SelectedItem; if (objectPoxies.ContainsKey(id3)) { prox = objectPoxies[id3]; string objectType = prox.GetObjectType(); Dictionary <string, string> treeData = new Dictionary <string, string>(); string s; DataValue dv; foreach (string key in prox.GetKeys()) { dv = prox[key].GetDataValue(); s = DataValueFactory.ToString(dv); treeData[key] = key + " = " + s; } if (treeView1.Nodes.ContainsKey(id3)) { foreach (string key in treeData.Keys) { treeView1.Nodes[id3].Nodes[key].Text = treeData[key]; } } else { treeView1.Nodes.Add(id3.ToString(), objectType + ": " + id3); foreach (string key in treeData.Keys) { treeView1.Nodes[id3.ToString()].Nodes.Add(key, treeData[key]); } treeView1.Nodes[id3.ToString()].Expand(); } } } //treeView1.Update(); //treeView1.Refresh(); }
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 (atts.attributes.ContainsKey("ID")) //REMOVE WHEN DONE MIGRATING REVEAL { string id2 = ((StringValue)atts["ID"]).value; if (objectProxies.ContainsKey(id2)) { SimulationObjectProxy proxi = objectProxies[id2]; foreach (string attname in atts.attributes.Keys) { if (proxi.GetKeys().Contains(attname) && proxi[attname].IsOwner()) { proxi[attname].SetDataValue(atts[attname]); } } } } /* * if (((StringValue)e["ObjectType"]).value == "Team") * { * StateDB.Team t = new StateDB.Team(((StringValue)e["ID"]).value, * ((StringListValue)((AttributeCollectionValue)e["Attributes"]).attributes["TeamHostility"]).strings); * * StateDB.teams[t.id] = t; * } * else if (((StringValue)e["ObjectType"]).value == "DecisionMaker") * { * string teamID = ((StringValue)((AttributeCollectionValue)e["Attributes"]).attributes["TeamMember"]).value; * StateDB.DecisionMaker d = new StateDB.DecisionMaker(((StringValue)e["ID"]).value, * StateDB.teams.ContainsKey(teamID) ? StateDB.teams[teamID] : null); * * StateDB.decisionMakers[d.id] = d; * }*/ }