Exemple #1
0
 void PinControl_StateChanged(PinControl sender, LogicState s)
 {
     Console.WriteLine(Name + " : " + State.ToString());
     ToolTip = new ToolTip()
     {
         Content = (State == LogicState.High) ? "High" : (State == LogicState.Low) ? "Low" : "Indeterminate"
     };
     if (_state == LogicState.High && !_transp)
     {
         ellipse.Fill = new SolidColorBrush(new Color()
         {
             A = 255, R = 255, G = 188, B = 188
         });
     }
     else if (_state == LogicState.Low && !_transp)
     {
         ellipse.Fill = new SolidColorBrush(new Color()
         {
             A = 255, R = 20, G = 20, B = 20
         });
     }
     else
     {
         ellipse.Fill = new SolidColorBrush(new Color()
         {
             A = 255, R = 121, G = 157, B = 255
         });
     }
 }
        /// <summary>
        /// If the time remaining until burn is too low to support the current or next (if set) state,
        /// this method sets next state to the appropriate state.
        /// </summary>
        void CommonStateLogic_SkipAhead()
        {
            // to minimize delay in handling appropriate skip ahead, we work on NextState if set, otherwise CurrentState
            LogicState relevantState = NextState ?? CurrentState;

            // this method is only relevant if between states FarAim (inclusive) and Countdown (exclusive)
            bool relevant = relevantState >= LogicState.FarAim && relevantState < LogicState.Countdown;

            if (!relevant)
            {
                return;
            }

            // cache time left to start
            var timeLeft = KspVars.TimeToNextManeuverBurnStartUT;

            // handle skipping ahead to countdown
            if (relevantState < LogicState.Countdown && timeLeft <= Settings.NearWarpBurnStartMarginSeconds)
            {
                LogUtility.Log("Skipping ahead to Countdown...");
                NextState = LogicState.Countdown;
            }
            else
            // otherwise, if autopiloting (so near aim state is relevant), handle skipping far warp
            if (FullAutoPilot && relevantState < LogicState.NearAim && timeLeft <= Settings.FarWarpBurnStartMarginSeconds)
            {
                LogUtility.Log("Skipping ahead to NearAim...");
                NextState = LogicState.NearAim;
            }
        }
Exemple #3
0
        public void Run()
        {
            while (!_finished)
            {
                _iterationStopwatch.Restart();

                _drawFinishedEvent.WaitOne();

                _logicState = _logic.RunLogicStep(_logicState);

                Execute.OnUIThread(() =>
                {
                    if (_bitmapGraphProvider.IsBitmapVisible)
                    {
                        _logic.Draw(_logicState, _drawingWindowState);
                    }

                    if (_bitmapGraphProvider.IsGraphVisible)
                    {
                        _logic.UpdateGraph(_logicState);
                    }

                    _drawFinishedEvent.Set();
                });

                var elapsedTime = _iterationStopwatch.ElapsedMilliseconds;
                if (elapsedTime < 100)
                {
                    Thread.Sleep((int)(100 - elapsedTime));
                }
            }
        }
        /// <summary>
        /// Performs a step in the game logic for the battleship game.
        /// </summary>
        protected internal override void GameLogicStep()
        {
            switch (currentState)
            {
                case LogicState.Begin:
                    Begin();
                    currentState = LogicState.PlaceShips;
                    break;

                case LogicState.PlaceShips:
                    StandardShipPlacement();
                    currentState = LogicState.Turn;
                    break;

                case LogicState.Turn:
                    StandardPlaceShot();
                    if (Remaining.Count <= 1)
                    {
                        End();
                        currentState = LogicState.End;
                    }
                    else
                    {
                        NextTurn();
                    }
                    break;
            }
        }
