// Update the state machine, try changing state. public void Update() { if (CurrentNode == null) { m_enqueuedActions.Clear(); return; } int maxPassThrough = 100; MyStateMachineNode nextNode; do { nextNode = null; int transitionId = -1; // enqueued transitions (actions) first if (m_enqueuedActions.Count > 0) { int bestPriority = int.MaxValue; foreach (var transition in CurrentNode.Transitions) { int transitionPriority = transition.Priority ?? int.MaxValue; if (transitionPriority <= bestPriority && m_enqueuedActions.Contains(transition.Name) && (transition.Conditions.Count == 0 || transition.Evaluate())) { transitionId = transition.Id; nextNode = transition.TargetNode; bestPriority = transitionPriority; } } } // transitions checking conditions if (nextNode == null) { nextNode = CurrentNode.QueryNewState(false, out transitionId); } // now try to transfer from one state to another if (nextNode != null) { //var fromNode = CurrentNode; var transitionWithStart = m_transitions[transitionId]; CurrentNode = nextNode; NotifyStateChanged(transitionWithStart); } } while (nextNode != null && // we changed state CurrentNode.PassThrough && // we want to pass through maxPassThrough-- > 0); // safety, prevent infinite loop caused by wrong data m_enqueuedActions.Clear(); if (CurrentNode != null) { CurrentNode.OnUpdate(this); } }
public static void InsertEntity_ImplementationPostfix(long entityId, ref MyConcurrentHashSet <long> ___m_containedEntities, ref MySafeZone __instance) { if (___m_containedEntities.Contains(entityId)) { return; } if (MyEntities.TryGetEntityById(entityId, out var top)) { top.SetSafeZone(__instance); } }
/// <summary> /// Adds newly added grids to cache and update count to meet change /// </summary> /// <param name="entity"></param> private void MyEntitiesOnOnEntityAdd(MyEntity entity) { if (!BlockLimiterConfig.Instance.EnableLimits) { return; } if (!(entity is MyCubeGrid grid)) { return; } if (grid.Projector != null || grid.IsPreview) { return; } // Do Not Add to grid cache at this point to allow MyCubeGridsOnBlockBuild to add and prevent double counts var blocks = grid.CubeBlocks; GridCache.AddGrid(grid); foreach (var block in blocks) { if (_justAdded.Contains(block)) { _justAdded.Remove(block); continue; } _justAdded.Add(block); Block.IncreaseCount(block.BlockDefinition, block.BuiltBy == block.OwnerId ? new List <long> { block.BuiltBy } : new List <long> { block.BuiltBy, block.OwnerId }, 1, grid.EntityId); } }
/// <summary> /// Expands current node with given cursor. /// First enquedAction is taking place then any valid transition. /// Cursor is being transitioned to result of expansion. /// Override this for custom behavior. /// </summary> protected virtual void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet <MyStringId> enquedActions, int passThrough) { MyStateMachineTransition nextTransition; do { // Try to find best transition across enquedActions // Does not need to be evaluated one. nextTransition = null; var transitions = cursor.Node.OutTransitions; if (enquedActions.Count > 0) { int bestPriority = int.MaxValue; for (var i = 0; i < transitions.Count; i++) { int transitionPriority = transitions[i].Priority ?? int.MaxValue; if (enquedActions.Contains(transitions[i].Name) && transitionPriority <= bestPriority && (transitions[i].Conditions.Count == 0 || transitions[i].Evaluate())) { nextTransition = transitions[i]; bestPriority = transitionPriority; } } } if (nextTransition == null) { // Try to find valid transition to next state nextTransition = cursor.Node.QueryNextTransition(); } // Transition into next state if (nextTransition != null) { cursor.FollowTransition(nextTransition); } } while (nextTransition != null && cursor.Node.PassThrough && passThrough-- > 0); }
public bool Contains(T item) { return(_hashSet.Contains(item)); }
/// <summary> /// Expands current node with given cursor. /// First enquedAction is taking place then any valid transition. /// Cursor is being transitioned to result of expansion. /// Override this for custom behavior. /// </summary> protected virtual void ExpandInternal(MyStateMachineCursor cursor, MyConcurrentHashSet<MyStringId> enquedActions, int passThrough) { MyStateMachineTransition nextTransition; do { // Try to find best transition across enquedActions // Does not need to be evaluated one. nextTransition = null; var transitions = cursor.Node.OutTransitions; if (enquedActions.Count > 0) { int bestPriority = int.MaxValue; for (var i = 0; i < transitions.Count; i++) { int transitionPriority = transitions[i].Priority ?? int.MaxValue; if (enquedActions.Contains(transitions[i].Name) && transitionPriority <= bestPriority && (transitions[i].Conditions.Count == 0 || transitions[i].Evaluate())) { nextTransition = transitions[i]; bestPriority = transitionPriority; } } } if (nextTransition == null) { // Try to find valid transition to next state nextTransition = cursor.Node.QueryNextTransition(); } // Transition into next state if (nextTransition != null) cursor.FollowTransition(nextTransition); } while (nextTransition != null && cursor.Node.PassThrough && passThrough-- > 0); }
//public static HashSet<MyEntity> UnregisteredEntities = new HashSet<MyEntity>(); public static void CheckAndConcealEntities( ) { if (_checkConceal) { return; } _checkConceal = true; try { List <MyPlayer> players; try { players = MySession.Static.Players.GetOnlinePlayers().ToList(); } catch (Exception ex) { Essentials.Log.Error(ex, "Error getting players list. Check and Conceal failed: {0}"); return; } foreach (GridGroup group in GridGroup.GetAllGroups(GridLinkTypeEnum.Logical)) { //we're using grid groups so that multi-part pirate ships don't lose pieces if (!PluginSettings.Instance.DynamicConcealPirates) { if (group.Parent.GetOwner() == "Space Pirates") { if (PluginSettings.Instance.DynamicShowMessages) { Essentials.Log.Info($"Not concealing pirate owned grid {group.Parent.EntityId} -> {group.Parent.DisplayName}."); } continue; } } foreach (MyCubeGrid grid in group.Grids) { if (grid.Physics == null) //projection { continue; } //if ( UnregisteredEntities.Contains( (MyEntity)grid ) ) // continue; if (RemovedGrids.Contains(grid.EntityId)) { continue; } if (grid.GridSizeEnum != MyCubeSize.Small) { if (grid.IsStatic && !PluginSettings.Instance.ConcealIncludeStations) { continue; } if (!PluginSettings.Instance.ConcealIncludeLargeGrids) { continue; } } if (players.Any(x => Vector3D.Distance(x.GetPosition(), grid.PositionComp.GetPosition()) < PluginSettings.Instance.DynamicConcealDistance)) { continue; } if (ProcessDockingZone.ZoneCache.Any(x => Vector3D.Distance(x.GetPosition(), grid.PositionComp.GetPosition()) < 100)) { continue; } if (CheckConcealBlockRules(grid)) { continue; } ConcealEntity(grid); } } } catch (Exception ex) { Essentials.Log.Error(ex); } finally { _checkConceal = false; } }