示例#1
0
        /// <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);
        }
示例#2
0
        public MoveEvent(String objectID, LocationValue location, int time)
        {
            EVENTTYPE = "MoveObject";

            ObjectID = objectID;
            DestinationLocation = location;
            Time = time;
        }
示例#3
0
文件: Vec2D.cs 项目: wshanshan/DDD
 public LocationValue ToLocationValue()
 {
     LocationValue v = new LocationValue();
     v.X = X;
     v.Y = Y;
     v.Z = 0;
     v.exists = true;
     return v;
 }
示例#4
0
        //

        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>();
        }
示例#5
0
        //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;

        }
示例#6
0
        //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;
        }
        public MoveWithAvoidanceBehavior(String thisID, LocationValue destLoc, double avoidRange,double avoidPathWidth, List<String> objectClassesToAvoid, double throttle)
        {
            m_thisID = thisID;
            m_destLocation = destLoc;
            m_avoidRange = avoidRange;
            m_avoidPathWidth = avoidPathWidth;
            m_dmView = null;
            m_objectClassesToAvoid = objectClassesToAvoid;
            m_throttle = throttle;
            m_holdWP = null;
            m_blockedBy = String.Empty;

            
        }
示例#8
0
 public EngageTargetBehavior(String thisID, String targetID, WaypointSequence relativeLoiterPattern, Boolean returnAfter)
 {
     m_engagementState = EngagementState.Tracking;
     m_thisID = thisID;
     m_targetID = targetID;
     m_relativeLoiterPattern = relativeLoiterPattern;
     m_absoluteLoiterPattern = null;
     m_destWaypoint = null;
     m_attackEndTime = 0;
     m_attackInProcess = false;
     m_attackIsWeapon = false;
     m_originalLocation = null;
     m_returnAfter = returnAfter;
 }
示例#9
0
        //detection
        public static DetectedAttributeValue Detection(LocationValue sensingLocation,
                                                        LocationValue emittingLocation,
                                                        DataValue emittingObjectAttribute,
                                                        List<ConeValue> sensingCones,
                                                        Dictionary<string, double> emitters,
                                                        List<SimulationObjectProxy> obstructions,
                                                        ref Random random)
        {
            DetectedAttributeValue returnDAV = new DetectedAttributeValue();
            Vec3D sensingPoint = new Vec3D(sensingLocation);
            Vec3D emittingPoint = new Vec3D(emittingLocation);
            Vec3D sensingDirection = new Vec3D(sensingPoint); //can't set to blank, just ignore.
            double coneAngle = 0.0;
            double angleBetweenSensorAndEmitter = 0.0;

            foreach(ConeValue cone in sensingCones)
            {
                sensingDirection.Set(cone.direction);
                Vec3D closestPoint = FindClosestPoint(sensingPoint, sensingDirection, emittingPoint);
                if (cone.extent > sensingPoint.ScalerDistanceTo(closestPoint))
                {//p* is within the cone's extent. 
                    
                    //determine if emitting point is within the spread of the cone.
                    coneAngle = cone.spread * Math.PI / 180;// System.Math.Atan(emittingPoint.ScalerDistanceTo(closestPoint) / sensingPoint.ScalerDistanceTo(closestPoint));//should be cone.spread
                    angleBetweenSensorAndEmitter = System.Math.Atan(emittingPoint.ScalerDistanceTo(closestPoint) / sensingPoint.ScalerDistanceTo(closestPoint));

                    if (coneAngle < angleBetweenSensorAndEmitter)
                    {
                        continue; //should go to next cone.
                    }
                    if (emitters.ContainsKey(cone.level))
                    {//emitter has an emission at the same level as the cone.
                        //returnDAV = (DetectedAttributeValue)ObfuscateAttributeValue(emittingObjectAttribute, emitters[cone.level], ref random);
                        returnDAV = (DetectedAttributeValue)FuzzAttributeValue(emittingObjectAttribute, emitters[cone.level], ref random);
    
                        return returnDAV;
                    }
                    else
                    { //emitter does not emit the same level as the cone.
                        //should this find next best, or just move on?
                    }
                }
            }

            return null;
        }
