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 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); }
/// <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); } }
/// <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); }
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); } } } }
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 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); }
public DataValue GetCorrectDataValue(string key, string value) { DataValue dv = null; String attType = GetAttributeType(key); switch (attType) { case "StringType": dv = DataValueFactory.BuildString(value); break; case "IntegerType": dv = DataValueFactory.BuildInteger(Int32.Parse(value)); break; //case "LocationType": // dv = DataValueFactory.BuildLocation(value); // break; //case "VelocityType": // dv = DataValueFactory.BuildVelocity(Int32.Parse(value)); // break; case "DoubleType": dv = DataValueFactory.BuildDouble(double.Parse(value)); break; case "BooleanType": dv = DataValueFactory.BuildBoolean(bool.Parse(value)); break; //case "StringListType": // dv = DataValueFactory.BuildStringList(value); // break; default: //state table, capability, vulnerability, detectedattribute, sensor array, emitter, custom attributes, attack collection, ClassificationDisplayRulesType break; } return(dv); }