/// <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 takes in the updated attribute collection value for a specified object, /// and each attribute in the collection that differs from the pre-existing attribute value. /// New attributes that did not exist before and modified attributes are added to an ACV which /// is returned as a collection of modified attributes. /// </summary> /// <param name="objectID">The unique object identifier of the object.</param> /// <param name="ACV">The collection of updated attributes for the specified object.</param> /// <returns>AttributeCollectionValue: Returns a collection of attributes that were not in /// or were different from pre-existing attributes in this object.</returns> public AttributeCollectionValue UpdateObject(string objectID, AttributeCollectionValue ACV) { AttributeCollectionValue returnACV = new AttributeCollectionValue(); DataValue dv1; DataValue dv2; if (!objectsList.ContainsKey(objectID)) { objectsList.Add(objectID, new AttributeCollectionValue()); } foreach (KeyValuePair <string, DataValue> kvp in ACV.attributes) { if (objectsList[objectID].attributes.ContainsKey(kvp.Key)) {//this object already contains the attribute dv1 = GetNestedDataValue(objectsList[objectID][kvp.Key]); dv2 = GetNestedDataValue(ACV[kvp.Key]); if (DataValueFactory.CompareDataValues(dv1, dv2) == true) { //no change required } else {//Need to update data, add to return ACV. objectsList[objectID][kvp.Key] = ACV[kvp.Key]; returnACV.attributes.Add(kvp.Key, kvp.Value); } } else { //this object does not already contain the attribute objectsList[objectID].attributes.Add(kvp.Key, kvp.Value); returnACV.attributes.Add(kvp.Key, kvp.Value); } } if (returnACV.attributes.Count == 0) { return(null); } //returned objects need ID and OwnerID passed. if (!returnACV.attributes.ContainsKey("ID")) { returnACV.attributes.Add("ID", ACV["ID"]); } if (!returnACV.attributes.ContainsKey("OwnerID")) { returnACV.attributes.Add("OwnerID", ACV["OwnerID"]); } return(returnACV); }