示例#10
0
 private static void SendWhiteboardLine(string object_ID, string userID, string targetUserID,
     int mode, LocationValue start, LocationValue end, double width, double originalScale, int color, string text)
 {
     SimulationEvent sendingEvent = SimulationEventFactory.BuildEvent(ref simModelInfo, "WhiteboardLine");
     DataValue dv = new StringValue();
     ((StringValue)sendingEvent["ObjectID"]).value = object_ID;
     ((StringValue)sendingEvent["UserID"]).value = userID;
     ((StringValue)sendingEvent["TargetUserID"]).value = targetUserID;
     ((IntegerValue)(sendingEvent["Mode"])).value = mode; 
     sendingEvent["StartLocation"] = start;
     sendingEvent["EndLocation"] = end;
     ((DoubleValue)(sendingEvent["Width"])).value = width;
     ((DoubleValue)(sendingEvent["OriginalScale"])).value = originalScale;
     ((IntegerValue)(sendingEvent["Color"])).value = color;
     ((StringValue)sendingEvent["Text"]).value = text;
     server.PutEvent(sendingEvent);        
 }
示例#11
0
文件: Vec3D.cs 项目: wshanshan/DDD
 public Vec3D(LocationValue v)
 {
     X = v.X;
     Y = v.Y;
     Z = v.Z;
 }
示例#12
0
        Polygon3D createAbsoluteCollisionShape(Polygon3D relShape, LocationValue loc)
        {
            Polygon3D absShape = new Polygon3D(relShape.BottomZ + loc.Z, relShape.TopZ + loc.Z);
            foreach (Vec2D v in relShape.Footprint.getVertices())
            {
                v.X += loc.X;
                v.Y += loc.Y;
                absShape.AddVertex(v);
            }
            return absShape;

        }
示例#13
0
        private void SendMoveObjectEvent(string objectID, double throttle, LocationValue destinationLocation)
        {
            SimulationEvent moveObject = SimulationEventFactory.BuildEvent(ref simModel, "MoveObject");
            moveObject["ObjectID"] = DataValueFactory.BuildString(objectID);
            moveObject["DestinationLocation"] = destinationLocation;
            moveObject["Throttle"] = DataValueFactory.BuildDouble(throttle);

            distClient.PutEvent(moveObject);
        }
示例#14
0
        private void ChangeObjectDestinationLocation(LocationValue newDestinationLocation, string objectID)
        {
            SimulationObjectProxy obj = objectProxies[objectID];
            if (obj == null)
                return;
            double throttle = ((DoubleValue)obj["Throttle"].GetDataValue()).value;

            if (newDestinationLocation.exists)
            {
                SendMoveObjectEvent(objectID, throttle, newDestinationLocation);
            }
        }
示例#15
0
 private double CalculateHeading(LocationValue current, LocationValue destination)
 {
     if (!(current.exists && destination.exists))
         return 0;
     Vec3D c = new Vec3D(current);
     Vec3D d = new Vec3D(destination);
     Vec3D headingVector = c.VectorDistanceTo(d);
     headingVector.Normalize();
     return 180 / Math.PI * Math.Atan2(headingVector.X, headingVector.Y);
 }