Exemple #5
0
    public void MoveToRandomPoint()
    {
        SpriteAnimatorNpc snpc = GetComponent <SpriteAnimatorNpc>();

        _logicState = LogicState.Walking;
        snpc.PlaySpriteAnimator();

        _pointWalkCount = (int)Random.Range(6, 10);

        if (!_lastTarget)
        {
            int random_range = _currentTarget.GetEdges().Length;
            _lastTarget    = _currentTarget;
            _currentTarget = _currentTarget.GetEdges()[(int)Random.Range(0, random_range)].GetComponent <Node>();
        }
        else
        {
            if (Random.Range(0f, 1f) < 0.05f)
            {
                Node aux_target = _currentTarget;
                _currentTarget = _lastTarget;
                _lastTarget    = aux_target;
            }
            else
            {
                GameObject[] targets_array = _currentTarget.GetEdges().Clone() as GameObject[];
                int          random_range  = targets_array.Length;
                _lastTarget    = _currentTarget;
                _currentTarget = targets_array[(int)Random.Range(0, random_range)].GetComponent <Node>();
            }
        }
    }
 void CommonStateLogic_WarpRest(StabilizationSettings restSettings, LogicState nextState)
 {
     if (AreStabilizationSettingsAchieved(restSettings))
     {
         NextState = nextState;
     }
 }
Exemple #7
0
 internal void ReturnSpawnedUnits()
 {
     foreach (var unit in UnitsCreatedByThis)
     {
         unit.AssignMoveGoal(this.Position.X, this.Position.Y, replace: true);
     }
     this.CurrentLogicState = LogicState.ReturningUnits;
 }
Exemple #8
0
        public static LogicState Not(this LogicState state)
        {
            if (state == LogicState.Undefined)
            {
                return(LogicState.Undefined);
            }

            return(1 - state);
        }
Exemple #9
0
 private void PushLogicState(LogicState state)
 {
     if (LogicStatesStack.Count > 0)
     {
         LogicStatesStack.Peek().StopState();
     }
     LogicStatesStack.Push(state);
     state.StartState();
 }
Exemple #10
0
        public static LogicState Xor(this LogicState state, LogicState other)
        {
            if (state == LogicState.Undefined || other == LogicState.Undefined)
            {
                return(LogicState.Undefined);
            }

            return(state ^ other);
        }
Exemple #11
0
 public void SetState(LogicState s, int linkLevel)
 {
     _state = s;
     if (linkLevel <= 1 && Connection != null)
     {
         Connection.SetState(_state, ++linkLevel);
     }
     StateChanged(this, _state);
 }
Exemple #12
0
    private void MoveToNextRandomPoint()
    {
        _pointWalkCount--;

        if (_pointWalkCount > 0)
        {
            if (!_lastTarget)
            {
                int random_range = _currentTarget.GetEdges().Length;
                _lastTarget    = _currentTarget;
                _currentTarget = _currentTarget.GetEdges()[(int)Random.Range(0, random_range)].GetComponent <Node>();
            }
            else
            {
                if (Random.Range(0f, 1f) < _backProbability)
                {
                    Node aux_target = _currentTarget;
                    _currentTarget = _lastTarget;
                    _lastTarget    = aux_target;
                }
                else
                {
                    GameObject[] targets_array = null;

                    if (_currentTarget.GetEdges().Length != 1)
                    {
                        targets_array = new GameObject[_currentTarget.GetEdges().Length - 1];
                        int ind = 0;

                        for (int i = 0; i < _currentTarget.GetEdges().Length; i++)
                        {
                            if (_lastTarget.transform.position != _currentTarget.GetEdges()[i].transform.position)
                            {
                                targets_array[ind] = _currentTarget.GetEdges()[i];
                                ind++;
                            }
                        }
                    }
                    else
                    {
                        targets_array = _currentTarget.GetEdges().Clone() as GameObject[];
                    }

                    int random_range = targets_array.Length;
                    _lastTarget    = _currentTarget;
                    _currentTarget = targets_array[(int)Random.Range(0, random_range)].GetComponent <Node>();
                }
            }
        }
        else
        {
            _logicState = LogicState.Stand;
            SpriteAnimatorNpc snpc = GetComponent <SpriteAnimatorNpc>();
            snpc.StopSpriteAnimator(true);
        }
    }
 void CommonStateLogic_WarpWait(double burnStartMarginSeconds, LogicState restState)
 {
     if (!StateChanged &&
         KspVars.CurrentWarpStatus != KspVars.WarpStatus.Fast &&
         KspVars.TimeToNextManeuverBurnStartUT <= burnStartMarginSeconds
         )
     {
         NextState = restState;
     }
 }
