Example #1
0
 /// <summary>
 /// Splits the current edge adding a new node in the middle.
 /// </summary>
 public void SplitCurrentEdge()
 {
     if (edge != null)
     {
         SplitEdge(edge);
         edge = null;
     }
 }
Example #2
0
            /// <summary>
            /// Build section of geometry between the two nodes
            /// </summary>
            /// <param name="n0"></param>
            /// <param name="n1"></param>
            public bool Connect(Road inRoad, WayPoint.Edge inEdge)
            {
                road = inRoad;
                edge = inEdge;

                road.Generator.NewSection(this);

                return(renderObj != null);
            }
Example #3
0
 /// <summary>
 /// Set the object (either node or edge) as current mouse-over object.
 /// No checks done, assumes this is the closest object we are moused-over.
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="pos"></param>
 /// <param name="dist"></param>
 private void Set(object obj, Vector3 pos, float dist)
 {
     this.distance = dist;
     this.height   = pos.Z;
     if ((this.node = obj as WayPoint.Node) == null)
     {
         this.edge = obj as WayPoint.Edge;
     }
     Debug.Assert((obj == null) || (node != null) || (edge != null), "Something not a node nor edge passed in?");
 }
Example #4
0
 /// <summary>
 /// If we're moused over a node and have the right mouse click,
 /// start adding more nodes.
 /// If we're over an edge and have the right mouse clicks,
 /// split the edge and select the new node.
 /// </summary>
 /// <returns></returns>
 private bool CheckAddDelete()
 {
     if (edge != null)
     {
         if (act.AddNodes || act.MouseSplit)
         {
             act.AddNodes   = false;
             act.MouseSplit = false;
             SplitEdge(edge);
             edge = null;
             return(true);
         }
         else if (act.Delete)
         {
             if (actOnPath)
             {
                 DeletePath(Path);
             }
             else
             {
                 DeleteEdge(edge);
             }
             edge = null;
             return(true);
         }
     }
     if (node != null)
     {
         if (act.MouseAddNodes)
         {
             act.MouseAddNodes = false;
             fromNode          = node;
             mode = Mode.Add;
             Click(ModeChange.Accept);
             Changed();
             return(true);
         }
         else if (act.Delete)
         {
             if (actOnPath)
             {
                 DeletePath(Path);
             }
             else
             {
                 DeleteNode(node);
             }
             node = null;
             return(true);
         }
     }
     return(false);
 }
Example #5
0
                /// <summary>
                /// Render a highlight for the given edge.
                /// </summary>
                /// <param name="camera"></param>
                /// <param name="edge"></param>
                private void RenderEdge(Camera camera, WayPoint.Edge edge)
                {
                    bool asRoad = false;

                    bool edit = edge.Edit;

                    edge.Edit = true;
                    edge.Render(camera, edge.Path.RGBColor, asRoad);
                    edge.Edit = edit;

                    Vector3 pos = (edge.Node0.RenderPosition(asRoad) + edge.Node1.RenderPosition(asRoad)) * 0.5f;

                    RenderSphere(camera,
                                 pos,
                                 CurrentRadius(),
                                 CurrentColor());
                }
Example #6
0
            public bool Connect(Road inRoad, WayPoint.Node inNode)
            {
                road = inRoad;
                node = inNode;
                // Make a list of all edges hitting this node. This should
                // probably already be stored on the node.
                sections.Clear();
                foreach (Section section in Road.Sections)
                {
                    WayPoint.Edge edge = section.Edge;
                    if ((edge.Node0 == node) || (edge.Node1 == node))
                    {
                        sections.Add(section);
                    }
                }

                if (sections.Count > 1)
                {
                    // Sort them by angle
                    sections.Sort(new EdgeCompare(node));

                    for (int first = 0; first < sections.Count; ++first)
                    {
                        int second = first + 1;
                        if (second >= sections.Count)
                        {
                            second = 0;
                        }
                        // Trim away any overlap between these two sections.
                        if (!Road.Generator.Trim(sections[first], sections[second]))
                        {
                            // If the angle between these was too big to cause a trim
                            // then we need to insert a fan.
                            MakeFan(node, sections[first], sections[second]);
                        }
                    }
                }
                else if (sections.Count == 1)
                {
                    // Make an end cap
                    MakeFan(node, sections[0], sections[0]);
                }

                return(Fans.Count > 0);
            }