示例#16
0
        /// <summary>
        /// Takes an xml string, and returns a DataValue object.
        /// Returns null if the xml doesn't represent a DataValue.
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static DataValue XMLDeserialize(string xml)
        {
            Match m = typeregex.Match(xml);
            if (m.Success)
            {
                Group g = m.Groups[1];

                string dataType = g.ToString();
                switch (dataType)
                {
                    case "StringType":
                        StringValue sv = new StringValue();
                        sv.FromXML(xml);
                        return sv;
                    case "DoubleType":
                        DoubleValue dv = new DoubleValue();
                        dv.FromXML(xml);
                        return dv;
                    case "IntegerType":
                        IntegerValue iv = new IntegerValue();
                        iv.FromXML(xml);
                        return iv;
                    case "BooleanType":
                        BooleanValue bv = new BooleanValue();
                        bv.FromXML(xml);
                        return bv;
                    case "LocationType":
                        LocationValue lv = new LocationValue();
                        lv.FromXML(xml);
                        return lv;
                    case "VelocityType":
                        VelocityValue vv = new VelocityValue();
                        vv.FromXML(xml);
                        return vv;
                    case "AttributeCollectionType":
                        AttributeCollectionValue av = new AttributeCollectionValue();
                        av.FromXML(xml);
                        return av;
                    case "CustomAttributesType":
                        CustomAttributesValue cav = new CustomAttributesValue();
                        cav.FromXML(xml);
                        return cav;
                    case "StringListType":
                        StringListValue slv = new StringListValue();
                        slv.FromXML(xml);
                        return slv;
                    case "PolygonType":
                        PolygonValue polyv = new PolygonValue();
                        polyv.FromXML(xml);
                        return polyv;
                    case "StateTableType":
                        StateTableValue stv = new StateTableValue();
                        stv.FromXML(xml);
                        return stv;
                    case "CapabilityType":
                        CapabilityValue cv = new CapabilityValue();
                        cv.FromXML(xml);
                        return cv;
                    case "VulnerabilityType":
                        VulnerabilityValue vv2 = new VulnerabilityValue();
                        vv2.FromXML(xml);
                        return vv2;
                    case "ConeType":
                        ConeValue cv2 = new ConeValue();
                        cv2.FromXML(xml);
                        return cv2;
                    case "SensorType":
                        SensorValue sv2 = new SensorValue();
                        sv2.FromXML(xml);
                        return sv2;
                    case "SensorArrayType":
                        SensorArrayValue sav = new SensorArrayValue();
                        sav.FromXML(xml);
                        return sav;
                    case "EmitterType":
                        EmitterValue ev = new EmitterValue();
                        ev.FromXML(xml);
                        return ev;
                    case "RangeRingDisplayType":
                        RangeRingDisplayValue rrdv = new RangeRingDisplayValue();
                        rrdv.FromXML(xml);
                        return rrdv;
                    case "AttackCollectionType":
                        AttackCollectionValue attCV = new AttackCollectionValue();
                        attCV.FromXML(xml);
                        return attCV;
                    case "WrapperType":
                        WrapperValue wrapper = new WrapperValue();
                        wrapper.FromXML(xml);
                        return wrapper;
                    case "ClassificationDisplayRulesType":
                        ClassificationDisplayRulesValue cdrv = new ClassificationDisplayRulesValue();
                        cdrv.FromXML(xml);
                        return cdrv;
                    default:
                        return null;
                }
            }
            else
            {
                return null;
            }

        }
示例#17
0
        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;
        }