Exemple #14
0
        private void LogicStateActivity()
        {
            const double fadeTime = 0.5;
            const double showTime = 1.8;

            /////////////////////EARLY OUT////////////////////////
            // This guaranteees a few frames have passed before we start logic
            if (this.ActivityCallCount < 3)
            {
                return;
            }
            ///////////////////END EARLY OUT/////////////////////

            switch (_mCurrentLogicState)
            {
            case LogicState.Uninitialized:
                CCGLabel.Visible       = false;
                CreatedByLabel.Visible = false;
                InterpolateToState(VariableState.Opaque, fadeTime);
                _mCurrentLogicState = LogicState.FadingIn;
                break;

            case LogicState.FadingIn:
                CCGLabel.Visible       = false;
                CreatedByLabel.Visible = false;
                if (CurrentState == VariableState.Opaque)
                {
                    _mCurrentLogicState = LogicState.Showing;
                    _mLastStateChange   = TimeManager.CurrentTime;
                }
                break;

            case LogicState.Showing:
                CCGLabel.Visible       = true;
                CreatedByLabel.Visible = true;
                if (TimeManager.SecondsSince(_mLastStateChange) > showTime)
                {
                    InterpolateToState(VariableState.Transparent, fadeTime);
                    _mCurrentLogicState = LogicState.FadingOut;
                }
                break;

            case LogicState.FadingOut:
                CCGLabel.Visible       = false;
                CreatedByLabel.Visible = false;
                if (CurrentState == VariableState.Transparent && AsyncLoadingState == FlatRedBall.Screens.AsyncLoadingState.Done)
                {
                    IsActivityFinished = true;
                    // NextScreen should be set through the Glue UI
                }
                break;
            }
        }
Exemple #15
0
 public void ChangeState(LogicState <T> newState)
 {
     if (newState == null)
     {
         return;
     }
     if (current_state != null)
     {
         current_state.exit(owner_entity);
     }
     current_state = newState;
     current_state.enter(owner_entity);
 }
Exemple #16
0
        public MainLoop(Commands commands, Log log, DrawingWindowState drawingWindowState, BitmapGraphProvider bitmapGraphProvider, ConnectionData connectionData)
        {
            _commands            = commands;
            _log                 = log;
            _drawingWindowState  = drawingWindowState;
            _bitmapGraphProvider = bitmapGraphProvider;

            _drawFinishedEvent  = new AutoResetEvent(true);
            _iterationStopwatch = new Stopwatch();

            _logicState = new LogicState();
            _logic      = new Logic(bitmapGraphProvider, bitmapGraphProvider, _log, _commands, connectionData);
        }
        void CommonStateLogic_AimStabilize(LogicState postAimState)
        {
            if (KspVars.NextManeuverOffAngle > MaxAimErrorAngle)
            {
                ResetCurrentState();
            }
            else if (AreStabilizationSettingsAchieved(Settings.AimStabilization))
            {
                NextState = postAimState;
            }

            CommonStateLogic_SkipAhead();
        }
Exemple #18
0
    private void MoveToDesiredNode(Node target)
    {
        Node n = _currentTarget.NextNodeTo(target);

        if (n == null || n == target) //Finish
        {
            SpriteAnimatorNpc snpc = GetComponent <SpriteAnimatorNpc>();
            _logicState = LogicState.Stand;
        }
        else
        {
            _currentTarget = n;
        }
    }
        void CommonStateLogic_Aim(LogicState aimStabilizationState)
        {
            if (StateChanged && Settings.EnableManeuverHold)
            {
                KspCommands.EnableAutoPilotManeuverHold();
            }

            if (KspVars.NextManeuverOffAngle <= MaxAimErrorAngle)
            {
                NextState = aimStabilizationState;
            }

            CommonStateLogic_SkipAhead();
        }
        private void OnUpdate(float dt)
        {
            LogicState result = m_BattleLogicMgr.Update(dt);

            //Debugger.Log("curState:"+result);
            if (result == LogicState.Playing)
            {
                m_BattleScene.Update();
            }
            else if (result == LogicState.End)
            {
                Exit();
            }
        }
