Exemplo n.º 1
0
 /// <summary>
 /// Reset our state
 /// </summary>
 public void Clear()
 {
     distance = float.MaxValue;
     node     = null;
     edge     = null;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Move the node by specified amount.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="delta"></param>
 private void MoveNode(WayPoint.Node node, Vector3 delta)
 {
     node.Translate(delta);
     Changed();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Break out of add mode.
 /// </summary>
 public void StopAdding()
 {
     mode     = Mode.None;
     fromNode = null;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Start adding to current path.
 /// </summary>
 public void StartAdding(WayPoint.Node from)
 {
     fromNode = from;
     mode     = Mode.Add;
 }
        }   // end of FindClosestMatchingWaypointSetTarget()

        /// <summary>
        /// Based on the name this is only supposed to be called when we're
        /// following a valid path and reach one of the WayPoints (nodes).
        /// So, if this is call without a valid path, it's probably an error
        /// upstream.
        /// </summary>
        /// <param name="gameActor"></param>
        /// <returns></returns>
        protected bool ReachedWaypoint(GameActor gameActor, ref Vector3 target)
        {
            bool validTarget = true;

            target = Vector3.Zero;

            // Save out the previously visited nodes.
            gameActor.followPathState.PreviousNode = gameActor.followPathState.CurrentNode;
            gameActor.followPathState.CurrentNode  = gameActor.followPathState.ActiveNode;
            if (gameActor.followPathState.ActiveNode != null)
            {
                WayPoint.Node activeNode = gameActor.followPathState.ActiveNode;

                Vector3 actorPosition   = gameActor.Movement.Position;
                Vector2 actorPosition2d = new Vector2(actorPosition.X, actorPosition.Y);
                float   distance        = Vector2.Distance(actorPosition2d, activeNode.Position2d);

                if (distance < accuracy)
                {
                    validTarget = NewWaypointTarget(gameActor, ref target);
                }
            }
            else
            {
                // Reached the edge itself.  Select the nearest node as the next target.

                Vector3 actorPosition   = gameActor.Movement.Position;
                Vector2 actorPosition2d = new Vector2(actorPosition.X, actorPosition.Y);

                WayPoint.Node nextNode = gameActor.followPathState.ActiveEdge.NearestNode(actorPosition);
                target = nextNode.Position;

                if (gameActor.followPathState.ActiveNode != null)
                {
                    gameActor.followPathState.ActiveNode.EndTarget();
                    gameActor.followPathState.ActiveNode = null;
                }
                gameActor.followPathState.ActiveNode = nextNode;
                nextNode.BeginTarget(gameActor);

                // Visit the "other" node on this edge so that the actor doesn't loop
                // back around unless absolutely necessary.
                if (nextNode == gameActor.followPathState.ActiveEdge.Node0)
                {
                    gameActor.followPathState.ActiveEdge.Node1.SetVisitedTime(gameActor);
                }
                else
                {
                    gameActor.followPathState.ActiveEdge.Node0.SetVisitedTime(gameActor);
                }
            }

            Debug.Assert(gameActor.followPathState.ActiveNode != null, "Still haven't found a node?");

            // Only check if we are end of path if there are more than 1 nodes in the path
            if (gameActor.followPathState.ActivePath.Nodes.Count > 1)
            {
                if (gameActor.followPathState.PreviousNode == gameActor.followPathState.ActiveNode)
                {
                    gameActor.ReachedEOP = gameActor.followPathState.PathColor;
                }
                else
                {
                    gameActor.ReachedEOP = Classification.Colors.None;
                }
            }
            else
            {
                gameActor.ReachedEOP = Classification.Colors.None;
            }

            return(validTarget);
        }
Exemplo n.º 6
0
        }   // end of FromGame()

        /// <summary>
        /// Hand off copies the objects in this XmlLevelData object
        /// into AddThing.
        /// </summary>
        /// <param name="gameThingList"></param>
        public void ToGame(InGame.AddThingDelegate AddThing)
        {
            WayPoint.ClearPaths();

            GraphicsDevice device = BokuGame.bokuGame.GraphicsDevice;

            // Copy local data to sim classes.

            // Copy waypoint data to sim classes.

            // In with the new.
            for (int i = 0; i < waypoints.paths.Count; i++)
            {
                XmlData.Path  p    = (XmlData.Path)waypoints.paths[i];
                WayPoint.Path path = new WayPoint.Path(p.color);
                path.RoadName = p.roadName;

                // Create nodes.
                for (int j = 0; j < p.nodes.Count; j++)
                {
                    XmlData.Node  n    = (XmlData.Node)p.nodes[j];
                    WayPoint.Node node = new WayPoint.Node(path, new Vector3(n.position, n.height));
                }

                // Create edges.
                for (int j = 0; j < p.edges.Count; j++)
                {
                    XmlData.Edge  e  = (XmlData.Edge)p.edges[j];
                    WayPoint.Node n0 = (WayPoint.Node)path.Nodes[e.node0];
                    WayPoint.Node n1 = (WayPoint.Node)path.Nodes[e.node1];
                    WayPoint.CreateNewEdge(n0, n1, (WayPoint.Edge.Direction)e.direction);
                }

                path.RecalcHeights(onLoad: true);
                if (path.Road != null)
                {
                    path.Road.Build();
                }
            }

            for (int i = 0; i < actor.Count; ++i)
            {
                XmlData.Actor srcActor = (XmlData.Actor)actor[i];
                GameActor     dstActor = ActorFromString(srcActor.typename);
                if (dstActor != null)
                {
                    srcActor.ToActor(dstActor);

                    dstActor = (GameActor)AddThing(dstActor);
                    if (dstActor != null)
                    {
                        // Init InsideGlassWalls.
                        // TODO (****) Right now we're doing this by checking the height of the terrain.
                        // We should also be able to do this by checking the material index BUT it appears
                        // that when we erase terrain we only set the height to 0 without resetting the material.
                        // I think...
                        dstActor.Chassis.InsideGlassWalls = Terrain.GetTerrainAndPathHeight(dstActor.Movement.Position) > 0;
                    }
                }
            }
        }   // end of ToGame()
Exemplo n.º 7
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()