/// <summary> /// Render highlights for all nodes and edges on given path. /// </summary> /// <param name="camera"></param> /// <param name="path"></param> private void RenderPath(Camera camera, WayPoint.Path path) { if (path != null) { int numNodes = path.Nodes.Count; for (int i = 0; i < numNodes; ++i) { RenderNode(camera, path.Nodes[i]); } int numEdges = path.Edges.Count; for (int i = 0; i < numEdges; ++i) { RenderEdge(camera, path.Edges[i]); } } }
/// <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> /// Move the path by specified amount. /// </summary> /// <param name="node"></param> /// <param name="delta"></param> private void MovePath(WayPoint.Path path, Vector3 delta) { path.Translate(delta); Changed(); }
public Road(RoadGenerator gen, WayPoint.Path inPath) { generator = generators[genIndex]; path = inPath; }
} // 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()
/// <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()
/// <summary> /// Finds the nearest matching path. If found, also set the targetPosition /// which is the point we should be heading toward. If we already have a path /// then this is the position of the next node. If we didn't have a path, this /// is the nearest point on the edge of the new path. /// </summary> /// <param name="reflex"></param> /// <param name="gameActor"></param> /// <param name="targetPostion">Where to go.</param> /// <returns>True is valid path found.</returns> protected bool FindClosestMatchingWaypointSetTarget(Reflex reflex, GameActor gameActor, out Vector3 targetPostion) { Vector3 actorPos = gameActor.Movement.Position; Vector2 actorPos2d = new Vector2(actorPos.X, actorPos.Y); bool pathFound = false; targetPostion = Vector3.Zero; // Get the color of the path we're targeting. Classification.Colors color; if (reflex.ModifierParams.HasColor) { color = reflex.ModifierParams.Color; } else { color = Classification.Colors.NotApplicable; } // If we've already got a valid path and it matches this color // then we're good. // Note, we also look at the frame counter since the state may be // from a while ago. We only want this to count if it's from the previous frame. if (gameActor.followPathState.ValidForColor(color) && gameActor.followPathState.FrameLastUpdated + 1 == Time.FrameCounter) { // Valid path. targetPostion = gameActor.followPathState.FollowTarget; gameActor.followPathState.FrameLastUpdated = Time.FrameCounter; pathFound = true; } else if (gameActor.followPathState.ActivePath == null || gameActor.followPathState.FrameLastUpdated < Time.FrameCounter) { // We currently don't have any path (or we have an old path) so try and find a path that matches color. // Colors.NotApplicable will match any path. WayPoint.Path path = WayPoint.GetNearestPath(color, actorPos); if (path != null) { // Found as matching path, set the actor's state to follow this path. gameActor.followPathState.ActivePath = path; // Use the actual path color rather than the color we searched for since that my be NotApplicable. gameActor.followPathState.PathColor = path.Color; // Note, even in a path with a single node we still return // a degenerate edge so this will always be valid. gameActor.followPathState.ActiveEdge = WayPoint.GetNearestEdgeFromPath(path, actorPos2d); if (gameActor.followPathState.ActiveEdge != null) { Vector3 nearestPoint = gameActor.followPathState.ActiveEdge.NearestPoint(actorPos); targetPostion = nearestPoint; } else { } gameActor.followPathState.ActiveNode = null; gameActor.followPathState.CurrentNode = null; gameActor.followPathState.FrameLastUpdated = Time.FrameCounter; pathFound = true; } } return(pathFound); } // end of FindClosestMatchingWaypointSetTarget()