Exemple #21
0
        public void InitLogic(int TemplateID, int Priority, ObjectCreature ReleaseObj, SpellInfo info, float timeInterval)
        {
            m_TempSkillTag.Clear();
            m_Oneself.Clear();
            m_Enemy.Clear();

            m_TemplateID   = TemplateID;
            m_ReleaseObj   = ReleaseObj;
            m_Priority     = Priority;
            m_Spellinfo    = info;
            m_ID           = ReleaseObj.GetGameObject().GetInstanceID();
            m_Tempai       = (SkillaiTemplate)DataTemplate.GetInstance().m_SkillaiTable.getTableData(m_TemplateID);
            m_TimeInterval = timeInterval;

            curState = LogicState.EM_LOGICSTATE_USE;
        }
Exemple #22
0
        public void ClearUp()
        {
            curState = LogicState.EM_LOGICSTATE_IDLE;

            m_TempSkillTag.Clear();
            m_Oneself.Clear();
            m_Enemy.Clear();

            m_TemplateID   = -1;
            m_ReleaseObj   = null;
            m_Priority     = -1;
            m_Spellinfo    = null;
            m_ID           = -1;
            m_Tempai       = null;
            m_TimeInterval = 0f;
        }
Exemple #23
0
        public static Color Color(this LogicState state)
        {
            switch (state)
            {
            case LogicState.Undefined: return(Constants.UndefinedLogicStateColor);

            case LogicState.On: return(Constants.OnLogicStateColor);

            case LogicState.Off: return(Constants.OffLogicStateColor);

            default: {
                Console.WriteLine($"Undefined Color for state {state}");
                return(Microsoft.Xna.Framework.Color.Pink);
            }
            }
        }
Exemple #24
0
    public static string LogicStateToString(LogicState state)
    {
        switch (state)
        {
        case LogicState.False:
            return("0");

        case LogicState.True:
            return("1");

        case LogicState.DontCare:
            return("X");

        default:
            throw new Exception("An unknown error occured.");
        }
    }
Exemple #25
0
        private void CustomActivity()
        {
            bool shouldReactivate = mAllowReactivation &&
                                    this.CurrentLogicState == LogicState.Defeated &&
                                    ScreenManager.CurrentScreen.PauseAdjustedSecondsSince(lastTimeDestroyed) > RegenerationTime;

            if (shouldReactivate)
            {
                this.CurrentLogicState = LogicState.ActiveWaiting;
            }

            if (this.CurrentLogicState == LogicState.ReturningUnits &&
                UnitsCreatedByThis.All(unit => this.DespawnCircleInstance.CollideAgainst(unit.CircleInstance)))
            {
                for (int i = UnitsCreatedByThis.Count - 1; i >= 0; i--)
                {
                    UnitsCreatedByThis[i].Destroy();
                }
                this.CurrentLogicState = LogicState.ActiveWaiting;
            }
        }
        public void SyncFrame(BattleData data)
        {
            Debugger.Log("完成帧:" + data.mFinishFrame);
            m_BattleLogicMgr.SetFinishFrame(data.mFinishFrame);
            AddCommand(data.mOperators);
            int currentFrame = data.mCurrentFrame;

            while (true)
            {
                if (m_BattleLogicMgr.m_currentFrame >= currentFrame - 1)
                {
                    return;
                }
                LogicState state = m_BattleLogicMgr.Update();
                if (state == LogicState.End)
                {
                    Exit();
                    return;
                }
            }
        }
        void CommonStateLogic_WarpStart(double burnStartMarginSeconds, LogicState warpWaitState, LogicState skippedWarpState)
        {
            // don't prevent first attempt to warp per entry into this state
            if (StateChanged)
            {
                LastWarpRetryLateUpdateCount = null;
            }

            if (KspVars.CurrentWarpStatus == KspVars.WarpStatus.Fast)
            {
                // just wait until the warp ends if already warping
                NextState = warpWaitState;
                return;
            }

            var timeTilStart = KspVars.TimeToNextManeuverBurnStartUT;

            // skip warp entirely if we're already within the burn start margin
            if (timeTilStart <= burnStartMarginSeconds)
            {
                LogUtility.Log($"Skipping ahead to {skippedWarpState}...");
                NextState = skippedWarpState;
            }
            else
            {
                // otherwise, start the warp, but don't retry during the same state unless sufficient updates have passed
                // (prevents spamming with "already warping" messages)
                if (!LastWarpRetryLateUpdateCount.HasValue || LateUpdateCountInState - LastWarpRetryLateUpdateCount.Value >= Settings.MinWarpRetryLateUpdateDelay)
                {
                    KspCommands.TimeWarpToUT(KspVars.CurrentUT + timeTilStart - burnStartMarginSeconds);
                    LastWarpRetryLateUpdateCount = LateUpdateCountInState;
                }

                // transition to wait state if actually warping
                if (KspVars.CurrentWarpStatus == KspVars.WarpStatus.Fast)
                {
                    NextState = warpWaitState;
                }
            }
        }
