internal static Snak newFromArray(JsonObject data) { if (data.get("snaktype") == null || data.get("property") == null) { throw new ArgumentException("Invalid Snak serialization", "data"); } var dataValue = data.get("datavalue"); if (dataValue != null) { return(new Snak( data.get("snaktype").asString(), EntityId.newFromPrefixedId(data.get("property").asString()), DataValueFactory.newFromArray(dataValue.asObject()) )); } else { return(new Snak( data.get("snaktype").asString(), EntityId.newFromPrefixedId(data.get("property").asString()), null )); } }
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); }
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)); }
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)); } } }
/// <summary> /// This event is broadcast out to each client. That client will attempt to put the object in motion, but will only /// succeed if the object already exists in its playfield. /// </summary> /// <param name="objectID"></param> /// <param name="ownerID"></param> /// <param name="location"></param> /// <param name="desLocation"></param> /// <param name="maxSpeed"></param> /// <param name="throttle"></param> /// <param name="time"></param> /// <param name="iconName"></param> /// <param name="isWeapon"></param> private void SendViewProMotionUpdate(string objectID, string ownerID, LocationValue location, LocationValue desLocation, double maxSpeed, double throttle, string iconName, bool isWeapon, double activeRegionSpeedMultiplier) { SimulationEvent vpmu = null; vpmu = SimulationEventFactory.BuildEvent(ref simModel, "ViewProMotionUpdate"); vpmu["ObjectID"] = DataValueFactory.BuildString(objectID); vpmu["OwnerID"] = DataValueFactory.BuildString(ownerID); vpmu["Location"] = location; vpmu["DestinationLocation"] = desLocation; //if (objectID == "Fighter01_Troop_2") //{ // Console.Out.Write(String.Format("\n{0} is moving at {1}*{2}\n", objectID, maxSpeed, activeRegionSpeedMultiplier)); //} vpmu["MaximumSpeed"] = DataValueFactory.BuildDouble(maxSpeed * activeRegionSpeedMultiplier); vpmu["Throttle"] = DataValueFactory.BuildDouble(throttle); vpmu["Time"] = DataValueFactory.BuildInteger(currentTick); vpmu["IconName"] = DataValueFactory.BuildString(iconName); //add label color to the mix vpmu["LabelColor"] = DataValueFactory.BuildInteger(dmColorMapping[ownerID]); vpmu["IsWeapon"] = DataValueFactory.BuildBoolean(isWeapon); distClient.PutEvent(vpmu); if (!movingObjects.Contains(objectID) && !DataValueFactory.CompareDataValues(location, desLocation)) { movingObjects.Add(objectID); } }
public void save(string summary) { if (!this.changes.isEmpty()) { if (this.changes.get("mainsnak") != null) { JsonObject change = this.changes.get("mainsnak").asObject(); if (change.get("snaktype") == null || change.get("property") == null) { throw new Exception("The main snak does not have required data"); } DataValue value = change.get("datavalue") == null ? null : DataValueFactory.newFromArray(change.get("datavalue").asObject()); JsonObject result; if (this.id == null) { result = this.entity.api.createClaim(this.entity.id.getPrefixedId(), change.get("snaktype").asString(), change.get("property").asString(), value, this.entity.lastRevisionId, summary); } else { result = this.entity.api.setClaimValue(this.id, change.get("snaktype").asString(), value, this.entity.lastRevisionId, summary); } this.updateDataFromResult(result); this.changes.removeAt("mainsnak"); } } }
/// <summary> /// For a given decision maker, get all sensor ranges which they currently have (max range per sensor object) /// </summary> /// <param name="dmID"></param> /// <returns></returns> public List <SensorRange> GetDecisionMakersSensorRanges(String dmID) { List <SensorRange> ranges = new List <SensorRange>(); lock (GroundTruthLock) { DMView view = _dddConnection.GetDMView(dmID); SensorRange range = null; if (view != null) { foreach (String s in view.MyObjects.Keys) { if (view.MyObjects[s].Location.exists) { double maxRange = 0; foreach (SensorValue sv in view.MyObjects[s].Sensors.sensors) { if (sv.maxRange > maxRange) { maxRange = sv.maxRange; } } range = new SensorRange(DataValueFactory.BuildFromDataValue(view.MyObjects[s].Location) as LocationValue, maxRange); ranges.Add(range); } } } } return(ranges); }
/// <summary> /// This method will send out a ViewProInitializeObject event to a specific client. /// This event will have that player add this object to their playfield. Once the /// object is in the playfield, it is able to be interacted with. /// </summary> /// <param name="targetPlayerID">Unique ID of the player recieving this event.</param> /// <param name="objectID">Unique ID of the object being revealed.</param> /// <param name="location">Location at which to display this object.</param> /// <param name="iconName">Icon file name used to display to user.</param> /// <param name="ownerID">Unique ID of the owner of the object.</param> private void SendViewProInitializeObject(string targetPlayerID, string objectID, LocationValue location, string iconName, string ownerID, bool isWeapon) { if (!activeDMs.Contains(targetPlayerID)) { return; } if (!location.exists) { return; } SimulationEvent initEvent = SimulationEventFactory.BuildEvent(ref simModel, "ViewProInitializeObject"); initEvent["Time"] = DataValueFactory.BuildInteger(currentTick); initEvent["TargetPlayer"] = DataValueFactory.BuildString(targetPlayerID); initEvent["ObjectID"] = DataValueFactory.BuildString(objectID); initEvent["Location"] = location; initEvent["OwnerID"] = DataValueFactory.BuildString(ownerID); initEvent["IsWeapon"] = DataValueFactory.BuildBoolean(isWeapon); initEvent["LabelColor"] = DataValueFactory.BuildInteger(dmColorMapping[ownerID]); String classification = GetClassificationForDM(objectID, targetPlayerID); String overrideIcon = GetClassificationBasedIcon(objectID, classification); initEvent["CurrentClassification"] = DataValueFactory.BuildString(classification); if (overrideIcon != String.Empty) { initEvent["IconName"] = DataValueFactory.BuildString(overrideIcon); } else { initEvent["IconName"] = DataValueFactory.BuildString(iconName); } distClient.PutEvent(initEvent); }
protected void SelfDefense(SimulationEvent ev) //Set throttle of target to 0 when pirate attacks (the "attack" is actually a self defense attack) { String targetID = ((StringValue)ev["TargetObjectID"]).value; _dddConnection.SendObjectAttributeUpdateEvent(targetID, "Throttle", DataValueFactory.BuildDouble(0)); }
protected void MoveDone(SimulationEvent ev) {//ObjectID, Reason String id = ((StringValue)ev["ObjectID"]).value; if (!_revealedObjects.ContainsKey(id)) { return; } AttributeCollectionValue atts = new AttributeCollectionValue(); atts.attributes.Add("DestinationLocation", new LocationValue()); atts.attributes.Add("Throttle", DataValueFactory.BuildDouble(0)); String owner = _revealedObjects[id].Owner; foreach (PolygonValue region in GetAllEntryRegions()) { if (Polygon2D.IsPointInside(new Polygon2D(region), new Vec2D(GetSeamateObject(id).Location)) && owner == "Merchant DM") { Console.WriteLine("Detected vessel " + id + " ending move in entry region, turning state to Dead."); //atts.attributes.Add("State", DataValueFactory.BuildString("Dead")); _dddConnection.SendStateChange(id, "Dead"); } } //LocationValue destLoc = as LocationValue; _revealedObjects[id].SetAttributes(atts); }
public override SimulationEvent ToSimulationEvent(ref SimulationModelInfo simModel) { SimulationEvent ev = SimulationEventFactory.BuildEvent(ref simModel, EVENTTYPE); AttributeCollectionValue attributes = new AttributeCollectionValue(); attributes.attributes.Add("Location", this.Location); attributes.attributes.Add("State", DataValueFactory.BuildString(this.State)); if (ObjectType != null && ObjectType != String.Empty) { attributes.attributes.Add("ClassName", DataValueFactory.BuildString(ObjectType)); } if (OwnerID != null && OwnerID != String.Empty) { attributes.attributes.Add("OwnerID", DataValueFactory.BuildString(OwnerID)); } if (StartupParameters != null) { foreach (String s in StartupParameters.Keys) { attributes.attributes.Add(s, StartupParameters[s]); } } //do stuff ((StringValue)ev["ObjectID"]).value = this.ObjectID; ev["Attributes"] = attributes; return(ev); }
private void SendOutScenarioInfo(string playerID, string terminalID) { SimulationEvent e = SimulationEventFactory.BuildEvent(ref simModelInfo, "HandshakeInitializeGUI"); e["PlayerID"] = DataValueFactory.BuildString(playerID); //e["TerminalID"] = DataValueFactory.BuildString(dmToTerminalMap[playerID]); e["TerminalID"] = DataValueFactory.BuildString(terminalID); e["ScenarioInfo"] = DataValueFactory.BuildString("BASIC SCENARIO INFO **PLACEHOLDER**"); e["ScenarioName"] = DataValueFactory.BuildString(scenarioName); e["ScenarioDescription"] = DataValueFactory.BuildString(scenarioDescription); e["MapName"] = DataValueFactory.BuildString(mapName); e["UTMNorthing"] = DataValueFactory.BuildDouble(northing); e["UTMEasting"] = DataValueFactory.BuildDouble(easting); e["HorizontalPixelsPerMeter"] = DataValueFactory.BuildDouble(horizMetersPerPixel); e["VerticalPixelsPerMeter"] = DataValueFactory.BuildDouble(vertMetersPerPixel); e["PlayerBrief"] = DataValueFactory.BuildString(allDMs[playerID].briefing); e["IconLibrary"] = DataValueFactory.BuildString(iconLibrary); e["VoiceChatEnabled"] = DataValueFactory.BuildBoolean(voiceChatEnabled); e["VoiceChatServerName"] = DataValueFactory.BuildString(voiceChatServerName); e["VoiceChatServerPort"] = DataValueFactory.BuildInteger(voiceChatServerPort); e["VoiceChatUserPassword"] = DataValueFactory.BuildString(voiceChatPassword); e["IsObserver"] = DataValueFactory.BuildBoolean(allDMs[playerID].isObserver); e["IsForkReplay"] = DataValueFactory.BuildBoolean(isForkReplay); e["DefaultDisplayLabels"] = DataValueFactory.BuildString(displayLabels); e["DefaultDisplayTags"] = DataValueFactory.BuildString(displayTags); server.PutEvent(e); }
public void InitializeGUIDone(SimulationEvent e) { //event contains PlayerID string playerID; string loginType; try { playerID = ((StringValue)e["PlayerID"]).value; loginType = ((StringValue)e["LoginType"]).value; } catch { throw new Exception("Player ID does not exist in this event."); } if (loginType == "FULL") { //add to DMs ready a true val for the specified dm dmsIsReady[playerID] = true; allDMs[playerID].availability = DecisionMaker.Availability.READY; Thread.Sleep(100);//delay so client can synch up SendSystemMessageToAll(String.Format("SYSTEM: New user ({0}) has joined the simulation.", playerID)); SimulationEvent player = SimulationEventFactory.BuildEvent(ref simModelInfo, "PlayerControl"); ((StringValue)player["DecisionMakerID"]).value = playerID; ((StringValue)player["ControlledBy"]).value = "HUMAN"; server.PutEvent(player); SimulationEvent assetTransferEnabled = SimulationEventFactory.BuildEvent(ref simModelInfo, "ClientSideAssetTransferAllowed"); assetTransferEnabled["EnableAssetTransfer"] = DataValueFactory.BuildBoolean(enableAssetTransfers); server.PutEvent(assetTransferEnabled); ////The following section is in place for clients that join after a CreateChatRoom ////Event has been sent out. Without this, new tabbed chat rooms would not open ////if the room was created before they joined. foreach (SimulationEvent ev in listOfChatRoomCreates.Values) { if (((StringListValue)ev["MembershipList"]).strings.Contains(playerID)) { server.PutEvent(ev); } } foreach (SimulationEvent ev in listOfWhiteboardRoomCreates.Values) { if (((StringListValue)ev["MembershipList"]).strings.Contains(playerID)) { server.PutEvent(ev); } } ////The following section is in place for clients that join after a CreateVoiceChannel ////event is sent out foreach (SimulationEvent ev in listOfVoiceChannelCreates.Values) { if (((StringListValue)ev["MembershipList"]).strings.Contains(playerID)) { server.PutEvent(ev); } } } }
public static void Tick(int tick) { if (tick > nextEventAt + 2000) { nextEventAt = tick + 1000 * (randInt(13, 37)); simModel = modelReader.readModel("C:\\Program Files\\Aptima\\DDD 4.0\\Client\\SimulationModel.xml"); } else if (Math.Truncate(tick / 1000.0) == Math.Truncate(nextEventAt / 1000.0)) {// do something now // first update nextEventTime nextEventAt += 1000 * randInt(3, 20); if (allUnits.Keys.Count > 0) { string[] keyArray = new string[allUnits.Keys.Count]; allUnits.Keys.CopyTo(keyArray, 0); string unitToUse = keyArray[randInt(keyArray.Length)]; SimulationEvent simEvent; switch (randInt(2)) { case 0: //move a unit Location whereToGo = allUnits[unitToUse].newLocation(); Console.WriteLine("Moving " + unitToUse + " from (" + allUnits[unitToUse].position.X + "," + allUnits[unitToUse].position.Y + ") to (" + whereToGo.X.ToString() + "," + whereToGo.Y.ToString() + ")"); // Generate a moveObject request simEvent = SimulationEventFactory.BuildEvent(ref simModel, "MoveObjectRequest"); simEvent["UserID"] = DataValueFactory.BuildString("red dm"); simEvent["ObjectID"] = DataValueFactory.BuildString(unitToUse); simEvent["DestinationLocation"] = DataValueFactory.BuildLocation((double)whereToGo.X, (double)whereToGo.Y, 0.0, true); simEvent["Throttle"] = DataValueFactory.BuildDouble(randInt(75, 101) / 100.0); simEvent["Time"] = DataValueFactory.BuildInteger(tick + 3000);// '+3000" is not magic -- just a clumsy attempt to avoid a race condition EventGetter.Network.PutEvent(simEvent); break; case 1: //attack a unit string myTarget = Target.GetRandom(); if ("" != myTarget) { Console.WriteLine("Using " + unitToUse + " to attack " + myTarget); //generate an attack request simEvent = SimulationEventFactory.BuildEvent(ref simModel, "AttackObjectRequest"); simEvent["UserID"] = DataValueFactory.BuildString("red dm"); simEvent["ObjectID"] = DataValueFactory.BuildString(unitToUse); simEvent["TargetObjectID"] = DataValueFactory.BuildString(myTarget); simEvent["CapabilityName"] = DataValueFactory.BuildString("Missile"); simEvent["Time"] = DataValueFactory.BuildInteger(tick + 3000);// '+3000" is not magic -- just a clumsy attempt to avoid a race condition EventGetter.Network.PutEvent(simEvent); } break; } } } }
private void SendStateChangeEvent(string objectID, string newStateName) { SimulationEvent stateChange = SimulationEventFactory.BuildEvent(ref simModel, "StateChange"); stateChange["ObjectID"] = DataValueFactory.BuildString(objectID); stateChange["NewState"] = DataValueFactory.BuildString(newStateName); distClient.PutEvent(stateChange); }
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)); } }
private void SendSystemErrorMessage(string text, string playerID) { SimulationEvent e = SimulationEventFactory.BuildEvent(ref simModelInfo, "SystemMessage"); e["Message"] = DataValueFactory.BuildString(text); e["TextColor"] = DataValueFactory.BuildInteger(-65536);//(System.Drawing.Color.Red.ToArgb()); e["PlayerID"] = DataValueFactory.BuildString(playerID); server.PutEvent(e); }
private void SendSelfDefenseAttackStarted(string attacker, string target) { SimulationEvent send = SimulationEventFactory.BuildEvent(ref simModel, "SelfDefenseAttackStarted"); send["AttackerObjectID"] = DataValueFactory.BuildString(attacker); send["TargetObjectID"] = DataValueFactory.BuildString(target); send["Time"] = DataValueFactory.BuildInteger(time); distClient.PutEvent(send); }
private void ResetObjectMovement(string objectID, double throttle, LocationValue destination) { SimulationEvent moveObject = SimulationEventFactory.BuildEvent(ref simModel, "MoveObject"); moveObject["ObjectID"] = DataValueFactory.BuildString(objectID); moveObject["DestinationLocation"] = destination; moveObject["Throttle"] = DataValueFactory.BuildDouble(throttle); distClient.PutEvent(moveObject); }
private void SendTrackRemovedEvent(String dmID, String objectID) { SimulationEvent ev = new SimulationEvent(); ev.eventType = "SEAMATE_TrackRemoved"; ev.parameters.Add("UserID", DataValueFactory.BuildString(dmID)); ev.parameters.Add("ObjectID", DataValueFactory.BuildString(objectID)); ev.parameters.Add("Time", DataValueFactory.BuildInteger(time)); DDDConnection.SendSimEvent(ev); }
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("")); }
/// <summary> /// /// </summary> /// <param name="playerID"></param> /// <param name="message"></param> private void SendSystemMessageToPlayer(string playerID, string message) { //might be nice to send out a confirmation of player X's joining to the server //and selection of a DM. The msg would be a text chat? SimulationEvent e = SimulationEventFactory.BuildEvent(ref simModelInfo, "SystemMessage"); e["Message"] = DataValueFactory.BuildString(message); e["PlayerID"] = DataValueFactory.BuildString(playerID); e["TextColor"] = DataValueFactory.BuildInteger(System.Drawing.Color.Red.ToArgb()); server.PutEvent(e); }
private Dictionary <string, DataValue> CopyFromCustomAttributes(Dictionary <string, DataValue> incoming) { Dictionary <string, DataValue> returnDict = new Dictionary <string, DataValue>(); foreach (KeyValuePair <string, DataValue> kvp in incoming) { returnDict.Add(kvp.Key, DataValueFactory.BuildFromDataValue(kvp.Value)); } return(returnDict); }
private void SendLoginEvent(String userID, String dmID, String teamID) { SimulationEvent ev = new SimulationEvent(); ev.eventType = "SEAMATE_ExperimenterLogin"; ev.parameters.Add("IndividualID", DataValueFactory.BuildString(userID)); ev.parameters.Add("TeamID", DataValueFactory.BuildString(teamID)); ev.parameters.Add("DM_ID", DataValueFactory.BuildString(dmID)); ev.parameters.Add("Time", DataValueFactory.BuildInteger(time)); DDDConnection.SendSimEvent(ev); }
public void Resume() { paused = false; SimulationEvent e = SimulationEventFactory.BuildEvent(ref simModel, "ResumeScenario"); e["Time"] = DataValueFactory.BuildInteger(time); if (distClient != null) { distClient.PutEvent(e); } }
public void SendStopReplayEvents() { if (simModelInfo != null) { SimulationEvent e = SimulationEventFactory.BuildEvent(ref simModelInfo, "StopReplay"); e["Time"] = DataValueFactory.BuildInteger(simulationTime);//ConvertInteger(latestTick); distClient.PutEvent(e); e = SimulationEventFactory.BuildEvent(ref simModelInfo, "ExternalApp_SimStop"); e["Time"] = DataValueFactory.BuildInteger(simulationTime);//ConvertInteger(latestTick); distClient.PutEvent(e); } }
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)); }
private void SendViewProActiveRegionUpdate(string objectID, bool isVisible, int displayColor, Polygon3D poly) { SimulationEvent vpmu = null; vpmu = SimulationEventFactory.BuildEvent(ref simModel, "ViewProActiveRegionUpdate"); vpmu["ObjectID"] = DataValueFactory.BuildString(objectID); vpmu["IsVisible"] = DataValueFactory.BuildBoolean(isVisible); vpmu["DisplayColor"] = DataValueFactory.BuildInteger(displayColor); vpmu["Shape"] = poly.Footprint.GetPolygonValue(); distClient.PutEvent(vpmu); }
private void EngramValue(SimulationEvent e) { SimulationObjectProxy obProx; string engramName = ((StringValue)e["EngramName"]).value; string engramValue = ((StringValue)e["EngramValue"]).value; string engramDataType = ((StringValue)e["EngramDataType"]).value; string objectID = string.Empty; objectID = ((StringValue)e["SpecificUnit"]).value; if (objectID != string.Empty) { obProx = objectProxies[objectID]; if (!StateDB.physicalObjects.ContainsKey(objectID)) { return; } EmitterValue em = (EmitterValue)obProx["Emitters"].GetDataValue(); CustomAttributesValue cus = (CustomAttributesValue)obProx["CustomAttributes"].GetDataValue(); if (em.attIsEngram.ContainsKey(engramName)) { cus.attributes[engramName] = DataValueFactory.BuildString(engramValue); obProx["CustomAttributes"].SetDataValue(cus); } //Add the qualified engram name to the collection. //Does not need to be the same qualified name as the scencon uses. StateDB.UpdateEngrams(String.Format("{0}|{1}", objectID, engramName), engramValue, engramDataType); return; } else { StateDB.UpdateEngrams(engramName, engramValue, engramDataType); foreach (string id in objectProxies.Keys) { obProx = objectProxies[id]; if (!StateDB.physicalObjects.ContainsKey(id)) { continue; } EmitterValue em = (EmitterValue)obProx["Emitters"].GetDataValue(); CustomAttributesValue cus = (CustomAttributesValue)obProx["CustomAttributes"].GetDataValue(); if (em.attIsEngram.ContainsKey(engramName)) { cus.attributes[engramName] = DataValueFactory.BuildString(engramValue); obProx["CustomAttributes"].SetDataValue(cus); } } return; } }
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)); }