public MyGuiScreenEditorWayPointPath(MyWayPointPath path, bool newlyAdded) : base(new Vector2(0.5f, 0.5f), newlyAdded ? new Vector2(0.4f, 0.25f) : new Vector2(0.32f, 0.25f)) { m_waypointPath = path; m_newlyAdded = newlyAdded; Init(); }
internal override void Init(MySmallShipBot bot) { base.Init(bot); findSmallship = new MyFindSmallshipHelper(); //processedWaypoints = 0; if (bot.WaypointPath != null && bot.WaypointPath.WayPoints.Count > 0) { bot.CurrentWaypoint = bot.WaypointPath.WayPoints[0]; m_lastWayPointPath = bot.WaypointPath; } }
internal override void Update(MySmallShipBot bot) { base.Update(bot); if (ShouldFallAsleep(bot)) { bot.IsSleeping = true; return; } bool pathChange = m_lastWayPointPath != bot.WaypointPath; if (pathChange) { m_lastWayPointPath = bot.WaypointPath; m_currentWayPointIndex = 0; } bool cycle = bot.PatrolMode == MyPatrolMode.CYCLE; if (bot.WaypointPath != null && !bot.SuspendPatrol && bot.WaypointPath.WayPoints.Count > 0) { UpdateVisibility(bot, bot.CurrentWaypoint.GetPosition()); if (!m_targetVisible) { findSmallship.Update(bot, bot.CurrentWaypoint); if (findSmallship.PathNotFound) { bot.IsSleeping = true; m_isInvalid = true; } } else { bool blockedEdgesIdDirty = m_lastBlockedEdgesChangeId != MyWayPoint.BlockedEdgesChangeId; m_path.Clear(); using (MyWayPoint.BlockedEdgesLock.AcquireSharedUsing()) { m_path.AddRange(bot.WaypointPath.CompletePath(MyWayPoint.BlockedEdgesForBots, bot.CurrentWaypoint, false, cycle, !blockedEdgesIdDirty)); } m_lastBlockedEdgesChangeId = MyWayPoint.BlockedEdgesChangeId; if (blockedEdgesIdDirty) { if (bot.CurrentWaypoint == null) { m_currentWayPointIndex = 0; } else { m_currentWayPointIndex = m_path.IndexOf(bot.CurrentWaypoint); } } // no path found if (m_currentWayPointIndex == -1) { return; } bot.CurrentWaypoint = m_path[m_currentWayPointIndex]; if (Vector3.DistanceSquared(bot.GetPosition(), bot.CurrentWaypoint.GetPosition()) <= WAYPOINT_NEAR_DISTANCE_SQR) { if (bot.CurrentWaypoint.EntityId != null && m_lastWayPoint != bot.CurrentWaypoint) { m_lastWayPoint = bot.CurrentWaypoint; MyScriptWrapper.BotReachedWaypoint(bot, bot.CurrentWaypoint); } //++processedWaypoints; int count = m_path.Count; switch (bot.PatrolMode) { case MyPatrolMode.CYCLE: //bot.CurrentWaypointIndex = processedWaypoints % count; m_currentWayPointIndex++; if (m_currentWayPointIndex >= count) { m_currentWayPointIndex = 0; } break; case MyPatrolMode.PING_PONG: if (count > 1) { //bot.CurrentWaypointIndex = processedWaypoints % (count * 2 - 2); //if (bot.CurrentWaypointIndex >= count) //{ // bot.CurrentWaypointIndex = (count * 2 - 2) - bot.CurrentWaypointIndex; //} if (m_forward) { if (m_currentWayPointIndex < count - 1) { m_currentWayPointIndex++; } else { m_currentWayPointIndex--; m_forward = false; } } else { if (m_currentWayPointIndex > 0) { m_currentWayPointIndex--; } else { m_currentWayPointIndex++; m_forward = true; } } } else { m_currentWayPointIndex = 0; } break; case MyPatrolMode.ONE_WAY: if (m_currentWayPointIndex < m_path.Count - 1) { ++m_currentWayPointIndex; } break; } bot.CurrentWaypoint = m_path[m_currentWayPointIndex]; } bot.Move(bot.CurrentWaypoint.GetPosition(), bot.CurrentWaypoint.GetPosition(), GetUpPlane(), false); findSmallship.Init(bot); } } }
public override void Close() { if (m_dangerZoneId != -1) { MyDangerZones.Instance.Unregister(this); m_dangerZoneId = -1; } MyEntities.OnEntityRemove -= MyEntities_OnEntityRemove; MySession.Static.LinkEntities -= OnLinkEntities; if (Followers.Count > 0) { MySmallShipBot newLeader = Followers[0]; Debug.Assert(newLeader != this); newLeader.Leader = null; Debug.Assert(!newLeader.Closed); if (m_aiTemplate.IsPatroling() && newLeader.WaypointPath != null) { SetWaypointPath(newLeader.WaypointPath.Name); newLeader.Patrol(); } else { Idle(); } var followers = Followers.ToArray(); for (int i = 1; i < followers.Length; i++) { followers[i].Follow(newLeader); } Followers.Remove(newLeader); Debug.Assert(Followers.Count == 0); } StopFollow(); if (m_currentBehavior != null) { m_currentBehavior.Close(this); m_currentBehavior = null; } if (m_biochemEffect != null) { m_biochemEffect.Stop(); m_biochemEffect = null; } WaypointPath = null; if (!IsSleeping) MySmallShipBot.TotalAliveBots--; base.Close(); }
public void SetWaypointPath(string name) { CurrentWaypoint = null; WaypointPath = MyWayPointGraph.GetPath(name); if (WaypointPath != null && WaypointPath.WayPoints.Count > 0) { CurrentWaypoint = WaypointPath.WayPoints[0]; } }
// Resolve EntityId links. public void ResolveLinks() { // parent entities (prefabs) if (objectBuilder.ParentEntityId != null && MyEntities.GetEntities().Contains(this)) { var parent = MyEntities.GetEntityByIdOrNull(new MyEntityIdentifier((uint)objectBuilder.ParentEntityId.Value)); if (parent != null) { var worldMatrix = WorldMatrix; MyEntities.Remove(this); //parent.Children.Add(this); // remove it and add back through the parent parent.AddChild(this); this.Activate(true, false); SetWorldMatrix(worldMatrix); } } // neighbors foreach (var neighborId in objectBuilder.NeighborEntityIds) { var neighbor = MyEntities.GetEntityByIdOrNull(new MyEntityIdentifier((uint)neighborId)); if (neighbor != null && neighbor is MyWayPoint) { Connect(this, (MyWayPoint)neighbor); } } // path placing for (int i = 0; i < objectBuilder.GroupPlacings.Count; i++) { var name = objectBuilder.GroupNames[i]; var placing = objectBuilder.GroupPlacings[i]; // resolve path by name: create it if it didn't exist MyWayPointPath path = MyWayPointGraph.GetPath(name); if (path == null) { path = new MyWayPointPath(name); } // make enough empty waypoints to make it fit while (placing >= path.WayPoints.Count) { path.WayPoints.Add(null); } path.WayPoints[placing] = this; } // can't delete object builder // This function is reentrant and sometimes we need both runs. //objectBuilder = null; // but we can delete neighbor and path info if (MyGuiScreenGamePlay.Static.IsGameActive()) { objectBuilder.GroupNames.Clear(); objectBuilder.GroupPlacings.Clear(); objectBuilder.NeighborEntityIds.Clear(); } }
public static void RemovePath(MyWayPointPath path) { if (path == SelectedPath) SelectedPath = null; StoredPaths.Remove(path); PathFromName.Remove(path.Name); }
// Update visibility, path and vertex selection. Used when toggling waypoint visibility. public static void UpdateVisibilityAndSelection(bool visible) { using (VerticesLock.AcquireSharedUsing()) { foreach (var waypoint in m_vertices) { waypoint.Visible = visible; } } // deselect waypoints if (!visible) { SelectedPath = null; foreach (var waypoint in MyWayPoint.FilterWayPoints(MyEditorGizmo.SelectedEntities)) MyEditorGizmo.RemoveEntityFromSelection(waypoint); } }
private static void InitPaths() { StoredPaths = new List<MyWayPointPath>(); PathFromName = new Dictionary<string, MyWayPointPath>(); SelectedPath = null; }