示例#18
0
        public override void OnMouseUp(object sender, MouseEventArgs e)
        {
            if (_playfield != null)
            {
                if (!_mini_map_thumb.Contains(e.Location) ||
                    (_mini_map_thumb.Contains(e.Location) && (e.Button == MouseButtons.Right)))
                {
                    if ((WBRoom != null) && (WhiteboardDrawing))
                    {
                        // Handle whiteboard mouse event
                        if (DrawDistanceLine)
                        {
                            if (((WBRoom.DrawMode == DrawModes.Line) || (WBRoom.DrawMode == DrawModes.Circle) ||
                                (WBRoom.DrawMode == DrawModes.Arrow))
                                && (WhiteboardDrawing == true))
                            {
                                LocationValue startLocation = new LocationValue();
                                LocationValue endLocation = new LocationValue();
                                double drawPointSize = WBRoom.DrawPointSize / _playfield.Scale;

                                startLocation.X = (LineStartLocation.X - Map.Position.X) / _playfield.Scale;
                                startLocation.Y = (LineStartLocation.Y - Map.Position.Y) / _playfield.Scale;
                                startLocation.exists = true;

                                endLocation.X = (LineEndLocation.X - Map.Position.X) / _playfield.Scale;
                                endLocation.Y = (LineEndLocation.Y - Map.Position.Y) / _playfield.Scale;
                                endLocation.exists = true;

                                if ((WBRoom.DrawMode == DrawModes.Line) && (WBRoom.DrawText != null) &&
                                    (WBRoom.DrawText.Length > 0))
                                {
                                    WBRoom.Controller.WhiteboardLineRequest(DDD_Global.Instance.PlayerID, (int)WBRoom.DrawMode,
                                        startLocation, endLocation, drawPointSize, _playfield.Scale, WBRoom.DrawColor, WBRoom.DrawText, WBRoom.Name);
                                }
                                else
                                {
                                    WBRoom.Controller.WhiteboardLineRequest(DDD_Global.Instance.PlayerID, (int)WBRoom.DrawMode,
                                        startLocation, endLocation, drawPointSize, _playfield.Scale, WBRoom.DrawColor, "", WBRoom.Name);
                                }

                                WhiteboardDrawing = false;
                            }
                            else if ((WBRoom.DrawMode == DrawModes.Text) && (WBRoom.DrawText != null) &&
                                (WBRoom.DrawText.Length > 0) && (WhiteboardDrawing == true))
                            {
                                LocationValue startLocation = new LocationValue();
                                LocationValue endLocation = new LocationValue();
                                double drawPointSize = (WBRoom.DrawPointSize + 7) / _playfield.Scale;

                                endLocation.X = (LineEndLocation.X - Map.Position.X) / _playfield.Scale;
                                endLocation.Y = (LineEndLocation.Y - Map.Position.Y) / _playfield.Scale;
                                endLocation.exists = true;

                                WBRoom.Controller.WhiteboardLineRequest(DDD_Global.Instance.PlayerID, (int)WBRoom.DrawMode,
                                    endLocation, endLocation, drawPointSize, _playfield.Scale, WBRoom.DrawColor, WBRoom.DrawText, WBRoom.Name);

                                WhiteboardDrawing = false;
                            }
                            else if ((WBRoom.DrawMode == DrawModes.Selection) && (WhiteboardDrawing == true))
                            {
                                RectangleF selectionRect;
                                float selectionX = (float)(Math.Min(LineStartLocation.X - Map.Position.X, LineEndLocation.X - Map.Position.X)) / _playfield.Scale;
                                float selectionY = (float)(Math.Min(LineStartLocation.Y - Map.Position.Y, LineEndLocation.Y - Map.Position.Y)) / _playfield.Scale;

                                selectionRect = new RectangleF(selectionX, selectionY,
                                    ((float)Math.Abs(LineStartLocation.X - LineEndLocation.X)) / _playfield.Scale,
                                    ((float)Math.Abs(LineStartLocation.Y - LineEndLocation.Y)) / _playfield.Scale);

                                // Clear the selection list
                                WBRoom.ClearSelectionList();

                                // Add contained objects to selection list
                                WBRoom.AddSelection(selectionRect, true);

                                if (!WBRoom.ObjectsSelected())
                                {
                                    _playfield.OnMouseUp(sender, e);
                                }

                                WhiteboardDrawing = false;
                            }
                            DrawDistanceLine = false;
                        }
                        if ((WBRoom.DrawMode == DrawModes.Selection) && (WhiteboardDrawing == true))
                        {
                            RectangleF selectionRect;

                            float selectionX = (float)(LineStartLocation.X - Map.Position.X) / _playfield.Scale;
                            float selectionY = (float)(LineStartLocation.Y - Map.Position.Y) / _playfield.Scale;

                            selectionRect = new RectangleF(selectionX, selectionY, 1.0f, 1.0f);

                            // Add contained objects to selection list
                            WBRoom.AddSelection(selectionRect, false);

                            if (!WBRoom.ObjectsSelected())
                            {
                                _playfield.OnMouseUp(sender, e);
                            }

                            WhiteboardDrawing = false;
                        }
                        WhiteboardDrawing = false;
                    }
                    else
                    {
                        _playfield.OnMouseUp(sender, e);
                    }
                }
                else
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        _mini_map_scroll = false;
                    }
                }
            }
        }
示例#19
0
 public ConeValue()
 {
     dataType = "ConeType";
     direction = new LocationValue();
     direction.exists = true;
     level = string.Empty;
     extent = 0.0;
     spread = 0.0;
     xmlStartTag = String.Format("<{0}>", dataType);
     xmlEndTag = String.Format("</{0}>", dataType);
 }
示例#20
0
 public LocationNode(String name, LocationValue loc)
 {
     m_location = loc;
     m_connectedNodes = new List<LocationNode>();
     Name = name;
 }
