/// <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> /// Makes a point which is in the closest entry region to the group of pirates, /// TODO: but not in the same entry region as any of them. /// </summary> /// <param name="pirates">The move events representing pirates</param> /// <param name="entryRegions">All entry regions</param> /// <returns>A random point in the closest entry region to the group of pirates</returns> private Vec2D GetPointInClosestEntryRegion(Dictionary <T_Move, T_Reveal> pirates, List <PolygonValue> entryRegions) { Vec2D point = new Vec2D(0, 0); double closestDistance = 100000000; PolygonValue closestRegion = null; Shuffle(entryRegions); T_Move randomPirate = pirates.Keys.ToList().ElementAt(0); LocationValue location = GetLocation(randomPirate, pirates[randomPirate]); foreach (PolygonValue entryRegion in entryRegions) { Polygon2D entry2D = new Polygon2D(entryRegion); double distance = Polygon2D.ScalarDistanceToPolygon(entry2D, new Vec2D(location)); if (distance < oneGroupingDistance) { point = entry2D.PointInside(); break; } else { if (distance < closestDistance) { closestDistance = distance; closestRegion = entryRegion; } } } if (point == null) { point = new Polygon2D(closestRegion).PointInside(); } return(point); }
public void Update(DDDServerConnection serverConnection, DMView dmView) { if (m_done) { return; } SimObject me = dmView.AllObjects[m_thisID]; SimObject dest = dmView.AllObjects[m_destID]; LocationValue myLocation = me.Location; LocationValue destLocation = dest.Location; VelocityValue myVelocity = me.Velocity; if (ObjectMath.IsWithinRange(0.1, myLocation, destLocation)) { m_done = true; return; } if (myVelocity.VX == 0 && myVelocity.VY == 0 && myVelocity.VZ == 0) { serverConnection.SendMoveObjectRequest(m_thisID, destLocation, 1); } }
public void Update(DDDServerConnection serverConnection, DMView dmView) { SimObject me = dmView.AllObjects[m_thisID]; SimObject dest = dmView.AllObjects[m_destID]; LocationValue clearLoc = dest.Location; LocationValue otherLocation = null; bool clear = true; foreach (String id in dmView.AllObjects.Keys) { if (id == m_destID || id == m_thisID) { continue; } otherLocation = dmView.AllObjects[id].Location; if (ObjectMath.IsWithinRange(100, clearLoc, otherLocation)) { clear = false; break; } } if (clear) { m_done = true; } }
//isPirate here refers to the objects we are trying to find, e.g. isPirate = true means find pirates private List <SeamateAdapter.DDD.DDDAdapter.SeamateObject> findObjectsInPlay(LocationValue nearby, PolygonValue pirateEntryRegion, T_Groupings grouping, bool isPirate) { List <DDDAdapter.SeamateObject> vessels = new List <DDDAdapter.SeamateObject>(); foreach (DDDAdapter.SeamateObject vessel in ddd.GetAllRevealedSeaVessels()) { if (isPirate && vessel.Owner == "Pirate DM" || !isPirate && vessel.Owner == "Merchant DM") { } else { continue; } double distance = new Vec2D(vessel.Location).ScalerDistanceTo(new Vec2D(nearby)); bool inSameEntryRegionAsPirate = false; if (pirateEntryRegion != null) { inSameEntryRegionAsPirate = Polygon2D.IsPointInside(new Polygon2D(pirateEntryRegion), new Vec2D(vessel.Location)); } if (grouping == T_Groupings.One && distance < oneGroupingDistance && !inSameEntryRegionAsPirate) { vessels.Add(vessel); } else if (grouping == T_Groupings.Two && distance > twoGroupingDistance && !inSameEntryRegionAsPirate) { vessels.Add(vessel); } } return(vessels); }
public void Update(DDDServerConnection serverConnection, DMView dmView) { SimObject me = dmView.AllObjects[m_thisID]; SimActiveRegion zone = dmView.ActiveRegions[m_zoneID]; LocationValue otherLocation = null; Polygon2D azPoly = new Polygon2D(); foreach (PolygonValue.PolygonPoint p in zone.Shape.points) { azPoly.AddVertex(new Vec2D(p.X, p.Y)); } bool clear = true; foreach (String id in dmView.AllObjects.Keys) { if (id == m_thisID) { continue; } otherLocation = dmView.AllObjects[id].Location; if (Polygon2D.IsPointInside(azPoly, new Vec2D(otherLocation))) { clear = false; break; } } if (clear) { m_done = true; } }
public SimulationEvent MoveDoneReceived(SimulationEvent e, SimulationModelInfo model, SimulationEvent theTick) { //Should receieve a MoveDone event, and create a new move event and send //it to the Queue Manager with time ticks + 1. SimulationEvent ee = SimulationEventFactory.BuildEvent(ref model, "MoveObject"); ee.eventType = "MoveObject"; DataValue myDV = new IntegerValue(); myDV = e["ObjectID"]; ee["ObjectID"] = myDV; myDV = new LocationValue(); ((LocationValue)(myDV)).X = 150; ((LocationValue)(myDV)).Y = 150; ((LocationValue)(myDV)).Z = 50; ee["DestinationLocation"] = myDV; myDV = new DoubleValue(); ((DoubleValue)(myDV)).value = .5; ee["Throttle"] = myDV; myDV = new IntegerValue(); ((IntegerValue)(myDV)).value = ((IntegerValue)theTick.parameters["Time"]).value + 1000; ee["Time"] = myDV; return(ee); }
public void Update(DDDServerConnection serverConnection, DMView dmView) { if (m_done) { return; } //SimObject me = dmView.AllObjects[m_thisID]; //LocationValue myLocation = me.Location; SimObject track = dmView.AllObjects[m_targetID]; LocationValue trackLocation = track.Location; m_absoluteLoiterPattern = m_relativeLoiterPattern.ToAbsolute(trackLocation); if (ShouldTrack(serverConnection, dmView)) { serverConnection.SendMoveObjectRequest(m_thisID, trackLocation, 1); m_trackTarget = true; } else { if (m_trackTarget) { StartLoiter(serverConnection, dmView); m_trackTarget = false; } ContinueLoiter(serverConnection, dmView); } }
private void AttackSucceeded(SimulationEvent e) { if (v3 != null) { string id = ((StringValue)e["ObjectID"]).value; string firingID = null; bool isWeapon = ((BooleanValue)objectProxies[id]["IsWeapon"].GetDataValue()).value; if (isWeapon) { firingID = ((StringValue)objectProxies[id]["ParentObjectID"].GetDataValue()).value; } else { firingID = id; } string targetID = ((StringValue)e["TargetID"]).value; string newState = ((StringValue)e["NewState"]).value; LocationValue targetlv = (LocationValue)objectProxies[targetID]["Location"].GetDataValue(); LocationValue firinglv = (LocationValue)objectProxies[firingID]["Location"].GetDataValue(); Dictionary <string, string> stateChangeParams = new Dictionary <string, string>(); stateChangeParams.Add("FiringObjectIdentifier", firingID); stateChangeParams.Add("FiringObjectLocation", String.Format("<X>{0}</X><Y>{1}</Y><Z>{2}</Z>", firinglv.X, firinglv.Y, firinglv.Z)); //stateChangeParams.Add("MunitionName", "Sensor"); stateChangeParams.Add("TargetObjectIdentifier", targetID); stateChangeParams.Add("TargetObjectLocation", String.Format("<X>{0}</X><Y>{1}</Y><Z>{2}</Z>", targetlv.X, targetlv.Y, targetlv.Z)); stateChangeParams.Add("NewDamageState", newState); v3.SendInteraction("DamageAssessment", stateChangeParams, time.ToString()); v3.Tick(); } }
public void Start(DDDServerConnection serverConnection, DMView dmView) { m_dmView = dmView; //Console.Out.WriteLine(String.Format("MoveWithAvoidanceBehavior.Start(){0}",m_thisID)); LogWriter.Write(m_dmView.DecisionMakerID + "_" + m_thisID, dmView.SimTime, String.Format("MoveWithAvoidanceBehavior.Start,{0},{1}", m_destLocation.ToXML(), m_throttle)); m_wasBlocked = false; SimObject me = dmView.AllObjects[m_thisID]; //SimObject dest = dmView.AllObjects[m_destID]; LocationValue myLocation = me.Location; //LocationValue destLocation = dest.Location; if (BehaviorHelper.LocationIsEqual(myLocation, m_destLocation)) { m_done = true; return; } if (!IsBlocked2()) { m_wasBlocked = false; serverConnection.SendMoveObjectRequest(m_thisID, me.Owner, m_destLocation, m_throttle); } else { m_wasBlocked = true; } }
static public Double Distance(LocationValue l1, LocationValue l2) { Vec3D v1 = new Vec3D(l1); Vec3D v2 = new Vec3D(l2); return(v1.ScalerDistanceTo(v2)); }
static public VelocityValue ComputeVelocityVector(LocationValue start, LocationValue dest, Double maxSpeed, Double throttle) { Vec3D startVec = new Vec3D(start); Vec3D destVec = new Vec3D(dest); Vec3D velVec; if (LocationIsEqual(start, dest)) { velVec = new Vec3D(0, 0, 0); return(velVec.ToVelocityValue()); } else { velVec = startVec.VectorDistanceTo(destVec); } velVec.Normalize(); velVec = velVec.Multiply(maxSpeed * throttle); //if (System.Double.IsNaN(velVec.X)) //{ // int i = 0; //} return(velVec.ToVelocityValue()); }
/// <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); }
private static SimulationEvent populateQueue4() { SimulationEvent ee = new SimulationEvent(); Dictionary <string, DataValue> myAtt = new Dictionary <string, DataValue>(); ee.eventType = "MoveObject"; DataValue myDV = new IntegerValue(); ((IntegerValue)(myDV)).value = 1; ee.parameters.Add("ObjectID", myDV); myDV = new LocationValue(); ((LocationValue)(myDV)).X = 100; ((LocationValue)(myDV)).Y = 100; ((LocationValue)(myDV)).Z = 100; ee.parameters.Add("DestinationLocation", myDV); myDV = new DoubleValue(); ((DoubleValue)(myDV)).value = .5; ee.parameters.Add("Throttle", myDV); myDV = new IntegerValue(); ((IntegerValue)(myDV)).value = 10000; ee.parameters.Add("Time", myDV); return(ee); }
public override string ToString() { if (Item == null) { return("NULL Location"); } if (Item is T_AbsolutePosition) { return(String.Format("{0:0.00},{1:0.00},{2:0.00}", ((T_AbsolutePosition)Item).X, ((T_AbsolutePosition)Item).Y, ((T_AbsolutePosition)Item).Z)); } if (Item is T_RelativePosition) { return("Some relative position"); } if (Item is DataValue) { LocationValue lv = Item as LocationValue; if (lv.exists == false) { return("Given no location"); } return(String.Format("{0:0.00},{1:0.00},{2:0.00}", lv.X, lv.Y, lv.Z)); } return("Unable to calculate Location"); }
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); } }
void ComputeIntersections(WaypointRoute route1, WaypointRoute route2) { List <LineSegment> segments1 = route1.ToLineSegments(); List <LineSegment> segments2 = route2.ToLineSegments(); Double THRESHOLD = 1.0; foreach (LineSegment ls1 in segments1) { foreach (LineSegment ls2 in segments2) { LocationValue intersect = BehaviorHelper.LineIntersect(ls1.First.Location, ls1.Second.Location, ls2.First.Location, ls2.Second.Location); if (intersect != null) { // if the intersect is really close to one of the route verticies, than don't do anything. // otherwise, insert the intersect into the routes if (BehaviorHelper.Distance(intersect, ls1.First.Location) > THRESHOLD && BehaviorHelper.Distance(intersect, ls1.Second.Location) > THRESHOLD) { int pos = route1.IndexOf(ls1.Second); route1.Insert(pos, new Waypoint(String.Format("between-{0}-{1}", ls1.First.Name, ls1.Second.Name), intersect)); } if (BehaviorHelper.Distance(intersect, ls2.First.Location) > THRESHOLD && BehaviorHelper.Distance(intersect, ls2.Second.Location) > THRESHOLD) { int pos = route2.IndexOf(ls2.Second); route2.Insert(pos, new Waypoint(String.Format("between-{0}-{1}", ls2.First.Name, ls2.Second.Name), intersect)); } return; // we only allow for one intersection between the two routes. } } } }
public MoveEvent(String objectID, LocationValue location, int time) { EVENTTYPE = "MoveObject"; ObjectID = objectID; DestinationLocation = location; Time = time; }
public Waypoint(Waypoint wp) { m_name = wp.Name; m_location = new LocationValue(); m_location.X = wp.Location.X; m_location.Y = wp.Location.Y; m_location.Z = wp.Location.Z; m_location.exists = wp.Location.exists; }
public Waypoint(String name, Double x, Double y, Double z) { m_name = name; m_location = new LocationValue(); m_location.X = x; m_location.Y = y; m_location.Z = z; m_location.exists = true; }
public Waypoint(String name, LocationValue loc) { m_name = name; m_location = new LocationValue(); m_location.X = loc.X; m_location.Y = loc.Y; m_location.Z = loc.Z; m_location.exists = loc.exists; }
//public LoiterBehavior(String thisID, String destID, WaypointSequence loiterPattern) //{ // m_thisID = thisID; // m_destID = destID; // m_destX = 0; // m_destY = 0; // m_loiterPattern = loiterPattern; //} public LoiterBehavior(String thisID, LocationValue refLoc, WaypointSequence relativeLoiterPattern) { m_thisID = thisID; //m_destID = String.Empty; m_referenceLocation = refLoc; m_relativeLoiterPattern = relativeLoiterPattern; m_absoluteLoiterPattern = relativeLoiterPattern.ToAbsolute(refLoc); m_destWaypoint = null; }
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)); } }
// public RevealEvent(String objectID, LocationValue location, String state, int time) { EVENTTYPE = "RevealObject"; ObjectID = objectID; Location = location; State = state; Time = time; StartupParameters = new Dictionary <string, DataValue>(); }
public void Start(DDDServerConnection serverConnection, DMView dmView) { m_dmView = dmView; SimObject me = dmView.AllObjects[m_thisID]; LocationValue myLocation = me.Location; m_destWaypoint = m_absoluteLoiterPattern.GetWaypointClosestTo(myLocation); serverConnection.SendMoveObjectRequest(m_thisID, m_destWaypoint.Location, 1); }
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); }
public OrderDetail(LocationValue deliveryLocation, string address, string flat, string houseNo, string contactNumber, string customerName) { DeliveryLocation = deliveryLocation; Address = address; Flat = flat; HouseNo = houseNo; ContactNumber = contactNumber; CustomerName = customerName; }
public LocationValue ToLocationValue() { LocationValue v = new LocationValue(); v.X = X; v.Y = Y; v.Z = 0; v.exists = true; return(v); }
public LocationValue ToLocationValue() { LocationValue lv = new LocationValue(); lv.X = Convert.ToDouble(this.X); lv.Y = Convert.ToDouble(this.Y); lv.Z = Convert.ToDouble(this.Z); lv.exists = true; return(lv); }
//Find obstructions //public static List<string> FindObstructions(List<string> allObstructions, Vec3D sensorPoint, Vec3D emitterPoint) //{//should pass a list of SimulationObjectProxies? // List<string> obstructionList = new List<string>(); // SimulationObject obj; // //do obstruction calculations // foreach (string region in allObstructions) // { // obj = bbc // Polygon3D reg = new Polygon3D( // } // return obstructionList; // //return a list of ACVs? //} /// <summary> /// This method determines if 2 objects are within a certain range. Returns true if /// the distance between the two objects is less than the range, otherwise returns false. Offers easy /// calculation of two LocationValue objects. /// </summary> /// <param name="range">The max distance that can be between the two objects while still returning true.</param> /// <param name="objectA">The first object's location as a LocationValue.</param> /// <param name="objectB">The second object's location as a LocationValue.</param> /// <returns></returns> public static bool IsWithinRange(double range, LocationValue objectA, LocationValue objectB) { Vec3D objA = new Vec3D(objectA); Vec3D objB = new Vec3D(objectB); if (range > objA.ScalerDistanceTo(objB)) { return(true); } return(false); }