Example #7
0
                /// <summary>
                /// Find the closest edge or node that we are moused-over.
                /// Loops over all edges and nodes in the scene.
                /// </summary>
                /// <param name="camera"></param>
                private void FindOver(Camera camera)
                {
                    if (!ContinueMoving)
                    {
                        WayPoint.Path oldPath = Path;
                        Clear();
                        int pathCount = WayPoint.Paths.Count;
                        for (int iPath = 0; iPath < pathCount; ++iPath)
                        {
                            WayPoint.Path path = WayPoint.Paths[iPath];

                            int nodeCount = path.Nodes.Count;
                            for (int iNode = 0; iNode < nodeCount; ++iNode)
                            {
                                bool          asRoad = false;
                                WayPoint.Node node   = path.Nodes[iNode];
                                Vector3       pos    = node.RenderPosition(asRoad);

                                CheckObject(camera, pos, node);
                            }

                            int edgeCount = path.Edges.Count;
                            for (int iEdge = 0; iEdge < edgeCount; ++iEdge)
                            {
                                bool asRoad = false;

                                WayPoint.Edge edge = path.Edges[iEdge];

                                Vector3 pos = (edge.Node0.RenderPosition(asRoad) + edge.Node1.RenderPosition(asRoad)) * 0.5f;

                                CheckObject(camera, pos, edge);
                            }
                        }
                        if ((oldPath != null) && (oldPath != Path))
                        {
                            oldPath.ClearEdit();
                        }
                    }
                }
        /// <summary>
        /// Returns the current waypoint target location.
        /// </summary>
        /// <param name="gameActor"></param>
        /// <param name="target"></param>
        /// <returns>True if the target is valid, false otherwise.</returns>
        protected bool NewWaypointTarget(GameActor gameActor, ref Vector3 target)
        {
            bool validTarget = false;

            WayPoint.Node activeNode = gameActor.followPathState.ActiveNode;

            target = gameActor.followPathState.FollowTarget;
            WayPoint.Edge newEdge = WayPoint.GetNextEdgeFromPath(gameActor.followPathState.ActivePath, activeNode, gameActor);

            if (newEdge != null)
            {
                activeNode.EndTarget();
                activeNode.SetVisitedTime(gameActor);

                // find the opposite node to the new edge of the current node
                if (newEdge.Node0 == activeNode)
                {
                    // use node1 off new edge
                    activeNode = newEdge.Node1;
                }
                else
                {
                    // use node0 off new edge
                    activeNode = newEdge.Node0;
                }

                target = activeNode.Position;
                activeNode.BeginTarget(gameActor);
                gameActor.followPathState.ActiveNode = activeNode;

                gameActor.followPathState.ActiveEdge = newEdge;

                validTarget = true;
            }

            return(validTarget);
        }
        protected bool ClosestNodeIsTarget(GameActor actor)
        {
            WayPoint.Node activeNode = actor.followPathState.ActiveNode;
            if (activeNode != null)
            {
                Vector3 actorPos     = actor.Movement.Position;
                Vector2 actor2d      = new Vector2(actorPos.X, actorPos.Y);
                float   activeDistSq = Vector2.DistanceSquared(actor2d, activeNode.Position2d);

                List <WayPoint.Edge> edges = actor.followPathState.ActivePath.Edges;

                for (int i = 0; i < edges.Count; ++i)
                {
                    WayPoint.Edge edge = edges[i];

                    WayPoint.Node other = null;
                    if (edge.Node0 == activeNode)
                    {
                        other = edge.Node1;
                    }
                    else if (edge.Node1 == activeNode)
                    {
                        other = edge.Node0;
                    }
                    if (other != null)
                    {
                        float otherDistSq = Vector2.DistanceSquared(actor2d, other.Position2d);
                        if (otherDistSq < activeDistSq)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Example #10
0
 /// <summary>
 /// Move the edge by specified amount.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="delta"></param>
 private void MoveEdge(WayPoint.Edge edge, Vector3 delta)
 {
     edge.Translate(delta);
     Changed();
 }
Example #11
0
 /// <summary>
 /// Reset our mouse-over state.
 /// </summary>
 private void Clear()
 {
     distance = float.MaxValue;
     node     = null;
     edge     = null;
 }
Example #12
0
        /// <summary>
        /// Copies the current state of the objects in
        /// the game to this XmlLevelData object.
        /// </summary>
        /// <param name="gameThingList"></param>
        public void FromGame(List <GameThing> gameThingList)
        {
            waypoints.paths.Clear();

            // Get the WayPoint data.
            for (int i = 0; i < WayPoint.Paths.Count; i++)
            {
                WayPoint.Path path = (WayPoint.Path)WayPoint.Paths[i];
                XmlData.Path  p    = new XmlData.Path();

                // Add path to list.
                waypoints.paths.Add(p);

                // Fill in path data.
                p.color    = path.Color;
                p.roadName = path.RoadName;

                // Copy node info.
                for (int j = 0; j < path.Nodes.Count; j++)
                {
                    WayPoint.Node node = (WayPoint.Node)path.Nodes[j];
                    XmlData.Node  n    = new XmlData.Node();
                    n.position = new Vector2(node.Position.X, node.Position.Y);
                    n.height   = node.Height;
                    p.nodes.Add(n);
                }

                // Copy edge info.
                for (int j = 0; j < path.Edges.Count; j++)
                {
                    WayPoint.Edge edge = (WayPoint.Edge)path.Edges[j];
                    XmlData.Edge  e    = new XmlData.Edge();
                    e.node0     = path.Nodes.IndexOf(edge.Node0);
                    e.node1     = path.Nodes.IndexOf(edge.Node1);
                    e.direction = (int)edge.Dir;
                    p.edges.Add(e);
                }
            }

            // Loop through the gameThingList putting things into the
            // right Xml array for serialization.
            for (int i = 0; i < gameThingList.Count; i++)
            {
                GameActor srcActor = gameThingList[i] as GameActor;

                if (gameThingList[i].GetType() == typeof(Boku.SimWorld.CursorThing))
                {
                    // This space intentionally left blank.
                }
                else if (gameThingList[i].GetType() == Type.GetType("Boku.Fireball"))
                {
                    // This space intentionally left blank.
                }
                else if (gameThingList[i].GetType() == Type.GetType("Boku.CruiseMissile"))
                {
                    // This space intentionally left blank.
                }
                else if (actor != null)
                {
                    XmlData.Actor dstActor = new XmlData.Actor(srcActor.StaticActor.NonLocalizedName);
                    dstActor.FromActor(srcActor);
                    this.actor.Add(dstActor);
                }
                else
                {
                    Debug.Assert(false, @"Trying to serialize unrecognized type.");
                }
            }
        }   // end of FromGame()
Example #13
0
 /// <summary>
 /// Reset our state
 /// </summary>
 public void Clear()
 {
     distance = float.MaxValue;
     node     = null;
     edge     = null;
 }