示例#21
0
        static public LocationGraph GenerateRouteGraph(String startName,LocationValue startLocation, String endName, LocationValue endLocation, List<WaypointRoute> routes)
        {
            LocationGraph result = new LocationGraph();

            double distanceThreshold = 1.0;

            //List<String> routeNames = new List<string>(this.Keys);
            String name;
            for (int i = 0; i < routes.Count; i++)
            {
                name = routes[i].Name;
                WaypointRoute route = routes[i];
                LocationGraph.LocationNode lastNode = null;
                foreach (Waypoint wp in route)
                {
                    LocationGraph.LocationNode node = new LocationGraph.LocationNode(wp.Name, wp.Location);
                    result.AddNode(node);
                    if (lastNode != null)
                    {
                        result.BiConnect(lastNode, node);
                    }
                    lastNode = node;
                }

                if (i > 0)
                {
                    WaypointRoute lastRoute = routes[i - 1];
                    Boolean done = false;
                    for (int j = 1; j < lastRoute.Count; j++)
                    {
                        if (done) break;
                        for (int k = 1; k < route.Count; k++)
                        {
                            if (done) break;
                            Waypoint lastRouteP1 = lastRoute[j - 1];
                            Waypoint lastRouteP2 = lastRoute[j];
                            Waypoint nextRouteP1 = route[k - 1];
                            Waypoint nextRouteP2 = route[k];
                            LocationValue intersect = BehaviorHelper.LineIntersect(lastRouteP1.Location, lastRouteP2.Location,
                                                                                   nextRouteP1.Location, nextRouteP2.Location);
                            /*if (intersect != null)
                            {
                                string newName = String.Format("Intersection_{0}_{1}_{2}_{3}", lastRouteP1.Name, lastRouteP2.Name, nextRouteP1.Name, nextRouteP2.Name);
                                LocationGraph.LocationNode intersectNode = new LocationGraph.LocationNode(newName, intersect);
                                result.AddNode(intersectNode);
                                result.BiConnect(intersectNode.Name, lastRouteP1.Name);
                                result.BiConnect(intersectNode.Name, lastRouteP2.Name);
                                result.BiConnect(intersectNode.Name, nextRouteP1.Name);
                                result.BiConnect(intersectNode.Name, nextRouteP2.Name);
                            }
                            else*/ 
                            if (BehaviorHelper.Distance(lastRouteP1.Location, nextRouteP1.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP1.Name, nextRouteP1.Name);
                                done = true;
                            }
                            else if (BehaviorHelper.Distance(lastRouteP1.Location, nextRouteP2.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP1.Name, nextRouteP2.Name);
                                done = true;
                            }
                            else if (BehaviorHelper.Distance(lastRouteP2.Location, nextRouteP1.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP2.Name, nextRouteP1.Name);
                                done = true;
                            }
                            else if (BehaviorHelper.Distance(lastRouteP2.Location, nextRouteP2.Location) < distanceThreshold)
                            {
                                result.BiConnect(lastRouteP2.Name, nextRouteP2.Name);
                                done = true;
                            }
                        }
                    }
                }
            }
            

            //result.ProximityConnect(10);
            //result.IntersectConnect();

            LocationNode startNode = new LocationNode(startName, startLocation);
            LocationNode endNode = new LocationNode(endName, endLocation);

            result.InsertByProximity(startNode);
            result.InsertByProximity(endNode);

            return result;
        }
示例#22
0
        /// <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;
            //Console.WriteLine(String.Format("VPMU: ID:{0} dX:{1} dY:{2}", objectID, desLocation.X, desLocation.Y));
            //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
            try
            {
                vpmu["LabelColor"] = DataValueFactory.BuildInteger(dmColorMapping[ownerID]);
            }
            catch (Exception ex)
            {
                vpmu["LabelColor"] = DataValueFactory.BuildInteger(-984833);
            }
            vpmu["IsWeapon"] = DataValueFactory.BuildBoolean(isWeapon);
            distClient.PutEvent(vpmu);
            if (!movingObjects.Contains(objectID) &&
                !DataValueFactory.CompareDataValues(location, desLocation))
            {
                movingObjects.Add(objectID);
            }
        }
示例#23
0
文件: Vec2D.cs 项目: wshanshan/DDD
 public void Set(LocationValue v)
 {
     X = v.X;
     Y = v.Y;
 }
示例#24
0
 new public void FromXML(string xml)
 {
     Match m = regex.Match(xml);
     if (m.Success)
     {
         LocationValue lv = new LocationValue();
         lv.FromXML("<LocationType>" + m.Groups[1].Value + "</LocationType>");
         direction = lv;
         level = m.Groups[2].Value;
         extent = Convert.ToDouble(m.Groups[3].Value);
         spread = Convert.ToDouble(m.Groups[4].Value);
     }
     else
     {
         throw new Exception(String.Format("Invalid XML string in {0}: {1}", dataType, xml));
     }
 }