Exemple #28
0
 private void Clock_StateChanged(PinControl sender, LogicState s)
 {
     if (Clock.State == LogicState.Indeterminate)
     {
         Q.State = LogicState.Indeterminate;
     }
     else
     {
         if (Clock.State == LogicState.Low)
         {
             Q.State = D.State;
         }
         else if (Clock.State == LogicState.High && D.State == LogicState.Low)
         {
             Q.State = LogicState.Low;
         }
         else if (Clock.State == LogicState.High && D.State == LogicState.High)
         {
             Q.State = LogicState.High;
         }
     }
 }
Exemple #29
0
        internal void Attack(Unit playerUnit, Func <string, Vector3, Unit> spawnAction)
        {
            if (CurrentLogicState == LogicState.ReturningUnits)
            {
                // units already exist, so attack:
                foreach (var unit in UnitsCreatedByThis)
                {
                    unit.AssignMoveAttackGoal(playerUnit.X, playerUnit.Y);
                }
            }
            else
            {
                CreateAllNewUnits(spawnAction);

                foreach (var unit in UnitsCreatedByThis)
                {
                    unit.AssignMoveAttackGoal(playerUnit.X, playerUnit.Y);
                }
            }

            this.CurrentLogicState = LogicState.Spawned;
        }
Exemple #30
0
 private void Q_StateChanged(PinControl sender, LogicState s)
 {
     _Q.State = (!(Bit) new Bit(Q.State)).Value;
 }
Exemple #31
0
        private void LogicStateActivity()
        {
            const double FadeTime = 0.5;
            const double ShowTime = 1.8;

            /////////////////////EARLY OUT////////////////////////
            // This guaranteees a few frames have passed before we start logic
            if (this.ActivityCallCount < 3)
            {
                return;
            }
            ///////////////////END EARLY OUT/////////////////////

            switch (mCurrentLogicState)
            {
                case LogicState.Uninitialized:
                    InterpolateToState(VariableState.Opaque, FadeTime);
                    mCurrentLogicState = LogicState.FadingIn;
                    break;
                case LogicState.FadingIn:
                    if (CurrentState == VariableState.Opaque)
                    {
                        mCurrentLogicState = LogicState.Showing;
                        mLastStateChange = TimeManager.CurrentTime;
                    }
                    break;
                case LogicState.Showing:
                    if (TimeManager.SecondsSince(mLastStateChange) > ShowTime)
                    {
                        InterpolateToState(VariableState.Transparent, FadeTime);
                        mCurrentLogicState = LogicState.FadingOut;
                    }
                    break;
                case LogicState.FadingOut:

                    if (CurrentState == VariableState.Transparent && AsyncLoadingState == AsyncLoadingState.Done)
                    {
                        IsActivityFinished = true;
                        // NextScreen should be set through the Glue UI
                    }
                    break;
            }
        }
Exemple #32
0
 private void B_StateChanged(PinControl sender, LogicState s)
 {
     Eval();
 }
 /// <summary>
 /// Passes parameters to the base constructor.
 /// </summary>
 /// <param name="info">The <see cref="MatchInfo"/> from a round to associate with.</param>
 /// <param name="controllers">The <see cref="ControllerUser"/>s to utilize.</param>
 public ClassicRound(MatchInfo info, List<ControllerUser> controllers)
     : base(info, controllers)
 {
     currentState = LogicState.Begin;
 }