Example #1
0
        // Return true if the given waypoints are connected by a path. O(n) (or O(1) if connected components were unchanged)
        /// <summary>This function needs to be called with EntityCloseLock already acquired, or not an issue.</summary>
        public static bool Connected(MyWayPoint v1, MyWayPoint v2)
        {
            int c1 = MyWayPointGraph.GetConnectedComponentId(v1);
            int c2 = MyWayPointGraph.GetConnectedComponentId(v2);

            return(c1 == c2 && c1 != -1);
        }
Example #2
0
        // Return true if the given waypoints are connected by a path. O(n) (or O(1) if connected components were unchanged)
        /// <summary>This function needs to be called with EntityCloseLock already acquired, or not an issue.</summary>
        public static bool Connected(IEnumerable <MyWayPoint> vertices)
        {
            int  component = -1;
            bool first     = true;

            foreach (var v in vertices)
            {
                if (first)
                {
                    component = MyWayPointGraph.GetConnectedComponentId(v);
                    first     = false;
                }
                else
                {
                    int c = MyWayPointGraph.GetConnectedComponentId(v);
                    if (c != component)
                    {
                        return(false);
                    }
                    else if (c == -1)
                    {
                        return(false);               // two vertices that don't lie in the waypoint graph must be unconnected
                    }
                }
            }
            return(true);  // 0 or 1 vertices are always connected
        }
Example #3
0
        public override bool DebugDraw()
        {            /*
                      * int i = MyWayPointGraph.GetConnectedComponentId(this);
                      * var vertexColor = HsvToRgb((0.36f + i * 0.618034f) % 1.0f, 0.8f, 0.75f);
                      *
                      * DrawWaypointVertex(WorldMatrix.Translation, vertexColor);  // draw only edges for generated waypoints
                      *
                      *
                      * // draw edges
                      * foreach (var neighbor in Neighbors)
                      * {
                      * //DrawWaypointEdge(wp.WorldMatrix.Translation, neighbor.WorldMatrix.Translation, Color.Red, Color.Green);  // selected path: red-green edges
                      *
                      * if (neighbor.WorldMatrix.Translation != WorldMatrix.Translation)
                      * {
                      * Vector3 direction = neighbor.WorldMatrix.Translation - WorldMatrix.Translation;
                      * float lineLength = direction.Length();
                      * direction.Normalize();
                      * MyTransparentGeometry.AddLineBillboard(MyTransparentMaterialEnum.ProjectileTrailLine, Color.Yellow.ToVector4(), WorldMatrix.Translation, direction, lineLength, 0.25f);
                      * }
                      *
                      * }
                      */
            if (((MyHud.ShowDebugWaypoints) || (MyGuiScreenGamePlay.Static.IsEditorActive() && !MyGuiScreenGamePlay.Static.IsIngameEditorActive())) && (MyFakes.ENABLE_GENERATED_WAYPOINTS_IN_EDITOR || MyHud.ShowDebugGeneratedWaypoints || Save))
            {
                // color by connected components
                int i           = MyWayPointGraph.GetConnectedComponentId(this);
                var vertexColor = HsvToRgb((0.36f + i * 0.618034f) % 1.0f, 0.8f, 0.75f);

                if (MyWayPointGraph.SelectedPath != null && MyWayPointGraph.SelectedPath.WayPoints.Contains(this))
                {
                    vertexColor = Color.Orange.ToVector3();  // selected path: orange vertices
                }

                if (IsSecret)
                {
                    vertexColor *= 0.25f;
                }

                // draw vertices
                if (MyEditorGizmo.SelectedEntities.Contains(this))
                {
                    DrawWaypointVertex(WorldMatrix.Translation, vertexColor + (IsSecret ? 1 : 3) * GetHighlightColor());
                    var name = new StringBuilder();
                    if (MyWayPointGraph.SelectedPath != null && MyWayPointGraph.SelectedPath.WayPoints.Contains(this))
                    {
                        name.Append(MyWayPointGraph.SelectedPath.Name).Append(": ").Append(MyWayPointGraph.SelectedPath.WayPoints.IndexOf(this) + 1);
                    }
                    else
                    {
                        name.Append(MyWayPoint.FilterWayPoints(MyEditorGizmo.SelectedEntities).IndexOf(this) + 1);
                    }
                    MyDebugDraw.DrawText(WorldMatrix.Translation, name, Color.White, 1);
                }
                else
                {
                    if (Save)
                    {
                        DrawWaypointVertex(WorldMatrix.Translation, vertexColor);  // for generated waypoints, draw only edges
                    }
                }

                // draw edges
                if (Save || MyHud.ShowDebugGeneratedWaypoints)
                {
                    using (MyWayPoint.NeighborsLock.AcquireSharedUsing())
                    {
                        foreach (var neighbor in Neighbors)
                        {
                            if (MyWayPointGraph.SelectedPath != null && MyWayPointGraph.SelectedPath.ContainsEdge(this, neighbor))
                            {
                                DrawWaypointEdge(WorldMatrix.Translation, neighbor.WorldMatrix.Translation, Color.Yellow, Color.White);  // on selected path: yellow-white
                                continue;
                            }

                            if (neighbor.Save || MyHud.ShowDebugGeneratedWaypoints)
                            {
                                using (MyWayPoint.BlockedEdgesLock.AcquireSharedUsing())
                                {
                                    // blocked for player (by a locked indestructible door: white-gray)
                                    if (BlockedEdgesForPlayer.Contains(Tuple.Create(this, neighbor)) || BlockedEdgesForPlayer.Contains(Tuple.Create(neighbor, this)))
                                    {
                                        DrawWaypointEdge(WorldMatrix.Translation, neighbor.WorldMatrix.Translation, Color.White, Color.Gray);
                                        continue;
                                    }

                                    // blocked for bots by a locked door: black-gray
                                    if (BlockedEdgesForBots.Contains(Tuple.Create(this, neighbor)) || BlockedEdgesForBots.Contains(Tuple.Create(neighbor, this)))
                                    {
                                        DrawWaypointEdge(WorldMatrix.Translation, neighbor.WorldMatrix.Translation, Color.Black, Color.Gray);
                                        continue;
                                    }
                                }

                                // obstructed: violet-white
                                if (MyHud.ShowDebugWaypointsCollisions && Position != neighbor.Position)
                                {
                                    var line = new MyLine(Position, neighbor.Position, true);
                                    if (MyEntities.GetAnyIntersectionWithLine(ref line, null, null, true, true, true, false) != null)
                                    {
                                        DrawWaypointEdge(WorldMatrix.Translation, neighbor.WorldMatrix.Translation, Color.Violet, Color.White);
                                        continue;
                                    }
                                }

                                // normal-normal: red-green
                                // generated-normal: orange-green (normally invisible)
                                // generated-generated: yellow-green (normally invisible)
                                bool generated      = !(Save && neighbor.Save);
                                bool fullyGenerated = !Save && !neighbor.Save;
                                DrawWaypointEdge(WorldMatrix.Translation, neighbor.WorldMatrix.Translation, generated ? fullyGenerated ? Color.Yellow : Color.Orange : Color.Red, Color.Green);
                                continue;
                            }
                        }
                    }
                }
            }
            return(base.DebugDraw());
        }