示例#25
0
        public void DrawWhiteboardRoomObjects(WhiteboardRoom wbRoom, Canvas canvas)
        {
            if (wbRoom == null)
            {
                return;
            }

            // Draw all whiteboard commands
            Array drawingCommands = wbRoom.GetCurrentDrawingCommands();

            foreach (object obj in drawingCommands)
            {
                if (obj is LineObject)
                {
                    LineObject line = (LineObject)obj;
                    LocationValue start = new LocationValue();
                    LocationValue end = new LocationValue();
                    int drawPointSize = (int)(line.Width * _playfield.Scale);

                    if ((drawPointSize == 0) && (line.Width > 0))
                    {
                        drawPointSize = 1;
                    }

                    if ((line.Mode == DrawModes.Line) || (line.Mode == DrawModes.Circle) ||
                        (line.Mode == DrawModes.Arrow))
                    {
                        start.X = line.Start.X * _playfield.Scale + Map.Position.X;
                        start.Y = line.Start.Y * _playfield.Scale + Map.Position.Y;

                        end.X = line.End.X * _playfield.Scale + Map.Position.X;
                        end.Y = line.End.Y * _playfield.Scale + Map.Position.Y;

                        if (line.Mode == DrawModes.Line)
                        {
                            if ((line.Text != null) && (line.Text.Length > 0))
                            {
                                int lineTextSize = (int) ((LineTextSize / line.OriginalScale) * _playfield.Scale);

                                DrawShortenedLine(canvas, line.Color, drawPointSize, (float)start.X, (float)start.Y,
                                    (float)end.X, (float)end.Y, (float) (_playfield.Scale / line.OriginalScale));

                                if (lineTextSize > MaxFontSize)
                                {
                                    lineTextSize = MaxFontSize;
                                }
                                if (lineTextSize < 1)
                                {
                                    lineTextSize = 1;
                                }
                                if (wbFonts[lineTextSize] == null)
                                {
                                    wbFonts[lineTextSize] = canvas.CreateFont(new System.Drawing.Font("Arial", lineTextSize, FontStyle.Bold, GraphicsUnit.Pixel));
                                }
                                DrawCenteredText(wbFonts[lineTextSize], line.Text, (int)end.X, (int)end.Y, line.Color);
                            }
                            else
                            {
                                canvas.DrawLine(line.Color, drawPointSize, (float)start.X, (float)start.Y,
                                    (float)end.X, (float)end.Y);
                            }
                        }
                        else if (line.Mode == DrawModes.Circle)
                        {
                            canvas.DrawCircle(line.Color, drawPointSize, (float)start.X, (float)start.Y,
                                (float)end.X, (float)end.Y);
                        }
                        else if (line.Mode == DrawModes.Arrow)
                        {
                            canvas.DrawArrow(line.Color, drawPointSize, (float)start.X, (float)start.Y,
                                (float)end.X, (float)end.Y);
                        }
                    }
                    else if ((line.Mode == DrawModes.Text) && (line.Text != null) &&
                        (line.Text.Length > 0))
                    {
                        start.X = line.Start.X * _playfield.Scale + Map.Position.X;
                        start.Y = line.Start.Y * _playfield.Scale + Map.Position.Y;

                        if (drawPointSize > MaxFontSize)
                        {
                            drawPointSize = MaxFontSize;
                        }
                        if (wbFonts[drawPointSize] == null)
                        {
                            wbFonts[drawPointSize] = canvas.CreateFont(new System.Drawing.Font("Arial", drawPointSize, FontStyle.Bold, GraphicsUnit.Pixel));
                        }
                        DrawCenteredText(wbFonts[drawPointSize], line.Text, (int)start.X, (int)start.Y, line.Color);

                        // Update the bounding box if needed
                        if ((line.BoundingPolygon == null) || (wbRoom == WBRoom))
                        {
                            RectangleF textRect;
                            Polygon textPoly;
                            float width;
                            float height;
                            PointF boundStart = new PointF();

                            textRect = wbFonts[drawPointSize].MeasureString(null, line.Text, DrawTextFormat.None, line.Color);

                            width = textRect.Right / _playfield.Scale;
                            if ((width * line.OriginalScale) < 5)
                            {
                                width = 5 / (float) line.OriginalScale;
                            }
                            height = textRect.Bottom / _playfield.Scale;
                            if ((height * line.OriginalScale) < 5)
                            {
                                height = 5 / (float) line.OriginalScale;
                            }
                            boundStart.X = (float)line.Start.X - (width / 2);
                            boundStart.Y = (float)line.Start.Y - (height / 2);

                            textPoly = new Polygon();
                            textPoly.Points.Add(new Vector(boundStart.X, boundStart.Y));
                            textPoly.Points.Add(new Vector(boundStart.X + width, boundStart.Y));
                            textPoly.Points.Add(new Vector(boundStart.X + width, boundStart.Y + height));
                            textPoly.Points.Add(new Vector(boundStart.X, boundStart.Y + height));
                            textPoly.Offset(0, 0);
                            textPoly.BuildEdges();

                            line.BoundingPolygon = textPoly;
                        }
                    }

                    // Draw Bounding rectable if object is selected
                    if ((line.ObjectSelected) && (line.BoundingPolygon != null) && (line.BoundingPolygon.Points.Count >= 2))
                    {
                        LocationValue boundStart = new LocationValue();
                        LocationValue boundEnd = new LocationValue();
                        Vector prevPoint = line.BoundingPolygon.Points[line.BoundingPolygon.Points.Count - 1]; 
                        foreach (Vector curPoint in line.BoundingPolygon.Points)
                        {
                            boundStart.X = prevPoint.X * _playfield.Scale + Map.Position.X;
                            boundStart.Y = prevPoint.Y * _playfield.Scale + Map.Position.Y;

                            boundEnd.X = curPoint.X * _playfield.Scale + Map.Position.X;
                            boundEnd.Y = curPoint.Y * _playfield.Scale + Map.Position.Y;

                            canvas.DrawLine(Color.Black.ToArgb(), 1, (float)boundStart.X, (float)boundStart.Y,
                                (float)boundEnd.X, (float)boundEnd.Y);

                            prevPoint = curPoint;
                        }
                    }
                }
            }
        }
示例#26
0
 /// <summary>
 /// Ask the DDD to move the specified object.
 /// </summary>
 /// <param name="objectID"></param>
 /// <param name="ownerID"></param>
 /// <param name="destination"></param>
 /// <param name="throttle"></param>
 public void SendMoveObjectRequest(String objectID, String ownerID, LocationValue destination, double throttle)
 {
     SimulationEvent e = SimulationEventFactory.BuildEvent(ref m_simModel, "MoveObjectRequest");
     ((StringValue)(e["UserID"])).value = ownerID;
     ((StringValue)(e["ObjectID"])).value = objectID;
     e["DestinationLocation"] = destination;
     ((DoubleValue)(e["Throttle"])).value = throttle;
     m_netClient.PutEvent(e);
 }
示例#27
0
文件: Vec2D.cs 项目: wshanshan/DDD
 public Vec2D(LocationValue v)
 {
     X = v.X;
     Y = v.Y;
 }
示例#28
0
 private void ChangeObjectLocation(LocationValue newLocation, string objectID)
 {
     SimulationObjectProxy obj = objectProxies[objectID];
     if (obj == null)
         return;
     obj["Location"].SetDataValue(newLocation);
     //Now that location has been updated, set in helper library:
     if (newLocation.exists)
     { ObjectDistances.UpdateObjectLocation(objectID, new Vec3D(newLocation)); }
     else
     { ObjectDistances.RemoveAnObject(objectID); }
 }
示例#29
0
 public SensorRange(LocationValue centerPoint, double sensorRadius)
 {
     CenterPoint = centerPoint;
     SensorRadius = sensorRadius;
 }
示例#30
0
        LocationValue CalculateIntercept(String myID, String targetID)
        {
            LocationValue interceptLoc = new LocationValue();

            LocationValue myLoc = m_dmView.AllObjects[myID].Location;
            LocationValue targetLoc = m_dmView.AllObjects[targetID].Location;

            //VelocityValue targetVel = m_dmView.AllObjects[targetID].Velocity;
            //Double myMaxSpeed = m_dmView.AllObjects[myID].MaximumSpeed;


            interceptLoc = targetLoc;


            return interceptLoc;
        }